Skip to content

Commit

Permalink
Set window size for new browser (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-tchad authored Nov 4, 2024
1 parent b9d90a2 commit b7f67e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
21 changes: 2 additions & 19 deletions src/org/labkey/test/BaseWebDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void setUp()

SingletonWebDriver.getInstance().setUpWebDriver(this);

initWebDriverTimeoutsAndSize();
initWebDriverTimeouts();
closeExtraWindows();

if (!TestProperties.isCspCheckSkipped() && cspFailFast())
Expand All @@ -320,29 +320,12 @@ public void setUp()
}

@LogMethod
private void initWebDriverTimeoutsAndSize()
private void initWebDriverTimeouts()
{
TestLogger.debug("set script timeout");
getDriver().manage().timeouts().scriptTimeout(Duration.ofMillis(WAIT_FOR_PAGE));
TestLogger.debug("page load timeout set");
getDriver().manage().timeouts().pageLoadTimeout(Duration.ofMillis(defaultWaitForPage));

TestProperties.getWindowSize().ifPresent(dimension -> {
try
{
TestLogger.info("set window size");
getDriver().manage().window().setSize(dimension);
}
catch (WebDriverException ex)
{
TestLogger.debug("failed to set window size");
// Ignore occasional error from attempting to resize maximized window
if (!ex.getMessage().contains("current state is maximized"))
{
throw ex;
}
}
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/org/labkey/test/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public static String getCloudPipelineBucketName()

public static Optional<Dimension> getWindowSize()
{
String dimensionStr = System.getProperty("webtest.window.size");
if (dimensionStr != null)
String dimensionStr = System.getProperty("webtest.window.size", "1280x1024");
if (!dimensionStr.isEmpty())
{
String[] dimensionParts = dimensionStr.split("x", 2);
int browserWidth = Integer.parseInt(dimensionParts[0]);
Expand Down
8 changes: 8 additions & 0 deletions src/org/labkey/test/WebDriverWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri

if (newWebDriver != null)
{

Optional<Dimension> windowSize = TestProperties.getWindowSize();
if (windowSize.isPresent())
{
TestLogger.info("Set window size: " + windowSize.get());
newWebDriver.manage().window().setSize(windowSize.get());
}

Capabilities caps = ((HasCapabilities) newWebDriver).getCapabilities();
String browserName = caps.getBrowserName();
String browserVersion = caps.getBrowserVersion();
Expand Down

0 comments on commit b7f67e8

Please sign in to comment.