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..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 @@ -1,15 +1,18 @@ 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; +import io.hawt.tests.features.utils.ByUtils; public class ConnectPage extends HawtioPage { @@ -24,12 +27,11 @@ 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) { + //Don't try to create the same connection twice + if ($(ByUtils.byAttribute("rowid", "connection " + name)).exists()) { + return; + } - 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(); $(CONNECTION_FORM).$(By.id("connection-form-name")).setValue(name); @@ -46,8 +48,6 @@ public void addConnection(String name, URL connection) { } $(MODAL).$(FOOTER_BUTTON).click(); - - } } public void connectTo(String name) { @@ -56,14 +56,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(); } } 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 dfa56737cc..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 @@ -1,15 +1,16 @@ 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.FirefoxOptions; +import org.openqa.selenium.firefox.FirefoxProfile; 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 +31,25 @@ public static void setup() { System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "target/driver.log"); } System.setProperty("hawtio.proxyWhitelist", "localhost, 127.0.0.1"); + 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(); 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 +58,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()); + }); } /**