BAEL-3906: Fix tests for Serenity (#13228)

This commit is contained in:
ACHRAF TAITAI 2023-01-07 18:20:57 +01:00 committed by GitHub
parent a67b82c2e8
commit 30a3a42e4a
4 changed files with 32 additions and 8 deletions

View File

@ -1,4 +1,7 @@
jira.url=<jira-url>
jira.project=<jira-project>
jira.username=<jira-username>
jira.password=<jira-password>
jira.password=<jira-password>
# The path must point to the chromedriver location on your workstation
# The chromedriver must be compatible with your browser version
webdriver.chrome.driver=PATH\\chromedriver.exe

View File

@ -1,7 +1,9 @@
package com.baeldung.serenity;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Managed;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
@ -9,13 +11,17 @@ import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Managed;
@RunWith(SerenityRunner.class)
public class GoogleSearchLiveTest {
/* The selectors must be appropriate for your own context.
you can inspect the desired element on the web page you are testing to get the appropriate selector */
private static String SELECTOR_EUGEN_TEXT = ".haz7je";
private static String SELECTOR_VALIDATE_COOKIES_DIALOG = "button[id='L2AGLb'] div[role='none']";
@Managed(driver = "chrome")
private WebDriver browser;
@ -23,11 +29,14 @@ public class GoogleSearchLiveTest {
public void whenGoogleBaeldungThenShouldSeeEugen() {
browser.get("https://www.google.com/ncr");
// If your browser displays cookie settings dialog, uncomment the line below
// browser.findElement(By.cssSelector(SELECTOR_VALIDATE_COOKIES_DIALOG)).click();
browser.findElement(By.name("q")).sendKeys("baeldung", Keys.ENTER);
new WebDriverWait(browser, 5).until(visibilityOfElementLocated(By.cssSelector("._ksh")));
new WebDriverWait(browser, 5).until(visibilityOfElementLocated(By.cssSelector(SELECTOR_EUGEN_TEXT)));
assertThat(browser.findElement(By.cssSelector("._ksh")).getText(), containsString("Eugen (Baeldung)"));
assertThat(browser.findElement(By.cssSelector(SELECTOR_EUGEN_TEXT)).getText(), containsString("Eugen (Baeldung)"));
}
}

View File

@ -19,6 +19,9 @@ public class GoogleSearchPageObjectLiveTest {
public void whenGoogleBaeldungThenShouldSeeEugen() {
googleSearch.open();
// If your browser displays cookie settings dialog, uncomment the line below
// googleSearch.validateCookies();
googleSearch.searchFor("baeldung");
googleSearch.resultMatches("Eugen (Baeldung)");

View File

@ -13,12 +13,18 @@ import static org.hamcrest.MatcherAssert.assertThat;
@DefaultUrl("https://www.google.com/ncr")
public class GoogleSearchPageObject extends PageObject {
/* The selectors "q", "._ksh" and "button[id='L2AGLb'] div[role='none']" must be appropriate for your own context.
you can inspect the desired element on the web page you are testing to get the appropriate selector */
@FindBy(name = "q")
private WebElement search;
@FindBy(css = "._ksh")
private WebElement result;
@FindBy(css = "button[id='L2AGLb'] div[role='none']")
private WebElement validateCookies;
public void searchFor(String keyword) {
search.sendKeys(keyword, Keys.ENTER);
}
@ -28,4 +34,7 @@ public class GoogleSearchPageObject extends PageObject {
assertThat(result.getText(), containsString(expected));
}
public void validateCookies() {
validateCookies.click();
}
}