Selenium Page Object Model

I am rewriting a Selenium project I have previously written in Java. I am really a beginner, but I am upgrading it and am using Maven as well as using the Page Object Model for my project.

I have created two packages as src/main/java/tests and src/main/java/pages. Is it standard practice to initialise the WebDriver within the src/main/java/tests package or should you place it src/main/java or even entirely separately? The code for Initializing the WebDriver and passing the users data to login uses a series of arrays and is therefore rather large so it would probably not have an associated Page with the Pages package. Are there any naming conventions for this initializing/base Java file or where it should be stored?



Hi welcome to the ministry of test community.
I’m not a Java person, but things like where you choose to put files really has more to do with how your test-runner engine (Maven) works and how your CI/CD script deploys and starts the tests together with how your reporting is generated. Let it evolve over time, code is easier to move about later than you think. Getting your code modular enough to maintain is a bigger challenge. You will want to split out and boil down all problems into small self-testable parts. For starters I would completely separate the webdriver initialization from the Login code, the implementations of these have absolutely nothing to do with each other, and should not even be in the same file. You will want to start creating fixtures, setup code and teardown code and adding tracing and logging. Setting the browser up is NOT part of your test, you are not testing the webdriver, so don’t create any coupling between concerns if you can. Product test code in separate folder to logging and fixture code. This kind of structure cleanup will only emerge over time though. I call it emergent design. And make sure that you give yourself enough breathing room in every work unit to do some tidy up later.

Making time to clean up is always hard, but I always prefer working tests over perfectly organised. Once a handful of stuff delivers you some value, a pattern will emerge and you will be able to delete the things that you feel are not helping and reshuffle.