diff --git a/libraries-testing/serenity.properties b/libraries-testing/serenity.properties index c77df9c0f7..9d8c664e2c 100644 --- a/libraries-testing/serenity.properties +++ b/libraries-testing/serenity.properties @@ -1,4 +1,7 @@ jira.url= jira.project= jira.username= -jira.password= \ No newline at end of file +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 \ No newline at end of file diff --git a/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchLiveTest.java b/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchLiveTest.java index 57bb7c1242..16df26c6b6 100644 --- a/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchLiveTest.java +++ b/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchLiveTest.java @@ -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)")); } } diff --git a/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchPageObjectLiveTest.java b/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchPageObjectLiveTest.java index 47fcdd5403..0a20dcd13a 100644 --- a/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchPageObjectLiveTest.java +++ b/libraries-testing/src/test/java/com/baeldung/serenity/GoogleSearchPageObjectLiveTest.java @@ -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)"); diff --git a/libraries-testing/src/test/java/com/baeldung/serenity/pageobjects/GoogleSearchPageObject.java b/libraries-testing/src/test/java/com/baeldung/serenity/pageobjects/GoogleSearchPageObject.java index d922ea8c85..11e7d08248 100644 --- a/libraries-testing/src/test/java/com/baeldung/serenity/pageobjects/GoogleSearchPageObject.java +++ b/libraries-testing/src/test/java/com/baeldung/serenity/pageobjects/GoogleSearchPageObject.java @@ -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(); + } }