Graphene Abstractions - Best Practice for Assertions

128 Views Asked by At

I started writing my tests using the Page Abstractions provided by Graphene (Page Objects and Page Fragments). I am trying to decide on what is the best practice for writing assertions. Specifically I am trying to decide where the assertions should be located. Should it be on the Page Fragment, on the Page Object or on the Test class? I am used on having all assertions on my Test classes but that is the "old" way.

For example, asserting if an element has a css class could be done in the following ways:

// not working code just  an example  
@Test  
public void simpleTest(){  
     assertTrue (pageObject.getElementA.isDisplayed());  
}  

or

@Test   
public void simpleTest(){  
     pageObject.isElementADisplayed();  
}  

where pageObject is a Page Object as defined by Graphene:

public class PageObject {  
     WebElement elementA;  
     public void isElementADisplayed(){  
          assertTrue(elementA.isDisplayed());  
     }  
}  

Also the page could as easily define a Page Fragment which in turn could have the assertion. Is there an obvious best practice for this?

Thank you in advance.

1

There are 1 best solutions below

0
On

I always got an IllegalStateException when AssertionErrors are thrown in PageFrragments.

I would say that assertions should be located in the test, while page and page fragments are providing the information you need.