2

I have some code that currently sits in my Steps class (I am using Cucumber BDD).

    DriverExtensions.WaitForEitherElement(BasePage.getDriver(), 
    this.page1.uniqueLocator(),
    this.page2.pleaseTryAgainLocator(), 12000);

I am calling a function that waits for one of two elements to be present, for 12s.

There seem to be some problems with this:

  • I am using the page object model, and according to the general principles of this, the locators I am referencing should be private and therefore only accessible by the page object
  • The steps class is not supposed to be accessing 'low level' concepts like the driver.

However, if I choose one of the page objects and move the wait function to that, within a new method, I will introduce a dependency between one page and another. It seems to violate Single Responsible Responsibility, as each page should only be handling things related to that page.

Is there a design pattern I can apply to resolve this, so I have a good place to put these waitForEitherElements? Ideally, it would allow me to make the driver protected and only accessible by page objects. However, that might mean this is impossible to resolve.

0

1 Answer 1

3

It seems that both pages are open at the same time and you are dealing with them parallelly.

It indicates you should have an object to manage (hide) them, rather than dealing with both separately on the test. A sort of facade, which will allow you to treat this pair of pages as one object.

I don't know how to name it, because you haven't shown your context, but you probably can imagine how the two pages together are called in your domain.

If it doesn't make sense in your domain to gather them together, you can stay as you are, but

The steps class is not supposed to be accessing 'low level' concepts like the driver.

Makes sense, the BasePage.getDriver() is not necessary, nor to expose locators. You can create two lambda expressions, one for each page, and make a pooling loop inside DriverExtensions.

Something like

DriverExtensions.WaitForEitherElement(
    () -> {this.page1.isElementXVisible()},
    () -> {this.page2.isElementYVisible()},
    12000);

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.