user539820
user539820

Reputation: 33

How to modify or add to default playwright methods (eg Page)?

I recently started using Playwright (coming from Cypress), and one thing I cant figure out is how to modify or add to Page methods.

In Cypress, I can make modify default behaviors of functions such as cy.get(...). Or create new methods such as cy.get(...).clearType(...) which would differ from the regular type method in that it clears the input box before typing.

In Playwright (Typescript), I haven't figured out how to modify any behaviors or add new methods to the Page class.

I want to add new functions such as this.page.clearType(...) which differs from this.page.type(...) in that it clears the input box before typing.

Looking through the Playwright documentation, the only thing that I can see mentions modifying the test fixtures (which I dont think is the same thing?)

Thank you in advance for your help :)

Upvotes: 1

Views: 3409

Answers (1)

Edi Imanto
Edi Imanto

Reputation: 2509

You can check some Puppeteer module related answers of this kind of question.
YES, you can, but NO, you shouldn't do this practice as this is bad habit.
Adding a custom method to puppeteer.Page object

Upvotes: 2

Related Questions