0
votes

I am using Testng with Selenium with PageObject Model. In a java file, I have multiple @Test Methods -

    @Test( groups={"regression"},description="used to navigate", priority=206)
public void navigateToRegister() {
    loginFrameMethods = PageFactory.initElements(driver, LoginFrameObjects.class);
    loginFrameMethods.clickAccountButton();
    loginFrameMethods.verifyTextPresence();// Asserts are done here
    loginFrameMethods.fillSignUpPhoneNumber("1234567890");
    loginFrameMethods.clickSignupContinueButton();
    loginFrameMethods.verifyResult(); // Asserts are done here
} 
@Test(){
//Other Validations
// Asserts May be done here also at the @Test Level
}

Now I wonder what is good practice- to write Assertions in PageFactory Class( in this case LoginFrameMethods) as these methods can be reused in other test flows also or at the individual TestLevel.

If the answer is former, then how to Use SoftAssert as it will require all the PageFactory Classes to have access to same SoftAssert Object to call assertAll() Method.

1
I wouldn't write my assertions in the page factory. Assertions should be in your test classes. And be careful re-using. If something changes on page 1 (and not on page 2 etc.) you will have to check all other pages, and in due time create a mess... - user745733

1 Answers

0
votes

The ideal implementation of page object does not suggest to have assertions in page class. You should customize the orientation of classes. I'd like to have a separate package for all the verification methods for a particular view/page class. I am not sure about your framework structure but if situation demands me to do something similar to your case, I'd prefer to do something as below:

org.xyz.example.views
    ----LoginFramePage.java
org.xyz.example
    ----VerifyLoginFramePage.java

Above package structure try to suggest, let's have two packages for each view one package will contain page methods like login, logout and second class (Verify*.java) will contains all the assertion methods for that particular view.