From 9895f7e65d9b5c082efd4d417d376f8650073142 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Mon, 10 Jun 2024 09:25:31 +0300 Subject: [PATCH 01/17] add chrome responsive to browser types --- .../bellatrix/web/infrastructure/Browser.java | 1 + .../web/infrastructure/DeviceName.java | 1 + .../web/infrastructure/DriverService.java | 23 ++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java index 2ff16eb7..cff02608 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java @@ -19,6 +19,7 @@ public enum Browser { CHROME("chrome"), CHROME_HEADLESS("chrome_headless"), CHROME_MOBILE("chrome_mobile"), + CHROME_RESPONSIVE("chrome_responsive"), FIREFOX("firefox"), FIREFOX_HEADLESS("firefox_headless"), EDGE("edge"), diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java index 20f4cd2d..3f6310c6 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java @@ -19,6 +19,7 @@ public enum DeviceName { NOT_SET(), IPHONE_13_PRO_MOBILE("iPhone 13 Pro", 375, 667, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), + IPHONE_12_PRO_MOBILE("iPhone 12 Pro", 390, 844, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), IPHONE_SE_MOBILE("iPhone SE", 750, 1334, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), IPHONE_X_MOBILE("iPhone X", 375, 667, true, 3, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1"), NEXUS_7_TABLET("Nexus 7", 600, 960, true, 2, true, true, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Safari/537.36"), diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java index d21ebea1..873c1b5d 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java @@ -268,6 +268,28 @@ private static WebDriver initializeDriverRegularMode() { driver = new ChromeDriver(chromeHeadlessOptions); } + case CHROME_RESPONSIVE -> { + var chromeHeadlessOptions = new ChromeOptions(); + addDriverOptions(chromeHeadlessOptions); + chromeHeadlessOptions.setAcceptInsecureCerts(true); + chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*"); + chromeHeadlessOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); + + Map deviceMetrics = new HashMap<>(); + deviceMetrics.put("width", BROWSER_CONFIGURATION.get().getWidth()); + deviceMetrics.put("height", BROWSER_CONFIGURATION.get().getHeight()); + deviceMetrics.put("pixelRatio", 3.0); + + Map mobileEmulation = new HashMap<>(); + mobileEmulation.put("deviceMetrics", deviceMetrics); + mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"); + + chromeHeadlessOptions.setExperimentalOption("mobileEmulation", mobileEmulation); + System.setProperty("webdriver.chrome.silentOutput", "true"); + if (shouldCaptureHttpTraffic) chromeHeadlessOptions.setProxy(proxyConfig); + + driver = new TouchableWebDriver(chromeHeadlessOptions); + } case CHROME_MOBILE -> { var chromeHeadlessOptions = new ChromeOptions(); addDriverOptions(chromeHeadlessOptions); @@ -284,7 +306,6 @@ private static WebDriver initializeDriverRegularMode() { driver = new TouchableWebDriver(chromeHeadlessOptions); } - case FIREFOX -> { var firefoxOptions = new FirefoxOptions(); addDriverOptions(firefoxOptions); From eb0011c93fc275c42f0f0bd0646a6ff5501fc12f Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Mon, 10 Jun 2024 15:33:38 +0300 Subject: [PATCH 02/17] refactor responsive design testing --- .../bellatrix/web/infrastructure/Browser.java | 1 - .../infrastructure/BrowserConfiguration.java | 4 ++- .../web/infrastructure/DeviceName.java | 30 +++++++++---------- .../web/infrastructure/DriverService.java | 24 +++------------ 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java index cff02608..2ff16eb7 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java @@ -19,7 +19,6 @@ public enum Browser { CHROME("chrome"), CHROME_HEADLESS("chrome_headless"), CHROME_MOBILE("chrome_mobile"), - CHROME_RESPONSIVE("chrome_responsive"), FIREFOX("firefox"), FIREFOX_HEADLESS("firefox_headless"), EDGE("edge"), diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserConfiguration.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserConfiguration.java index 80205ff9..fe849269 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserConfiguration.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserConfiguration.java @@ -75,7 +75,9 @@ public boolean equals(Object obj) { if (!(obj instanceof BrowserConfiguration)) return false; BrowserConfiguration that = (BrowserConfiguration)obj; - if (!(this.getBrowser() == null ? that.getBrowser() == null : this.getBrowser().equals(that.getBrowser()))) + if (!((this.getBrowser() == null) ? (that.getBrowser() == null) : this.getBrowser().equals(that.getBrowser()))) + return false; + if (this.deviceName != that.deviceName) return false; if (!(this.getLifecycle() == null ? that.getLifecycle() == null : this.getLifecycle().equals(that.getLifecycle()))) return false; diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java index 3f6310c6..51396d0c 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java @@ -18,38 +18,38 @@ @Getter public enum DeviceName { NOT_SET(), - IPHONE_13_PRO_MOBILE("iPhone 13 Pro", 375, 667, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), - IPHONE_12_PRO_MOBILE("iPhone 12 Pro", 390, 844, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), - IPHONE_SE_MOBILE("iPhone SE", 750, 1334, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), - IPHONE_X_MOBILE("iPhone X", 375, 667, true, 3, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1"), - NEXUS_7_TABLET("Nexus 7", 600, 960, true, 2, true, true, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Safari/537.36"), - IPAD("Apple iPad", 768, 1024, true, 2, true, true, "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3"); + MOBILE_S("MOBILE_S", 300, 873, false, 1), + MOBILE_M("MOBILE_M", 320, 873, false, 1), + MOBILE_L("MOBILE_L", 393, 873, false, 1), + TABLET("TABLET", 768, 873, false, 1), + IPHONE_13_PRO_MOBILE("iPhone 13 Pro", 375, 667, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), + IPHONE_12_PRO_MOBILE("iPhone 12 Pro", 390, 844, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), + IPHONE_SE_MOBILE("iPhone SE", 750, 1334, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), + IPHONE_X_MOBILE("iPhone X", 375, 667, true, 3, "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1"), + NEXUS_7_TABLET("Nexus 7", 600, 960, true, 2, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Safari/537.36"), + IPAD("Apple iPad", 768, 1024, true, 2, "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3"); private final String name; private final int width; private final int height; private final boolean isMobile; private final int scaleFactor; - private final boolean supportsConsoleLogs; - private final boolean supportsFullPage; private final String userAgent; - DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor, boolean supportsConsoleLogs, boolean supportsFullPage) { - this(name, width, height, isMobile, scaleFactor, supportsConsoleLogs, supportsFullPage, null); + DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor) { + this(name, width, height, isMobile, scaleFactor, null); } DeviceName() { - this(null, 0, 0, false, 0, false, false, null); + this(null, 0, 0, false, 0, ""); } - DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor, boolean supportsConsoleLogs, boolean supportsFullPage, String userAgent) { + DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor, String userAgent) { this.name = name; this.width = width; this.height = height; this.isMobile = isMobile; this.scaleFactor = scaleFactor; - this.supportsConsoleLogs = supportsConsoleLogs; - this.supportsFullPage = supportsFullPage; this.userAgent = userAgent; } -} +} \ No newline at end of file diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java index 873c1b5d..b1f34203 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java @@ -268,7 +268,7 @@ private static WebDriver initializeDriverRegularMode() { driver = new ChromeDriver(chromeHeadlessOptions); } - case CHROME_RESPONSIVE -> { + case CHROME_MOBILE -> { var chromeHeadlessOptions = new ChromeOptions(); addDriverOptions(chromeHeadlessOptions); chromeHeadlessOptions.setAcceptInsecureCerts(true); @@ -276,9 +276,9 @@ private static WebDriver initializeDriverRegularMode() { chromeHeadlessOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); Map deviceMetrics = new HashMap<>(); - deviceMetrics.put("width", BROWSER_CONFIGURATION.get().getWidth()); - deviceMetrics.put("height", BROWSER_CONFIGURATION.get().getHeight()); - deviceMetrics.put("pixelRatio", 3.0); + deviceMetrics.put("width", BROWSER_CONFIGURATION.get().getDeviceName().getWidth()); + deviceMetrics.put("height", BROWSER_CONFIGURATION.get().getDeviceName().getHeight()); + deviceMetrics.put("pixelRatio", BROWSER_CONFIGURATION.get().getDeviceName().getScaleFactor()); Map mobileEmulation = new HashMap<>(); mobileEmulation.put("deviceMetrics", deviceMetrics); @@ -290,22 +290,6 @@ private static WebDriver initializeDriverRegularMode() { driver = new TouchableWebDriver(chromeHeadlessOptions); } - case CHROME_MOBILE -> { - var chromeHeadlessOptions = new ChromeOptions(); - addDriverOptions(chromeHeadlessOptions); - chromeHeadlessOptions.setAcceptInsecureCerts(true); - chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*"); - chromeHeadlessOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); - - var deviceNameOption = new HashMap(); - deviceNameOption.put("deviceName", BROWSER_CONFIGURATION.get().getDeviceName().getName()); - - chromeHeadlessOptions.setExperimentalOption("mobileEmulation", deviceNameOption); - System.setProperty("webdriver.chrome.silentOutput", "true"); - if (shouldCaptureHttpTraffic) chromeHeadlessOptions.setProxy(proxyConfig); - - driver = new TouchableWebDriver(chromeHeadlessOptions); - } case FIREFOX -> { var firefoxOptions = new FirefoxOptions(); addDriverOptions(firefoxOptions); From d3904bfa57b219d63021486293b2386bed6bcdd1 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Tue, 11 Jun 2024 13:38:50 +0300 Subject: [PATCH 03/17] add hold event into TouchableWebDriver --- .../web/infrastructure/TouchableWebDriver.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/TouchableWebDriver.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/TouchableWebDriver.java index 403d6580..bf2c1706 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/TouchableWebDriver.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/TouchableWebDriver.java @@ -43,6 +43,21 @@ public void triggerTapEvent(WebElement swipeFromElement) tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); this.perform(Arrays.asList(tap)); } + + public void triggerHoldEvent(WebElement swipeFromElement) { + PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); + Sequence tap = new Sequence(finger, 1); + + int centerX = swipeFromElement.getLocation().x + swipeFromElement.getSize().getWidth() / 2; + int centerY = swipeFromElement.getLocation().y + swipeFromElement.getSize().getHeight() / 2; + + // Move to the center of the element and perform a tap + tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), centerX, centerY)); + tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); + tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); + this.perform(Arrays.asList(tap)); + } + // // public void triggerTapEvent(WebElement tapElement) // { From 15fd1cd91692a27b0c8c5ec9a9ba9fb9ba38dddb Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Thu, 13 Jun 2024 16:42:27 +0300 Subject: [PATCH 04/17] fix Devices enum --- .../solutions/bellatrix/web/infrastructure/DeviceName.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java index 51396d0c..69e3ca2c 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DeviceName.java @@ -24,8 +24,8 @@ public enum DeviceName { TABLET("TABLET", 768, 873, false, 1), IPHONE_13_PRO_MOBILE("iPhone 13 Pro", 375, 667, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), IPHONE_12_PRO_MOBILE("iPhone 12 Pro", 390, 844, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), - IPHONE_SE_MOBILE("iPhone SE", 750, 1334, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), - IPHONE_X_MOBILE("iPhone X", 375, 667, true, 3, "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1"), + IPHONE_SE_MOBILE("iPhone SE", 375, 667, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"), + IPHONE_X_MOBILE("iPhone X", 375, 667, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1"), NEXUS_7_TABLET("Nexus 7", 600, 960, true, 2, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Safari/537.36"), IPAD("Apple iPad", 768, 1024, true, 2, "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3"); From ffe6d9cae650f4443c4ebc07b43057a75fd9e723 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Wed, 3 Jul 2024 16:09:32 +0300 Subject: [PATCH 05/17] enhance drop-down wait logic to utilize Proxy Service if available --- .../bellatrix/web/services/BrowserService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java index c4d9c675..121ee82d 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java @@ -19,6 +19,7 @@ import org.openqa.selenium.*; import org.openqa.selenium.logging.LogEntry; import org.openqa.selenium.logging.LogType; +import org.openqa.selenium.remote.http.HttpMethod; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; @@ -27,6 +28,7 @@ import solutions.bellatrix.core.utilities.Wait; import solutions.bellatrix.web.components.Frame; import solutions.bellatrix.web.configuration.WebSettings; +import solutions.bellatrix.web.infrastructure.ProxyServer; import java.net.URI; import java.net.URISyntaxException; @@ -417,11 +419,14 @@ public void waitForRequest(String partialUrl) { } public void tryWaitForRequest(String partialUrl) { - var javascriptExecutor = (JavascriptExecutor)getWrappedDriver(); - String script = "return performance.getEntriesByType('resource').filter(item => item.name.toLowerCase().includes('" + partialUrl.toLowerCase() + "'))[0] !== undefined;"; - try { - waitUntil(e -> (boolean)javascriptExecutor.executeScript(script)); + if(ProxyServer.get() != null) { + ProxyServer.waitForResponse(getWrappedDriver(), partialUrl, HttpMethod.GET, 0); + } else { + var javascriptExecutor = (JavascriptExecutor)getWrappedDriver(); + String script = "return performance.getEntriesByType('resource').filter(item => item.name.toLowerCase().includes('" + partialUrl.toLowerCase() + "'))[0] !== undefined;"; + waitUntil(e -> (boolean)javascriptExecutor.executeScript(script)); + } } catch (Exception exception) { Log.error("The expected request with URL '%s' is not loaded!", partialUrl); } From 95bf831d9b76fd7729c2850ce564a9fa7bb0879d Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Thu, 4 Jul 2024 12:31:03 +0300 Subject: [PATCH 06/17] add static wait in Wait Service --- .../java/solutions/bellatrix/core/utilities/Wait.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java index 136a1d80..4d19b654 100644 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java @@ -77,4 +77,12 @@ public static boolean retry(Runnable action, Duration timeout, Duration sleepInt public static void retry(Runnable action, Duration timeout, Duration sleepInterval, Class ... exceptionsToIgnore) { Wait.retry(action, timeout, sleepInterval, true, exceptionsToIgnore); } + + public static void forMilliseconds(int millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } } From dd29af85e40bc1694e48615dbe8e6db3e7c49c3c Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Thu, 11 Jul 2024 15:56:40 +0300 Subject: [PATCH 07/17] wait for ajax temporary disable --- .../web/services/BrowserService.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java index 121ee82d..793a7b25 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java @@ -209,22 +209,24 @@ public List getSevereLogEntries() { } public void waitForAjax() { - long ajaxTimeout = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getWaitForAjaxTimeout(); - long sleepInterval = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getSleepInterval(); - var webDriverWait = new WebDriverWait(getWrappedDriver(), Duration.ofSeconds(ajaxTimeout), Duration.ofSeconds(sleepInterval)); - var javascriptExecutor = (JavascriptExecutor)getWrappedDriver(); - webDriverWait.until(d -> { - var numberOfAjaxConnections = javascriptExecutor.executeScript("return !isNaN(window.openHTTPs) ? window.openHTTPs : null"); - if (Objects.nonNull(numberOfAjaxConnections)) { - int ajaxConnections = Integer.parseInt(numberOfAjaxConnections.toString()); - return ajaxConnections == 0; - } else { - monkeyPatchXMLHttpRequest(); - } - - return false; - } - ); + waitUntilPageLoadsCompletely(); + // TODO: navramov 11/07/2024 Uncomment when a better way is found as it causes the system to throw console errors +// long ajaxTimeout = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getWaitForAjaxTimeout(); +// long sleepInterval = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getSleepInterval(); +// var webDriverWait = new WebDriverWait(getWrappedDriver(), Duration.ofSeconds(ajaxTimeout), Duration.ofSeconds(sleepInterval)); +// var javascriptExecutor = (JavascriptExecutor)getWrappedDriver(); +// webDriverWait.until(d -> { +// var numberOfAjaxConnections = javascriptExecutor.executeScript("return !isNaN(window.openHTTPs) ? window.openHTTPs : null"); +// if (Objects.nonNull(numberOfAjaxConnections)) { +// int ajaxConnections = Integer.parseInt(numberOfAjaxConnections.toString()); +// return ajaxConnections == 0; +// } else { +// monkeyPatchXMLHttpRequest(); +// } +// +// return false; +// } +// ); } private void monkeyPatchXMLHttpRequest() { From 9e760320753fc520c8ee7e78d8a61d184ed057ea Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Mon, 15 Jul 2024 13:01:46 +0300 Subject: [PATCH 08/17] fix wait for Ajax --- .../web/services/BrowserService.java | 67 +++++++++---------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java index 793a7b25..c9339869 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java @@ -209,45 +209,40 @@ public List getSevereLogEntries() { } public void waitForAjax() { - waitUntilPageLoadsCompletely(); - // TODO: navramov 11/07/2024 Uncomment when a better way is found as it causes the system to throw console errors -// long ajaxTimeout = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getWaitForAjaxTimeout(); -// long sleepInterval = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getSleepInterval(); -// var webDriverWait = new WebDriverWait(getWrappedDriver(), Duration.ofSeconds(ajaxTimeout), Duration.ofSeconds(sleepInterval)); -// var javascriptExecutor = (JavascriptExecutor)getWrappedDriver(); -// webDriverWait.until(d -> { -// var numberOfAjaxConnections = javascriptExecutor.executeScript("return !isNaN(window.openHTTPs) ? window.openHTTPs : null"); -// if (Objects.nonNull(numberOfAjaxConnections)) { -// int ajaxConnections = Integer.parseInt(numberOfAjaxConnections.toString()); -// return ajaxConnections == 0; -// } else { -// monkeyPatchXMLHttpRequest(); -// } -// -// return false; -// } -// ); + long ajaxTimeout = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getWaitForAjaxTimeout(); + long sleepInterval = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getSleepInterval(); + var webDriverWait = new WebDriverWait(getWrappedDriver(), Duration.ofSeconds(ajaxTimeout), Duration.ofSeconds(sleepInterval)); + var javascriptExecutor = (JavascriptExecutor)getWrappedDriver(); + webDriverWait.until(d -> { + var numberOfAjaxConnections = javascriptExecutor.executeScript("return !isNaN(window.$openHTTPs) ? window.$openHTTPs : null"); + if (Objects.nonNull(numberOfAjaxConnections)) { + int ajaxConnections = Integer.parseInt(numberOfAjaxConnections.toString()); + return ajaxConnections == 0; + } else { + monkeyPatchXMLHttpRequest(); + } + + return false; + }); } private void monkeyPatchXMLHttpRequest() { - var numberOfAjaxConnections = javascriptExecutor.executeScript(("return !isNaN(window.openHTTPs) ? window.openHTTPs : null")); - - if (Objects.nonNull(numberOfAjaxConnections)) { - var ajaxConnections = Integer.parseInt(numberOfAjaxConnections.toString()); - } else { - var script = " (function() {" + - "var oldOpen = XMLHttpRequest.prototype.open;" + - "window.openHTTPs = 0;" + - "XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {" + - "window.openHTTPs++;" + - "this.addEventListener('readystatechange', function() {" + - "if(this.readyState == 4) {" + - "window.openHTTPs--;" + - "}" + - "}, false);" + - "oldOpen.call(this, method, url, async, user, pass);" + - "}" + - "})();"; + var numberOfAjaxConnections = javascriptExecutor.executeScript(("return !isNaN(window.$openHTTPs) ? window.$openHTTPs : null")); + + if (Objects.isNull(numberOfAjaxConnections)) { + var script = "(function() {" + + "const oldOpen = XMLHttpRequest.prototype.open;" + + "window.$openHTTPs = 0;" + + "XMLHttpRequest.prototype.open = function() {" + + "window.$openHTTPs++;" + + "this.addEventListener('readystatechange', function() {" + + "if(this.readyState == 4) {" + + "window.$openHTTPs--;" + + "}" + + "}, false);" + + "return oldOpen.call(this, ...arguments);" + + "}" + + "})();"; javascriptExecutor.executeScript(script); } From ca105ca6059f4ee6f1059a643badd9abda54b7f0 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Fri, 19 Jul 2024 12:50:52 +0300 Subject: [PATCH 09/17] DO NOT ADD AZURE DEPENDENCIES AS THEY BREAK PROXY SERVER --- bellatrix.core/pom.xml | 10 ---------- .../core/integrations/azure/KeyVaultSettings.java | 9 --------- 2 files changed, 19 deletions(-) delete mode 100644 bellatrix.core/src/main/java/solutions/bellatrix/core/integrations/azure/KeyVaultSettings.java diff --git a/bellatrix.core/pom.xml b/bellatrix.core/pom.xml index 478c5657..667a658e 100644 --- a/bellatrix.core/pom.xml +++ b/bellatrix.core/pom.xml @@ -153,16 +153,6 @@ ${rest.assured.version} compile - - com.azure - azure-security-keyvault-secrets - 4.2.3 - - - com.azure - azure-identity - 1.2.0 - org.jsoup jsoup diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/integrations/azure/KeyVaultSettings.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/integrations/azure/KeyVaultSettings.java deleted file mode 100644 index 6234a82c..00000000 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/integrations/azure/KeyVaultSettings.java +++ /dev/null @@ -1,9 +0,0 @@ -package solutions.bellatrix.core.integrations.azure; - -import lombok.Data; - -@Data -public class KeyVaultSettings { - private String keyVaultEndpoint; - private boolean isEnabled; -} \ No newline at end of file From 8091a93d3481c0d6f48ffa99e2b869bd6b1093d4 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Mon, 22 Jul 2024 11:50:33 +0300 Subject: [PATCH 10/17] simplify logic for browser starting --- .../BrowserLifecyclePlugin.java | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java index fc5e6b65..0a1d8f2c 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java @@ -26,53 +26,38 @@ public class BrowserLifecyclePlugin extends Plugin { private static final ThreadLocal CURRENT_BROWSER_CONFIGURATION; private static final ThreadLocal PREVIOUS_BROWSER_CONFIGURATION; - private static final ThreadLocal IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS; private static final ThreadLocal IS_BROWSER_STARTED_CORRECTLY; static { CURRENT_BROWSER_CONFIGURATION = new ThreadLocal<>(); PREVIOUS_BROWSER_CONFIGURATION = new ThreadLocal<>(); - IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS = ThreadLocal.withInitial(() -> false); IS_BROWSER_STARTED_CORRECTLY = ThreadLocal.withInitial(() -> false); } @Override public void preBeforeClass(Class type) { if (Objects.equals(ConfigurationService.get(WebSettings.class).getExecutionType(), "regular")) { - CURRENT_BROWSER_CONFIGURATION.set(getExecutionBrowserClassLevel(type)); if (shouldRestartBrowser()) { shutdownBrowser(); startBrowser(); - // TODO: maybe we can simplify and remove this parameter. - IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(true); - } else { - IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false); } - } else { - IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false); } - super.preBeforeClass(type); } @Override public void postAfterClass(Class type) { shutdownBrowser(); - IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false); super.preAfterClass(type); } @Override public void preBeforeTest(TestResult testResult, Method memberInfo) { CURRENT_BROWSER_CONFIGURATION.set(getBrowserConfiguration(memberInfo)); - - if (!IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.get()) { - if (shouldRestartBrowser()) { - startBrowser(); - } + if (shouldRestartBrowser()) { + shutdownBrowser(); + startBrowser(); } - - IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false); } @Override From fd8ff3909fa30e6784a9326bf89a99b6f4955304 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Mon, 22 Jul 2024 15:18:14 +0300 Subject: [PATCH 11/17] fix issues with browser lifecycle. --- .../bellatrix/core/utilities/Wait.java | 2 +- .../BrowserLifecyclePlugin.java | 11 ++++-- .../web/services/BrowserService.java | 37 +++++++++++++------ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java index d710946f..84b06be1 100644 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/Wait.java @@ -74,7 +74,7 @@ public static boolean retry(Runnable action, Duration timeout, Duration sleepInt return true; } - public static void retry(Runnable action, Duration timeout, Duration sleepInterval, Class ... exceptionsToIgnore) { + public static void retry(Runnable action, Duration sleepInterval, Duration timeout, Class ... exceptionsToIgnore) { Wait.retry(action, timeout, sleepInterval, true, exceptionsToIgnore); } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java index 0a1d8f2c..0b92bed2 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java @@ -16,11 +16,12 @@ import solutions.bellatrix.core.configuration.ConfigurationService; import solutions.bellatrix.core.plugins.Plugin; import solutions.bellatrix.core.plugins.TestResult; -import solutions.bellatrix.core.utilities.DebugInformation; +import solutions.bellatrix.core.utilities.Log; import solutions.bellatrix.core.utilities.SecretsResolver; import solutions.bellatrix.web.configuration.WebSettings; import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.Objects; public class BrowserLifecyclePlugin extends Plugin { @@ -37,6 +38,7 @@ public class BrowserLifecyclePlugin extends Plugin { @Override public void preBeforeClass(Class type) { if (Objects.equals(ConfigurationService.get(WebSettings.class).getExecutionType(), "regular")) { + CURRENT_BROWSER_CONFIGURATION.set(getBrowserConfiguration(type)); if (shouldRestartBrowser()) { shutdownBrowser(); startBrowser(); @@ -86,12 +88,11 @@ private void shutdownBrowser() { } private void startBrowser() { -// shutdownBrowser(); try { DriverService.start(CURRENT_BROWSER_CONFIGURATION.get()); IS_BROWSER_STARTED_CORRECTLY.set(true); } catch (Exception ex) { - DebugInformation.printStackTrace(ex); + Log.error("Error occurred while trying to start browser: %s".formatted(ex.getMessage())); IS_BROWSER_STARTED_CORRECTLY.set(false); } @@ -127,6 +128,10 @@ private BrowserConfiguration getBrowserConfiguration(Method memberInfo) { return result; } + private BrowserConfiguration getBrowserConfiguration(Type classType) { + return getExecutionBrowserClassLevel(classType.getClass()); + } + private BrowserConfiguration getExecutionBrowserMethodLevel(Method memberInfo) { if (!memberInfo.isAnnotationPresent(ExecutionBrowser.class)) return null; diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java index c9339869..5fc02c0d 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java @@ -211,19 +211,32 @@ public List getSevereLogEntries() { public void waitForAjax() { long ajaxTimeout = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getWaitForAjaxTimeout(); long sleepInterval = ConfigurationService.get(WebSettings.class).getTimeoutSettings().getSleepInterval(); - var webDriverWait = new WebDriverWait(getWrappedDriver(), Duration.ofSeconds(ajaxTimeout), Duration.ofSeconds(sleepInterval)); var javascriptExecutor = (JavascriptExecutor)getWrappedDriver(); - webDriverWait.until(d -> { - var numberOfAjaxConnections = javascriptExecutor.executeScript("return !isNaN(window.$openHTTPs) ? window.$openHTTPs : null"); - if (Objects.nonNull(numberOfAjaxConnections)) { - int ajaxConnections = Integer.parseInt(numberOfAjaxConnections.toString()); - return ajaxConnections == 0; - } else { - monkeyPatchXMLHttpRequest(); - } - - return false; - }); + try { + Wait.retry(() -> { + var numberOfAjaxConnections = javascriptExecutor.executeScript("return !isNaN(window.$openHTTPs) ? window.$openHTTPs : null"); + if (Objects.nonNull(numberOfAjaxConnections)) { + int ajaxConnections = Integer.parseInt(numberOfAjaxConnections.toString()); + if (ajaxConnections > 0) { + String message = "Waiting for %s Ajax Connections...".formatted(ajaxConnections); + injectInfoNotificationToast(message); + Log.info(message); + throw new TimeoutException(message); + } + } else { + monkeyPatchXMLHttpRequest(); + } + }, + Duration.ofSeconds(ajaxTimeout), + Duration.ofSeconds(sleepInterval), + true, + TimeoutException.class); + } + catch (Exception e) { + var message = "Timed out waiting for Ajax connections."; + Log.error(message); + injectErrorNotificationToast(message); + } } private void monkeyPatchXMLHttpRequest() { From ed0971ff4408ec8e6d558c004a56b2562ab06d55 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Fri, 2 Aug 2024 14:32:13 +0300 Subject: [PATCH 12/17] fix issue in BrowserLifecyclePlugin not passing correct Test Class Type --- .../bellatrix/web/infrastructure/BrowserLifecyclePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java index 0b92bed2..f36893e2 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/BrowserLifecyclePlugin.java @@ -129,7 +129,7 @@ private BrowserConfiguration getBrowserConfiguration(Method memberInfo) { } private BrowserConfiguration getBrowserConfiguration(Type classType) { - return getExecutionBrowserClassLevel(classType.getClass()); + return getExecutionBrowserClassLevel((Class)classType); } private BrowserConfiguration getExecutionBrowserMethodLevel(Method memberInfo) { From 93d9fec18aa88d711355f22ee4f66062796b9f63 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Mon, 5 Aug 2024 09:51:03 +0300 Subject: [PATCH 13/17] disable search engine notification --- .../playwright/infrastructure/PlaywrightService.java | 4 ++-- .../bellatrix/web/infrastructure/DriverService.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/PlaywrightService.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/PlaywrightService.java index 5bc13405..1da0af99 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/PlaywrightService.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/PlaywrightService.java @@ -155,7 +155,7 @@ private static Browser initializeBrowserRegularMode() { BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions(); launchOptions.setChannel("chrome"); launchOptions.setHeadless(false); - launchOptions.setArgs(List.of("--log-level=3", "--remote-allow-origins=*")); + launchOptions.setArgs(List.of("--log-level=3", "--remote-allow-origins=*", "--disable-search-engine-choice-screen")); launchOptions.setTimeout(Settings.web().getArtificialDelayBeforeAction()); // System.setProperty("webdriver.chrome.silentOutput", "true"); ? @@ -166,7 +166,7 @@ private static Browser initializeBrowserRegularMode() { BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions(); launchOptions.setChannel("chrome"); launchOptions.setHeadless(true); - launchOptions.setArgs(List.of("--log-level=3")); + launchOptions.setArgs(List.of("--log-level=3", "--disable-search-engine-choice-screen")); // System.setProperty("webdriver.chrome.silentOutput", "true"); ? return browser(browserType.launch(launchOptions)); diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java index 36351b87..b6b4a388 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/DriverService.java @@ -252,7 +252,7 @@ private static WebDriver initializeDriverRegularMode() { var chromeOptions = new ChromeOptions(); addDriverOptions(chromeOptions); addDriverCapabilities(chromeOptions); - chromeOptions.addArguments("--log-level=3","--remote-allow-origins=*"); + chromeOptions.addArguments("--log-level=3","--remote-allow-origins=*", "--disable-search-engine-choice-screen"); chromeOptions.setAcceptInsecureCerts(true); chromeOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); System.setProperty("webdriver.chrome.silentOutput", "true"); @@ -266,7 +266,7 @@ private static WebDriver initializeDriverRegularMode() { var chromeHeadlessOptions = new ChromeOptions(); addDriverOptions(chromeHeadlessOptions); chromeHeadlessOptions.setAcceptInsecureCerts(true); - chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*"); + chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*", "--disable-search-engine-choice-screen"); chromeHeadlessOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); chromeHeadlessOptions.addArguments("--headless=old"); System.setProperty("webdriver.chrome.silentOutput", "true"); @@ -278,7 +278,7 @@ private static WebDriver initializeDriverRegularMode() { var chromeHeadlessOptions = new ChromeOptions(); addDriverOptions(chromeHeadlessOptions); chromeHeadlessOptions.setAcceptInsecureCerts(true); - chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*"); + chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*", "--disable-search-engine-choice-screen"); chromeHeadlessOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); Map deviceMetrics = new HashMap<>(); From e19b5ac713dab0a72fbdfa21adec44fb05c13206 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Mon, 5 Aug 2024 15:49:41 +0300 Subject: [PATCH 14/17] rename wait method --- .../java/solutions/bellatrix/web/services/BrowserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java index 5fc02c0d..416e313b 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/BrowserService.java @@ -428,7 +428,7 @@ public void waitForRequest(String partialUrl) { } } - public void tryWaitForRequest(String partialUrl) { + public void tryWaitForResponse(String partialUrl) { try { if(ProxyServer.get() != null) { ProxyServer.waitForResponse(getWrappedDriver(), partialUrl, HttpMethod.GET, 0); From 9dfeb07219b3f0939b21ea658e5917ed4058e69a Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Tue, 13 Aug 2024 15:16:48 +0300 Subject: [PATCH 15/17] add default wait for page load --- .../src/main/java/solutions/bellatrix/web/pages/WebPage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java index e8bd15f1..593c94c2 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java @@ -71,5 +71,6 @@ public void open() { } protected void waitForPageLoad() { + browser().waitForAjax(); } } From 591d777db395569860d1c80738db09c4dfa73cb1 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Wed, 21 Aug 2024 10:54:21 +0300 Subject: [PATCH 16/17] fix proxyServer matching partial url with a space --- .../solutions/bellatrix/web/infrastructure/ProxyServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java index 3cf46682..65ef8c30 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java @@ -151,7 +151,7 @@ public static void waitForResponse(WebDriver driver, String requestPartialUrl, H webDriverWait.until(d -> { var harEntries = PROXY_SERVER.get().getHar().getLog().getEntries(); var isResponseReceived = harEntries.stream().anyMatch( - r -> r.getRequest().getUrl().contains(requestPartialUrl) + r -> (r.getRequest().getUrl().contains(requestPartialUrl) || r.getRequest().getUrl().contains(requestPartialUrl.replace("%20", "+"))) && r.getRequest().getMethod().equals(httpMethod.toString()) && successHttpStatusesList.contains(r.getResponse().getStatus()) && (httpMethod.equals(HttpMethod.DELETE)? true : (r.getResponse().getContent().getText() != null && !r.getResponse().getContent().getText().isEmpty())) From 5b313de6b87836d7a46a1b8652855fbc02b108c5 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Wed, 28 Aug 2024 10:49:24 +0300 Subject: [PATCH 17/17] fix restart browser issue - not clearing up Singleton Factory services --- .../solutions/bellatrix/core/utilities/SingletonFactory.java | 4 ++++ .../src/main/java/solutions/bellatrix/web/services/App.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/SingletonFactory.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/SingletonFactory.java index 4676393a..36d32ddc 100644 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/SingletonFactory.java +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/SingletonFactory.java @@ -48,4 +48,8 @@ public static void register(T instance) { public static void register(Class classKey, T instance) { mapHolder.get().put(classKey, instance); } + + public static void clear() { + mapHolder.get().clear(); + } } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/App.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/App.java index 5eb6a63a..da557850 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/services/App.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/services/App.java @@ -86,7 +86,7 @@ public void close() { } DriverService.close(); - + SingletonFactory.clear(); disposed = true; } }