Hey guys, if you could help me. So i started automation testing with Cypress, and now i want to continue with Playwright. I am working in Typescript. In Cypress I was using commands, which we can use multiple times. I manage to create something simular in Playwright with functions, and didn't have to use POM.
I want to know is that way is correct? Or should i change my code to use POM?
This thread is trying to answer question "Should I continue using functions in Playwright or switch to using the Page Object Model (POM)?"
I went through the same migration process @Sale . My project is up to about 37k LOC now, and while we don't have any 'formal' POMs, we do group our functions by pages/components. I would encourage looking into the 'screenplay' pattern if you are interested in test framework architecture that scales well. https://serenity-js.org/handbook/design/screenplay-pattern/
Related Ask AI answer for "What is the difference between using functions and the Page Object Model in Playwright?".
Both functions and the Page Object Model (POM) in Playwright offer unique advantages.
Functions like page.waitForFunction()
let you evaluate a function in the context of a page. This is handy when you need to wait for certain conditions on the page to be met before proceeding.
await page.waitForFunction('document.querySelector("body").innerText.includes("Hello World")');
If your test suite is large or complex, using individual functions can become cumbersome. That's where POM comes in. POM allows you to encapsulate common operations on specific pages of your application into reusable objects.
class HomePage {
async navigate() {
await page.goto('https://ray.run');
}
// other methods for interacting with the home page
}
Each part of your web application can be represented by separate POMs. This simplifies authoring and makes maintenance easier by centralizing element selectors in one place.
Whether you should continue using functions or switch to using the Page Object Model depends largely on the complexity of your test suite and personal preference. If you find yourself repeating similar sequences of operations across different tests or struggling with maintaining consistency across tests due to scattered selectors, it might be beneficial for you to switch over to using POMs.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].