Question

I'm in the process of developing an automation framework using Selenium Webdriver following the PageObject pattern where there are 2 layers:

  • Test classes (Test specification)
  • PageObject classes (Test implementation)

My test classes contain TestNG annotation methods (@Test, @BeforeTest, @AfterTest etc) where I'm creating objects of the PageObject classes and calling the methods in those classes, which will actually interact with the AUT.

The way I'm passing data to the tests is by including:

  • All the locators (css/xpath/class/id locators) of elements in the application.
  • All the test-data needed

in a properties file (For ex: testDataSet1.properties). I'm creating a HashMap<String, String> of the properties file and passing it as a parameter to all the pageobjects which will read the data from the hashmap and use them in the script. I'm not passing test data at all from the test classes.

What my problem is, I am not sure whether it is appropriate to read test-data in PageObjects. I get a feeling that this approach is very inflexible because I am tying test data to PageObjects instead of tying it to the tests. So when I need to perform data-driven tests / run the automation suite in multiple iterations, this will not work. Because, currently if I need to use different data each time I need to manually go and change the key specified in the hashmap which will fetch me a different value from the properties file.

Any suggestions?

Was it helpful?

Solution

I personally like having the page object act as a the web page itself, providing me actions to perform and validation methods to use. For example, I keep all of my CSS, ID, etc. selectors within the page object itself. This way, if there is ever an update to the webpage which breaks the tests, I simply go to the corresponding Page Object for that web page and update the selector there.

As far as test data, I have some other files (classes, properties, etc.) that I use to pull test data from eg. test users. The test classes themselves pull this test data and pass it into the Page Objects (when needed), or the Page Object methods for validation purposes.

An example of a test data class (mine is a bit more complex, but this is a simple example):

public TestUser(){
    username = getUniqueUser();
    password = ""; 
    name = "Test User";
    email = getUniqueEmail(username);
}

tl;dr;

  • I keep the html selectors IN their respective Page Objects (can use sub-page objects for re-use if needed).
  • I keep the test data mixed between classes, property files, and test classes.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top