I wish people would stop using POM, it’s a maven Project Object Model. I’m guessing you mean you want to use a Page Object model.
I would suggest looking at using Fluent API’s with page objects. You can effectively create your own DSL (Domain Specific Language) for your tests and make them nice and easy for other people to read. You will then be able to chain the methods in your page objects so that they look something like this:
PageObject page = new PageObject(); page.setCustomerName("Jim").setGender(MALE).submitForm()
In the example above I’m assuming that MALE is part of an ENUM. You can then stick a simple case statement in your setGender() method that works out which radio button to select.
Remember that page objects are badly named and don’t have to be a definition of a complete page, they are just a useful abstraction for a group of related things. You can have a page object model that pulls in multiple different page object models to build a codified view of your page that’s not too big or complex.
Its fine for a method in a page object to return a new instance of another page object, but think about the possible places it could go. For example if you are automating a login form you probably have a few locations that are viable:
- Successfully login
- Change password screen
- Failed login
In this case having the command that clicks the login button returning a specific page object is probably a bad idea, you would probably want to have login return an instance of itself and add some helper methods that return the relevant page object based upon what your check is expecting e.g.
loginPage.username("Jim").password("Password123").submit().successfulLogin()
loginPage.username("Jim").password("Password123").submit().failedLogin()
DO NOT make everything static, it’s a massive anti-pattern. Remember test code is as important as production code, spend time making it as good as you can.