Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix e2e errors #3316

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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);
Expand All @@ -46,8 +48,6 @@ public void addConnection(String name, URL connection) {
}

$(MODAL).$(FOOTER_BUTTON).click();

}
}

public void connectTo(String name) {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
Expand All @@ -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());
});
}

/**
Expand Down