BAEL-3906: Fix tests for Serenity (#13228)
This commit is contained in:
parent
a67b82c2e8
commit
30a3a42e4a
@ -2,3 +2,6 @@ jira.url=<jira-url>
|
|||||||
jira.project=<jira-project>
|
jira.project=<jira-project>
|
||||||
jira.username=<jira-username>
|
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
|
@ -1,7 +1,9 @@
|
|||||||
package com.baeldung.serenity;
|
package com.baeldung.serenity;
|
||||||
|
|
||||||
import net.serenitybdd.junit.runners.SerenityRunner;
|
import static org.hamcrest.CoreMatchers.containsString;
|
||||||
import net.thucydides.core.annotations.Managed;
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
@ -9,13 +11,17 @@ import org.openqa.selenium.Keys;
|
|||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
import net.serenitybdd.junit.runners.SerenityRunner;
|
||||||
import static org.junit.Assert.assertThat;
|
import net.thucydides.core.annotations.Managed;
|
||||||
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
|
|
||||||
|
|
||||||
@RunWith(SerenityRunner.class)
|
@RunWith(SerenityRunner.class)
|
||||||
public class GoogleSearchLiveTest {
|
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")
|
@Managed(driver = "chrome")
|
||||||
private WebDriver browser;
|
private WebDriver browser;
|
||||||
|
|
||||||
@ -23,11 +29,14 @@ public class GoogleSearchLiveTest {
|
|||||||
public void whenGoogleBaeldungThenShouldSeeEugen() {
|
public void whenGoogleBaeldungThenShouldSeeEugen() {
|
||||||
browser.get("https://www.google.com/ncr");
|
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);
|
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)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ public class GoogleSearchPageObjectLiveTest {
|
|||||||
public void whenGoogleBaeldungThenShouldSeeEugen() {
|
public void whenGoogleBaeldungThenShouldSeeEugen() {
|
||||||
googleSearch.open();
|
googleSearch.open();
|
||||||
|
|
||||||
|
// If your browser displays cookie settings dialog, uncomment the line below
|
||||||
|
// googleSearch.validateCookies();
|
||||||
|
|
||||||
googleSearch.searchFor("baeldung");
|
googleSearch.searchFor("baeldung");
|
||||||
|
|
||||||
googleSearch.resultMatches("Eugen (Baeldung)");
|
googleSearch.resultMatches("Eugen (Baeldung)");
|
||||||
|
@ -13,12 +13,18 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||||||
@DefaultUrl("https://www.google.com/ncr")
|
@DefaultUrl("https://www.google.com/ncr")
|
||||||
public class GoogleSearchPageObject extends PageObject {
|
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")
|
@FindBy(name = "q")
|
||||||
private WebElement search;
|
private WebElement search;
|
||||||
|
|
||||||
@FindBy(css = "._ksh")
|
@FindBy(css = "._ksh")
|
||||||
private WebElement result;
|
private WebElement result;
|
||||||
|
|
||||||
|
@FindBy(css = "button[id='L2AGLb'] div[role='none']")
|
||||||
|
private WebElement validateCookies;
|
||||||
|
|
||||||
public void searchFor(String keyword) {
|
public void searchFor(String keyword) {
|
||||||
search.sendKeys(keyword, Keys.ENTER);
|
search.sendKeys(keyword, Keys.ENTER);
|
||||||
}
|
}
|
||||||
@ -28,4 +34,7 @@ public class GoogleSearchPageObject extends PageObject {
|
|||||||
assertThat(result.getText(), containsString(expected));
|
assertThat(result.getText(), containsString(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validateCookies() {
|
||||||
|
validateCookies.click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user