generated from serenity-bdd/serenity-junit-starter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
75 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 22 additions & 19 deletions
41
src/test/java/starter/acceptancetests/WhenSearchingForTerms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
package starter.acceptancetests; | ||
|
||
import net.serenitybdd.annotations.Steps; | ||
import net.serenitybdd.junit5.SerenityJUnit5Extension; | ||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.annotations.CastMember; | ||
import net.serenitybdd.screenplay.ensure.Ensure; | ||
import net.serenitybdd.screenplay.questions.page.TheWebPage; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import starter.actions.navigation.NavigateTo; | ||
import starter.actions.search.LookForInformation; | ||
import starter.actions.NavigateSteps; | ||
import starter.actions.SearchSteps; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(SerenityJUnit5Extension.class) | ||
class WhenSearchingForTerms { | ||
|
||
@CastMember | ||
Actor actor; | ||
@Steps | ||
NavigateSteps navigate; | ||
|
||
@Steps | ||
SearchSteps search; | ||
|
||
@Test | ||
@DisplayName("Should be able to search for red things") | ||
void searchForRedThings() { | ||
actor.attemptsTo( | ||
NavigateTo.theSearchHomePage(), | ||
LookForInformation.about("red"), | ||
Ensure.that(TheWebPage.title()).containsIgnoringCase("red") | ||
); | ||
navigate.opensTheHomePage(); | ||
|
||
search.searchForTerm("red"); | ||
|
||
assertThat(search.getSearchResults()).anyMatch(title -> title.toLowerCase().contains("red")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should be able to search for green things") | ||
@DisplayName("Result page title should mention the search term") | ||
void searchForGreenThings() { | ||
actor.attemptsTo( | ||
NavigateTo.theSearchHomePage(), | ||
LookForInformation.about("green"), | ||
Ensure.that(TheWebPage.title()).containsIgnoringCase("green") | ||
); | ||
navigate.opensTheHomePage(); | ||
|
||
search.searchForTerm("green"); | ||
|
||
assertThat(search.getTitle()).containsIgnoringCase("green"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package starter.actions; | ||
|
||
import net.serenitybdd.annotations.Step; | ||
import net.serenitybdd.core.steps.UIInteractionSteps; | ||
import starter.pageobjects.SearchForm; | ||
|
||
public class NavigateSteps extends UIInteractionSteps { | ||
|
||
SearchForm searchForm; | ||
|
||
@Step("User opens the DuckDuckGo home page") | ||
public void opensTheHomePage() { | ||
searchForm.open(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package starter.actions; | ||
|
||
import net.serenitybdd.annotations.Step; | ||
import net.serenitybdd.annotations.Steps; | ||
import net.serenitybdd.core.steps.UIInteractionSteps; | ||
import org.openqa.selenium.Keys; | ||
import starter.pageobjects.SearchForm; | ||
|
||
import java.util.List; | ||
|
||
public class SearchSteps extends UIInteractionSteps { | ||
|
||
SearchForm searchForm; | ||
|
||
@Step("User searches for '{0}'") | ||
public void searchForTerm(String searchTerm) { | ||
find(SearchForm.SEARCH_FIELD).sendKeys(searchTerm); | ||
find(SearchForm.SEARCH_BUTTON).click(); | ||
} | ||
|
||
@Step("Check the search results") | ||
public List<String> getSearchResults() { | ||
return findAll(SearchForm.ARTICLE_HEADINGS).texts(); | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
src/test/java/starter/actions/navigation/DuckDuckGoHomePage.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/test/java/starter/actions/search/LookForInformation.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package starter.pageobjects; | ||
|
||
import net.serenitybdd.annotations.DefaultUrl; | ||
import net.serenitybdd.core.pages.PageObject; | ||
import org.openqa.selenium.By; | ||
|
||
@DefaultUrl("https://duckduckgo.com/") | ||
public class SearchForm extends PageObject { | ||
public static final By SEARCH_FIELD = By.name("q"); | ||
public static final By SEARCH_BUTTON = By.cssSelector("[aria-label='Search']"); | ||
public static final By ARTICLE_HEADINGS = By.cssSelector("[data-testid=result] h2"); | ||
} |