I think there's a bit of ambiguity in the communit...
# best-practices
a
I think there's a bit of ambiguity in the community about what "Page Object" really means. As a holdover from Selenium, when you actually had a class to represent each page and the test had to use a
new MyPageObject
constructor to execute, I very much don't like. However, importing/exporting JSON objects in something like a
myPageTestIds.js
so you can call
myPageTestIds.locator
is great!
g
Do you have an example of this you could share?
a
sure, just off the cuff and in pseduocode, let's say you have an eCommerce site. you want to test your shopping cart. you could create a file called
shoppingCartTestIds.js
that lives, really anywhere your team decides. Inside of it you might have
Copy code
export const shoppingCartIds = {
  checkoutButton: "locator",
  itemsInCartTable: "locator",
  paymentInformation: "locator",
}
then in your
testCart.spec
file you can
import shoppingCartIds from /path/to/shoppingCartTestIds.js
and use
cy.get(shoppingCartIds.checkoutButton).click()
etc
this isn't limited to just locators, either. any repeatable actions like maybe
completeCheckout()
can be a function with several
cy
actions. Of course in that scenario it would make more sense to name the file something like
shoppingCartPage.js
or whatever
g
Awesome. Thanks!
3 Views