Assertions

Assertions are the core of test automation, and there has been a good long debate on where assertions belong. Broadly, there are two types of approaches for handling assertions, and they can be implemented in either of the following:

  • Page Object
  • Test script

The first approach says that Page Objects should contain assertions. The advantage of this approach is to minimize the duplication of assertions in the test suite. Also, it helps in organizing the messages and following the Tell, Don't Ask principle (for more information visit: https://martinfowler.com/bliki/TellDontAsk.html). The Tell, Don't Ask principle recommends that an object can be issued a command to perform some operation or logic, rather than to query its state. It suggests that we should tell the object what to do, rather than asking the object for data and then acting on it.

Let's apply the same in our code. Here's what we have automated:

@Then("^I should see the first car search result with "([^"]*)"$")
public void iShouldSeeTheFirstCarSearchResultWith(String arg0) throws Throwable {
List<WebElement> elements = appiumDriver.findElements(By.id("cars_ad_list_title_tv"));
Assert.assertTrue(elements.get(0).getText().startsWith(arg0));
}
..................Content has been hidden....................

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