mazzaccaro
mazzaccaro

Reputation: 1

Creating PageObjects in WebDriverIO

I've been creating PageObjects for WebDriverIO and have been following the ES6 method for Page Object pattern in the WebDriverIO documentation.

However, someone on my team suggested simply making objects of selectors, and then calling those strings in the tests. Is there a good reason why the Page Object pattern returns elements and not string of the selectors?

Upvotes: 0

Views: 708

Answers (2)

Orane Findley
Orane Findley

Reputation: 94

Page Object returns elements instead of just the selector string to allow actions to be called directly on the elements e.g.

PageObject.Element.waitForDisplayed()

Instead of you doing

Browser.waitForDisplayed(PageObject.Element)

Which may get lengthy and doesn't chain as well. You can find more actions that can be performed on elements here

However, you can also get the string of the selector if you want by doing

PageObject.Element.selector()

Chaining e.g.

PageObject.Element.waitForDisplayed().click()

Upvotes: 1

Kevin Lamping
Kevin Lamping

Reputation: 2269

I think the point is allow you to use the objects directly. So:

MyPageObject.MyElement.click()

versus:

browser.click(MyPageObject.MyElement)

Just a little less verbose

Upvotes: 0

Related Questions