From b7f67e857819438b5292889288899952d34d2845 Mon Sep 17 00:00:00 2001 From: Trey Chadick Date: Mon, 4 Nov 2024 14:19:24 -0800 Subject: [PATCH] Set window size for new browser (#2119) --- src/org/labkey/test/BaseWebDriverTest.java | 21 ++------------------- src/org/labkey/test/TestProperties.java | 4 ++-- src/org/labkey/test/WebDriverWrapper.java | 8 ++++++++ 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/org/labkey/test/BaseWebDriverTest.java b/src/org/labkey/test/BaseWebDriverTest.java index 2337029c52..75febf25b9 100644 --- a/src/org/labkey/test/BaseWebDriverTest.java +++ b/src/org/labkey/test/BaseWebDriverTest.java @@ -310,7 +310,7 @@ public void setUp() SingletonWebDriver.getInstance().setUpWebDriver(this); - initWebDriverTimeoutsAndSize(); + initWebDriverTimeouts(); closeExtraWindows(); if (!TestProperties.isCspCheckSkipped() && cspFailFast()) @@ -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; - } - } - }); } /** diff --git a/src/org/labkey/test/TestProperties.java b/src/org/labkey/test/TestProperties.java index ba799e8342..e1feb53813 100644 --- a/src/org/labkey/test/TestProperties.java +++ b/src/org/labkey/test/TestProperties.java @@ -186,8 +186,8 @@ public static String getCloudPipelineBucketName() public static Optional 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]); diff --git a/src/org/labkey/test/WebDriverWrapper.java b/src/org/labkey/test/WebDriverWrapper.java index e80bec049a..ebde594655 100644 --- a/src/org/labkey/test/WebDriverWrapper.java +++ b/src/org/labkey/test/WebDriverWrapper.java @@ -403,6 +403,14 @@ protected Pair createNewWebDriver(@NotNull Pair 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();