Skip to content

Commit

Permalink
Add test property to set the browser time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-tchad committed Feb 4, 2025
1 parent c8db5b2 commit 2dc901e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/org/labkey/test/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public static boolean isDumpBrowserConsole()
return getBooleanProperty("webtest.dump.browser.console", false);
}

public static String getBrowserTimeZone()
{
return System.getProperty("webtest.browser.tz");
}

public static double getTimeoutMultiplier()
{
return Math.max(0, getDoubleProperty("webtest.timeout.multiplier", 1.0));
Expand Down
18 changes: 14 additions & 4 deletions src/org/labkey/test/WebDriverWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.GeckoDriverService;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverService;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.service.DriverService;
Expand Down Expand Up @@ -210,6 +211,11 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri
WebDriver newWebDriver = null;
DriverService oldDriverService = oldDriverAndService.getRight();
DriverService newDriverService = null;
Map<String, String> browserEnv = new HashMap<>();
if (TestProperties.getBrowserTimeZone() != null)
{
browserEnv.put("TZ", TestProperties.getBrowserTimeZone());
}

switch (browserType)
{
Expand All @@ -236,7 +242,8 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri
}
if (oldWebDriver == null)
{
newWebDriver = new InternetExplorerDriver();
newDriverService = new InternetExplorerDriverService.Builder().withEnvironment(browserEnv).build();
newWebDriver = new InternetExplorerDriver((InternetExplorerDriverService) newDriverService);
}
break;
}
Expand Down Expand Up @@ -276,7 +283,7 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri
options.addArguments("headless");
}

newDriverService = ChromeDriverService.createDefaultService();
newDriverService = new ChromeDriverService.Builder().withEnvironment(browserEnv).build();
newWebDriver = new ChromeDriver((ChromeDriverService) newDriverService, options);
}
break;
Expand Down Expand Up @@ -373,7 +380,10 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri
capabilities.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
FirefoxOptions firefoxOptions = new FirefoxOptions(capabilities);

newDriverService = GeckoDriverService.createDefaultService();
GeckoDriverService.Builder driverServiceBuilder = new GeckoDriverService.Builder()
.withEnvironment(browserEnv);

newDriverService = driverServiceBuilder.build();
try
{
newWebDriver = new FirefoxDriver((FirefoxDriverService) newDriverService, firefoxOptions);
Expand All @@ -384,7 +394,7 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri
{
retry.printStackTrace(System.err);
newDriverService.stop();
newDriverService = GeckoDriverService.createDefaultService();
newDriverService = driverServiceBuilder.build();
sleep(10000);
newWebDriver = new FirefoxDriver((FirefoxDriverService) newDriverService, firefoxOptions);
}
Expand Down
2 changes: 2 additions & 0 deletions test.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ selenium.reuseWebDriver=true
#webtest.webdriver.headless=false
## Customize browser window size
#webtest.window.size=1280x1024
## Set browser time zone
#webtest.browser.tz=America/New_York


#==============================================================================
Expand Down

0 comments on commit 2dc901e

Please sign in to comment.