Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import componenttest.rules.repeater.RepeatTests;
import io.openliberty.faces.fat.selenium.util.internal.CustomDriver;
import io.openliberty.faces.fat.selenium.util.internal.ExtendedWebDriver;
import io.openliberty.faces.fat.selenium.util.internal.WebPage;

/**
* JSF 2.2 Tests
Expand Down Expand Up @@ -122,6 +123,22 @@ public static ExtendedWebDriver getWebDriver() throws Exception {
if(DRIVER == null) {
throw new Exception("Failed to initialize WebDriver after multiple attempts! See log for details.");
}

// Register the driver reset callback statically for the WebPage to use if exceptions occur.
WebPage.setDriverResetCallback(() -> {
Log.info(c, "DriverResetCallback", "Resetting WebDriver due to some error. See log for details");
if (DRIVER != null) {
try {
DRIVER.quit();
} catch (Exception e) {
// no-op
}
DRIVER = null;
}
DRIVER = getWebDriver();
return DRIVER;
});

return DRIVER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import componenttest.rules.repeater.RepeatTests;
import io.openliberty.faces.fat.selenium.util.internal.CustomDriver;
import io.openliberty.faces.fat.selenium.util.internal.ExtendedWebDriver;
import io.openliberty.faces.fat.selenium.util.internal.WebPage;

/**
* JSF 2.2 Tests
*
Expand Down Expand Up @@ -133,6 +135,22 @@ public static ExtendedWebDriver getWebDriver() throws Exception {
if(DRIVER == null) {
throw new Exception("Failed to initialize WebDriver after multiple attempts! See log for details.");
}

// Register the driver reset callback statically for the WebPage to use if exceptions occur.
WebPage.setDriverResetCallback(() -> {
Log.info(c, "DriverResetCallback", "Resetting WebDriver due to some error. See log for details");
if (DRIVER != null) {
try {
DRIVER.quit();
} catch (Exception e) {
// no-op
}
DRIVER = null;
}
DRIVER = getWebDriver();
return DRIVER;
});

return DRIVER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import componenttest.rules.repeater.RepeatTests;
import io.openliberty.faces.fat.selenium.util.internal.CustomDriver;
import io.openliberty.faces.fat.selenium.util.internal.ExtendedWebDriver;
import io.openliberty.faces.fat.selenium.util.internal.WebPage;

/**
* JSF 2.3 Tests
Expand Down Expand Up @@ -107,6 +108,22 @@ public static ExtendedWebDriver getWebDriver() throws Exception {
if(DRIVER == null) {
throw new Exception("Failed to initialize WebDriver after multiple attempts! See log for details.");
}

// Register the driver reset callback statically for the WebPage to use if exceptions occur.
WebPage.setDriverResetCallback(() -> {
Log.info(c, "DriverResetCallback", "Resetting WebDriver due to some error. See log for details");
if (DRIVER != null) {
try {
DRIVER.quit();
} catch (Exception e) {
// no-op
}
DRIVER = null;
}
DRIVER = getWebDriver();
return DRIVER;
});

return DRIVER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import componenttest.rules.repeater.RepeatTests;
import io.openliberty.faces.fat.selenium.util.internal.CustomDriver;
import io.openliberty.faces.fat.selenium.util.internal.ExtendedWebDriver;
import io.openliberty.faces.fat.selenium.util.internal.WebPage;

/**
* JSF 2.3 Tests
Expand Down Expand Up @@ -139,6 +140,22 @@ public static ExtendedWebDriver getWebDriver() throws Exception {
if(DRIVER == null) {
throw new Exception("Failed to initialize WebDriver after multiple attempts! See log for details.");
}

// Register the driver reset callback statically for the WebPage to use if exceptions occur.
WebPage.setDriverResetCallback(() -> {
Log.info(c, "DriverResetCallback", "Resetting WebDriver due to some error. See log for details");
if (DRIVER != null) {
try {
DRIVER.quit();
} catch (Exception e) {
// no-op
}
DRIVER = null;
}
DRIVER = getWebDriver();
return DRIVER;
});

return DRIVER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import componenttest.topology.impl.JavaInfo;
import io.openliberty.faces.fat.selenium.util.internal.CustomDriver;
import io.openliberty.faces.fat.selenium.util.internal.ExtendedWebDriver;
import io.openliberty.faces.fat.selenium.util.internal.WebPage;

@RunWith(Suite.class)
@SuiteClasses({
Expand Down Expand Up @@ -160,6 +161,22 @@ public static ExtendedWebDriver getWebDriver() throws Exception {
if(DRIVER == null) {
throw new Exception("Failed to initialize WebDriver after multiple attempts! See log for details.");
}

// Register the driver reset callback statically for the WebPage to use if exceptions occur.
WebPage.setDriverResetCallback(() -> {
Log.info(c, "DriverResetCallback", "Resetting WebDriver due to some error. See log for details");
if (DRIVER != null) {
try {
DRIVER.quit();
} catch (Exception e) {
// no-op
}
DRIVER = null;
}
DRIVER = getWebDriver();
return DRIVER;
});

return DRIVER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ public class WebPage {
public static final Duration LONG_TIMEOUT = Duration.ofMillis(16000);

protected ExtendedWebDriver webDriver;
private static DriverResetCallback driverResetCallback = null;

/*
* Interface to reset the driver, see setDriverResetCallback
*/
@FunctionalInterface
public interface DriverResetCallback {
ExtendedWebDriver resetDriver() throws Exception;
}

/*
* Set a callback to reset the driver
* Must be called once within the FATSuite during driver initialization
*/
public static void setDriverResetCallback(DriverResetCallback callback) {
driverResetCallback = callback;
}

public WebPage(ExtendedWebDriver webDriver) {
this.webDriver = webDriver;
Expand All @@ -52,7 +69,30 @@ public void setWebDriver(ExtendedWebDriver webDriver) {
}

public void get(String url) {
webDriver.get(url);
int maxAttempts = 2;
Exception lastException = null;

for (int attempt = 1; attempt <= maxAttempts; attempt++) {
try {
webDriver.get(url);
return;
} catch (Exception e) {
lastException = e;

// callback exists and we have attempts left
if (driverResetCallback != null && attempt < maxAttempts) {
try {
Thread.sleep(10000); // Wait 10 seconds before retrying if it's some network issue.
webDriver = driverResetCallback.resetDriver();
} catch (Exception resetEx) {
// no-op, as we may have attempts left
}
} else if (attempt == maxAttempts) {
// Last attempt failed, throw exception
throw new RuntimeException("Failed to navigate to URL after " + maxAttempts + " attempts: " + url, lastException);
}
}
}
}

public String getTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import io.openliberty.org.apache.myfaces40.fat.tests.bugfixes.MyFaces4628Test;
import io.openliberty.org.apache.myfaces40.fat.tests.bugfixes.MyFaces4658Test;

import io.openliberty.faces.fat.selenium.util.internal.WebPage;

@RunWith(Suite.class)
@SuiteClasses({
AcceptInputFileTest.class,
Expand Down Expand Up @@ -152,6 +154,22 @@ public static ExtendedWebDriver getWebDriver() throws Exception {
if(DRIVER == null) {
throw new Exception("Failed to initialize WebDriver after multiple attempts! See log for details.");
}

// Register the driver reset callback statically for the WebPage to use if exceptions occur.
WebPage.setDriverResetCallback(() -> {
Log.info(c, "DriverResetCallback", "Resetting WebDriver due to some error. See log for details");
if (DRIVER != null) {
try {
DRIVER.quit();
} catch (Exception e) {
// no-op
}
DRIVER = null;
}
DRIVER = getWebDriver();
return DRIVER;
});

return DRIVER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testOnErrorWebsocket() throws Exception {

String contextRoot = "WebSocket";

String url = JSFUtils.createSeleniumURLString(server, contextRoot, "OnErrorWebSocketTest.jsf");;
String url = JSFUtils.createSeleniumURLString(server, contextRoot, "OnErrorWebSocketTest.jsf");
WebPage page = new WebPage(driver);
page.get(url);
page.waitForPageToLoad();
Expand Down