Implementing assertions in Page Object

The first step is to replace the implementation with the following page class and the method that will perform the verification of the search results on the car search results page. So, we can declare something like this:

@Then("^I should see the first car search result with "([^"]*)"$")
public void iShouldSeeTheFirstCarSearchResultWith(String arg0) throws Throwable {
new CarResultsPage(appiumDriver).verifySearchResult(searchInput);
}

The next step is to implement the CarResultsPage class and the verifySearchResult(String searchInput) method. So, this method will take care of the verification of the result. This is the implementation of the CarResultsPage class:

package pages;

import io.appium.java_client.AppiumDriver;
import org.junit.Assert;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

public class CarResultsPage extends BasePage {
AppiumDriver appiumDriver;

@FindBy(id = "category")
private WebElement categoryChooser;

@FindBy(id = "inspected_checkbox")
private WebElement inspectedToggle;

@FindBy(xpath = "//android.widget.TextView[@text='SORT']")
private WebElement sortLink;

@FindBy(xpath = "//android.widget.TextView[@text='FILTER']")
private WebElement filterLink;

@FindBy(id = "cars_ad_list_title_tv")
private List<WebElement> searchResultText;

public CarResultsPage(AppiumDriver appiumDriver) throws Exception {
super(appiumDriver);
this.appiumDriver = appiumDriver;
PageFactory.initElements(appiumDriver, this);
}

public void verifySearchResult(String text) {
for (WebElement result : searchResultText) {
Assert.assertTrue(result.getText().contains(text));
}
}

}

we can add other assertions and remove the assertion from the step class. Let's look at the other approach of implementing assertions in the test script.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.30.62