0

When following the POM design pattern, how modularized/specific should the page class methods be? i.e. if I have a test that involves entering a username and password, is it better practice to:

  1. Create enterUsername() and enterPassword() methods in the appropriate page class and call both from my test method
  2. Create an enterUserData() method instead that sends data to both fields
  3. Create all three methods and call enterUsername() and enterPassword() within enterUserData()
  • 1
    There is no right solution. You can do both ways. Depending on your application specific and how deep you need to test your interaction – Alexey R. Oct 22 '18 at 13:48
1

It depends

If the fields are re-used elsewhere in the application, you might do better with enterUsername() and enterPassword() so you can call them for updating user data, changing user password, or forgot password scenarios.

If they're used only for logging in, you might find it simpler to just have an enterUserData() method.

If you find that you're going to enter username and password in some places, and some variation on username or password, you might be better off using all three with enterUserData() calling enterUsername() and enterPassword().

It completely depends on what will work best with your application and how the fields are handled. What works well when every place you enter a username has a text field with the same ID and every place you enter a password has a password field with the same ID is not going to work the same when the username field is named differently on every page it appears.

As quite a few testers have said many times, there are no "best practices". There are only good practices which are more, or less, applicable to a specific situation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.