I'm using selenium on java to write an automated suite following the page object model.
My suite has to perform several actions with a random user, so I randomly create a user name and password, and then I have to use those credentials to perform other tests. What I'm not sure about would be: do I need to create a "User" object?
The structure of my project has:
- a "POM" package to place page objects, with one class per page in the system under test.
- a "tests" package to place tests, with one class per suite/feature of the system under test.
- a "utils" package to place other needed functionality, like string manipulation.
When it comes to tests, there are two kind of tests that would use a user account:
- Tests dealing with user accounts (where the focus of the test is to be able to register a new user, delete a user account, etc).
- Tests that are about some other functionality, but where the creation of a user is a precondition (e.g.: a user must exist and then I should be able to perform some action as this user).
In both cases I need to create a user with random credentials. In the first case that's pretty much the point of the tests, in the second case that's a precondition to even begin executing the tests.
So I thought of two different approaches:
- should I just add two String (username/password) attributes within any test class (from the "tests" package) that needs to deal with the user, to store randomly created credentials?
- Or would it be a better design decision to create a User class and then instantiate it in a test class? In this last case, should that User class be placed in my "utils" package?
My question is: what of those two approaches holds the best practice? Unless there's another way of doing it that I haven't thought of...