2

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...

Floella
  • 1,279
  • 1
  • 22
  • 41
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the [How to Ask](https://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – undetected Selenium Feb 15 '18 at 03:58
  • Hmm... I believe I'm asking just one question: what of the two approaches I listed at the end would be the best practice (unless there's a third one I haven't thought of). I edited to make it clear that this is the question. – Floella Feb 15 '18 at 11:16

0 Answers0