Michal
Michal

Reputation: 3276

Selenium Webdriver - Can test data be stored in Page Objects?

We have some test framework created for Selenium in Java and think about test data management for our tests.

We've implemented Page Objects classes, Tasks classes which group Page Object actions in higher level methods, Tests classes(jUnit) extend some BaseTest class.

For now, we don't have test data stored in some separate properties files. I was trying to find any advice if we can/should place test data in the Page Objects but couldn't find the answer. Currently we have test data stored in variables in our tests. We use variables e.g.

private final static String SOME_DATA ="value";

which we can reuse across tests from given TestClass but if we need it in another Test Class we have to repeat it there.

We don't want to place test data in the BaseTest class as it will grow significantly in time.

Upvotes: 3

Views: 2285

Answers (2)

user2062360
user2062360

Reputation: 1543

Test data may be used in page objects but might not be a good coding practice , llike MrTi said the best way should be to use constants. I have been using the Page Object Pattern for a while and I have a whole package called Constants where there are ConstantsUrl , ConstantsConfig, ConstantsCredentials.. However if there is data that needs to change I generally used input files (.txt , .csv) . Hope this helps!

Upvotes: 1

Nathan Merrill
Nathan Merrill

Reputation: 8396

I would recommend a Constants class for data that is spread across all test cases and doesn't change during runtime. I use a Constants class to store all of the URLs, usernames and passwords for test accounts, and various other data that is global.

However, a Constant is NOT a Constant if it changes during runtime, or if it is only applicable to a small set of tests/classes.

Upvotes: 2

Related Questions