From 16de15adbc5521a18cf42b14b01190a95fc67bc5 Mon Sep 17 00:00:00 2001 From: Martin Muzikar Date: Mon, 18 Mar 2024 10:53:41 +0100 Subject: [PATCH 1/3] fix(e2e): disable chrome password prompts --- .../hawt/tests/features/setup/WebDriver.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java index dfa56737cc..1c2c9c4350 100644 --- a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java +++ b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java @@ -1,15 +1,14 @@ package io.hawt.tests.features.setup; -import org.openqa.selenium.Capabilities; import org.openqa.selenium.chrome.ChromeDriverService; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.firefox.GeckoDriverService; -import org.openqa.selenium.remote.DesiredCapabilities; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.codeborne.selenide.Configuration; import com.codeborne.selenide.Selenide; +import com.google.common.collect.ImmutableMap; import java.nio.file.Path; import java.util.Arrays; @@ -30,13 +29,21 @@ public static void setup() { System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "target/driver.log"); } System.setProperty("hawtio.proxyWhitelist", "localhost, 127.0.0.1"); + // System.setProperty("chromeoptions.args", ); + if (Configuration.browser.equals("chrome")) { + ChromeOptions options = new ChromeOptions(); + options.setExperimentalOption("prefs", ImmutableMap.of("credentials_enable_service", false, "profile.password_manager_enabled", false)); + Configuration.browserCapabilities = options; + } Configuration.headless = TestConfiguration.browserHeadless(); Configuration.browserSize = "1920x1080"; Configuration.timeout = 20000; + } /** - * Setup drivers when running in container - avoid fetching driver from Internet every run + * Setup drivers when running in container - avoid fetching driver from Internet + * every run */ private static void setupDriverPaths() { Path optFolder = Path.of("/", "opt"); @@ -45,9 +52,10 @@ private static void setupDriverPaths() { }); Path seleniumFolder = optFolder.resolve("selenium"); Arrays.stream(seleniumFolder.toFile().list()).filter(f -> f.startsWith("chromedriver")).findFirst() - .ifPresent(path -> { - System.setProperty("webdriver.chrome.driver", seleniumFolder.resolve(path).toAbsolutePath().toString()); - }); + .ifPresent(path -> { + System.setProperty("webdriver.chrome.driver", + seleniumFolder.resolve(path).toAbsolutePath().toString()); + }); } /** From 8fb1c6af6a6ea004446dd16137643f2747893fcc Mon Sep 17 00:00:00 2001 From: Martin Muzikar Date: Mon, 18 Mar 2024 10:54:13 +0100 Subject: [PATCH 2/3] fix(e2e): fix click on connect button --- .../pageobjects/pages/ConnectPage.java | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java index 42bdf4515e..bc7600a25e 100644 --- a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java +++ b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java @@ -1,15 +1,17 @@ package io.hawt.tests.features.pageobjects.pages; -import com.codeborne.selenide.Condition; -import com.codeborne.selenide.Selenide; -import io.hawt.tests.features.config.TestConfiguration; -import io.hawt.tests.features.setup.LoginLogout; +import static com.codeborne.selenide.Selenide.$; + import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; +import com.codeborne.selenide.Condition; +import com.codeborne.selenide.Selenide; + import java.net.URL; +import java.time.Duration; -import static com.codeborne.selenide.Selenide.$; +import io.hawt.tests.features.config.TestConfiguration; public class ConnectPage extends HawtioPage { @@ -25,28 +27,28 @@ public class ConnectPage extends HawtioPage { public void addConnection(String name, URL connection) { - if ($(CONNECTION_LIST).isDisplayed()) { - /* I have added if-else construct due to the reason that on re-occurring error screenshots, it seemed like the test-connection already existed. + if ($(CONNECTION_LIST).isDisplayed()) { + /* I have added if-else construct due to the reason that on re-occurring error screenshots, it seemed like the test-connection already + existed. TO-DO: task for further examination and potential refinement */ - return; - } else { - $(CONNECT_BUTTON).shouldBe(Condition.interactable).click(); + return; + } else { + $(CONNECT_BUTTON).shouldBe(Condition.interactable).click(); - $(CONNECTION_FORM).$(By.id("connection-form-name")).setValue(name); - $(CONNECTION_FORM).$(By.id("connection-form-host")).setValue(connection.getHost()); - $(CONNECTION_FORM).$(By.id("connection-form-port")).setValue(String.valueOf(connection.getPort())); - $(CONNECTION_FORM).$(By.id("connection-form-path")).setValue(connection.getPath()); + $(CONNECTION_FORM).$(By.id("connection-form-name")).setValue(name); + $(CONNECTION_FORM).$(By.id("connection-form-host")).setValue(connection.getHost()); + $(CONNECTION_FORM).$(By.id("connection-form-port")).setValue(String.valueOf(connection.getPort())); + $(CONNECTION_FORM).$(By.id("connection-form-path")).setValue(connection.getPath()); - if (!connection.getPath().endsWith("/jolokia")) { - $(CONNECTION_FORM).$(By.id("connection-form-path")).sendKeys("/jolokia"); - } + if (!connection.getPath().endsWith("/jolokia")) { + $(CONNECTION_FORM).$(By.id("connection-form-path")).sendKeys("/jolokia"); + } - if ("https".equals(connection.getProtocol())) { - $(CONNECTION_FORM).$(By.id("connection-form-scheme")).click(); - } - - $(MODAL).$(FOOTER_BUTTON).click(); + if ("https".equals(connection.getProtocol())) { + $(CONNECTION_FORM).$(By.id("connection-form-scheme")).click(); + } + $(MODAL).$(FOOTER_BUTTON).click(); } } @@ -56,14 +58,14 @@ public void connectTo(String name) { final String username = TestConfiguration.getConnectAppUsername(); final String password = TestConfiguration.getConnectAppPassword(); - $(CONNECTION_LIST).$(connectionSelector).click(); + $(CONNECTION_LIST).$(connectionSelector).shouldBe(Condition.interactable, Duration.ofSeconds(5)) + .click(); Selenide.Wait().until(ExpectedConditions.numberOfWindowsToBe(2)); Selenide.switchTo().window(1); $(CONNECTION_LOGIN_FORM).$(By.id("connect-login-form-username")).setValue(username); $(CONNECTION_LOGIN_FORM).$(By.id("connect-login-form-password")).setValue(password); - $(MODAL).$(FOOTER_BUTTON).click(); - + $(MODAL).$(FOOTER_BUTTON).shouldBe(Condition.interactable, Duration.ofSeconds(5)).click(); } } From 993d2b2d351baacd084e2d30a29856d4dc08a370 Mon Sep 17 00:00:00 2001 From: Martin Muzikar Date: Wed, 20 Mar 2024 10:41:05 +0100 Subject: [PATCH 3/3] fix(e2e): workaround proxy not having access to crypto API & add waits for login --- .../pageobjects/pages/ConnectPage.java | 34 +++++++++---------- .../features/pageobjects/pages/LoginPage.java | 15 +++++--- .../hawt/tests/features/setup/WebDriver.java | 8 ++++- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java index bc7600a25e..a408aee596 100644 --- a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java +++ b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/ConnectPage.java @@ -12,6 +12,7 @@ import java.time.Duration; import io.hawt.tests.features.config.TestConfiguration; +import io.hawt.tests.features.utils.ByUtils; public class ConnectPage extends HawtioPage { @@ -26,30 +27,27 @@ public class ConnectPage extends HawtioPage { private static final By FOOTER_BUTTON = By.cssSelector("footer button.pf-m-primary"); public void addConnection(String name, URL connection) { - - if ($(CONNECTION_LIST).isDisplayed()) { - /* I have added if-else construct due to the reason that on re-occurring error screenshots, it seemed like the test-connection already - existed. - TO-DO: task for further examination and potential refinement */ + //Don't try to create the same connection twice + if ($(ByUtils.byAttribute("rowid", "connection " + name)).exists()) { return; - } else { - $(CONNECT_BUTTON).shouldBe(Condition.interactable).click(); + } - $(CONNECTION_FORM).$(By.id("connection-form-name")).setValue(name); - $(CONNECTION_FORM).$(By.id("connection-form-host")).setValue(connection.getHost()); - $(CONNECTION_FORM).$(By.id("connection-form-port")).setValue(String.valueOf(connection.getPort())); - $(CONNECTION_FORM).$(By.id("connection-form-path")).setValue(connection.getPath()); + $(CONNECT_BUTTON).shouldBe(Condition.interactable).click(); - if (!connection.getPath().endsWith("/jolokia")) { - $(CONNECTION_FORM).$(By.id("connection-form-path")).sendKeys("/jolokia"); - } + $(CONNECTION_FORM).$(By.id("connection-form-name")).setValue(name); + $(CONNECTION_FORM).$(By.id("connection-form-host")).setValue(connection.getHost()); + $(CONNECTION_FORM).$(By.id("connection-form-port")).setValue(String.valueOf(connection.getPort())); + $(CONNECTION_FORM).$(By.id("connection-form-path")).setValue(connection.getPath()); - if ("https".equals(connection.getProtocol())) { - $(CONNECTION_FORM).$(By.id("connection-form-scheme")).click(); - } + if (!connection.getPath().endsWith("/jolokia")) { + $(CONNECTION_FORM).$(By.id("connection-form-path")).sendKeys("/jolokia"); + } - $(MODAL).$(FOOTER_BUTTON).click(); + if ("https".equals(connection.getProtocol())) { + $(CONNECTION_FORM).$(By.id("connection-form-scheme")).click(); } + + $(MODAL).$(FOOTER_BUTTON).click(); } public void connectTo(String name) { diff --git a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/LoginPage.java b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/LoginPage.java index 48e1621493..bd6b2820f8 100644 --- a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/LoginPage.java +++ b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/pageobjects/pages/LoginPage.java @@ -6,12 +6,13 @@ import static com.codeborne.selenide.Condition.visible; import static com.codeborne.selenide.Selenide.$; +import org.assertj.core.api.Assertions; + import com.codeborne.selenide.SelenideElement; import com.codeborne.selenide.WebDriverRunner; +import com.codeborne.selenide.ex.ElementNotFound; -import java.net.URL; - -import io.hawt.tests.features.config.TestConfiguration; +import java.time.Duration; /** * Represents a Login page. @@ -26,11 +27,15 @@ public class LoginPage { * Login to hawtio as given user with given password. */ public void login(String username, String password) { - if (WebDriverRunner.url().contains("login")) { - loginDiv.shouldBe(visible).should(exist); + try { + loginDiv.shouldBe(visible, Duration.ofSeconds(5)).should(exist); loginInput.shouldBe(editable).setValue(username); passwordInput.shouldBe(editable).setValue(password); loginButton.shouldBe(enabled).click(); + } catch (ElementNotFound e) { + Assertions.assertThat(WebDriverRunner.url()) + .withFailMessage(() -> "Failed to login on login page: " + e) + .doesNotContain("login"); } } diff --git a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java index 1c2c9c4350..f135f8dd72 100644 --- a/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java +++ b/tests/hawtio-test-suite/src/main/java/io/hawt/tests/features/setup/WebDriver.java @@ -2,6 +2,8 @@ import org.openqa.selenium.chrome.ChromeDriverService; import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.GeckoDriverService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,10 +31,14 @@ public static void setup() { System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "target/driver.log"); } System.setProperty("hawtio.proxyWhitelist", "localhost, 127.0.0.1"); - // System.setProperty("chromeoptions.args", ); if (Configuration.browser.equals("chrome")) { ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", ImmutableMap.of("credentials_enable_service", false, "profile.password_manager_enabled", false)); + options.addArguments("--proxy-bypass-list=\"<-loopback>\""); + Configuration.browserCapabilities = options; + } else { + FirefoxOptions options = new FirefoxOptions(); + options.addPreference("network.proxy.allow_hijacking_localhost", false); Configuration.browserCapabilities = options; } Configuration.headless = TestConfiguration.browserHeadless();