Skip to content

Commit

Permalink
Added waits to cater for the time the results take to appear
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 15, 2023
1 parent baeb6ff commit bbdd11d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/test/java/starter/actions/SearchSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import net.serenitybdd.annotations.Step;
import net.serenitybdd.core.steps.UIInteractionSteps;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import starter.pageobjects.SearchForm;

import java.util.List;

public class SearchSteps extends UIInteractionSteps {
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

SearchForm searchForm;
public class SearchSteps extends UIInteractionSteps {

@Step("User searches for '{0}'")
public void searchForTerm(String searchTerm) {
find(SearchForm.SEARCH_FIELD).sendKeys(searchTerm);
find(SearchForm.SEARCH_BUTTON).click();
waitFor(presenceOfElementLocated(SearchForm.ARTICLE_HEADINGS));
}

@Step("Check the search results")
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/starter/stepdefinitions/SearchStepDefinitions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public class SearchStepDefinitions {
@Steps
SearchSteps search;

@Given("{} is researching things on the internet")
public void researchingThings(String actor) {
@Given("^(?:.*) is researching things on the internet")
public void researchingThings() {
navigate.opensTheHomePage();
}

@When("{} looks up {string}")
public void searchesFor(String actor, String term) {
@When("^(?:.*) looks up \"(.*)\"")
public void searchesFor(String term) {
search.searchForTerm(term);
}

@Then("{} should see information about {string}")
public void should_see_information_about(String actor, String term) {
@Then("^(?:.*) should see information about \"(.*)\"")
public void should_see_information_about(String term) {
assertThat(search.getSearchResults()).anyMatch(title -> title.toLowerCase().contains(term));

}
Expand Down

0 comments on commit bbdd11d

Please sign in to comment.