samedi 25 mars 2017

Selenium [Java] PageFactory Design : Where do I write my Assertions following Page Object Model

I am following Page Object Model to automate a flow in one application. In one of the module I have to assert Page Title and some more messages. As of now I am putting my Assertion code in the PageFactory itself as follows:

public class EditPost {

    WebDriver driver;

    public EditPost(WebDriver editPostDriver)
    {
        this.driver=editPostDriver;
    }

    @FindBy(how=How.XPATH,using="//*[@id='message']/p")
    WebElement post_published;

    public void assert_message()
    {
        String actual_message_title=post_published.getText();
        Assert.assertEquals(actual_message_title, "Post published. View post");
        System.out.println("Message: Post published, Successfully Verified");
    }
}

I am calling the assert methods from the main file implementing TestNG as follows:

@Test (priority=5)
public void assert_message()
{
    //Created Page Object using Page Factory
    EditPost edit_post = PageFactory.initElements(driver, EditPost.class);
    edit_post.assert_message();

}

Currently, I am running the execution through 3 packages. "Helper" package for the Browser Factory, "Pages" package for the PageFactories and "Testcase" package for the Testcases.

My objective is to reuse the code written for all the different utilities.

My questions are:

  1. As per the concept of PageFactory & Page Object Model is my approach correct? Or do I need to move the Assertions to the "Helper" package? Or should I create a separate library/package for the Assertions?

  2. In the next sprint I may require to do some other activities like Uploading a File, Take Screen Shots of All/Failed Testcases. How do I keep my design structured and organized so I can reuse them in a optimum way?

Aucun commentaire:

Enregistrer un commentaire