I’m working on restructuring some deadline driven code, which basically means I’m largely rebuilding it from the ground up. One of the problems is that the QA automation tests are very fragile because every element is found by raw xpaths that rely on the page structure (divs, trs, no id’s are class names).
As such, I’m working on implementing a proper page object model. I understand that I want to use instance variables for the page objects so that my tests can be multi-threaded. The usage of instance variables leads me to wonder, how should I go about creating new page object instances? Like for instance, if I navigate from the landing page to the user profile page, what entity should be responsible for constructing the profile page object model instance?
In the example above, I’m leaning towards having the landing page have a method that triggers a transition to the user profile page and returns a new page object (as opposed to having each page instantiate their own page object). To mean this ensures that one session has a consistent driver passed about and reduces complications in the actual test, but was unsure if this would be “correct” within the page object model framework, or maybe if there’s even a third better way to handle this.
Source: Read More