Cerosh Jacob
1 min readJun 16, 2024

--

Hai Navya,

such a great write up with loads of information. If you are open for suggestion given below are few things that i have noticed.

module. exports = LoginPage; i

s not the latest export method in modern JavaScript. While it's a valid approach used in the CommonJS module system, the recommended way to export in modern JavaScript is using the export keyword, which can be exported as default LoginPage.

const LoginPage = require ('./LoginPage');

is not the modern JavaScript syntax for importing modules. This syntax is a common approach with the CommonJS module system, which is still prevalent in Node.js projects but has yet to be the preferred approach for modern JavaScript development. it can be import LoginPage from './LoginPage.js';

page = await browser.newPage();

is a valid approach to creating a Page object in Playwright. Even though it's easy, there are alternative strategies that can enhance code organization and reusability. This approach needs to include encapsulation and reusability. Also, with this approach, you create new Page objects for every test step, potentially impacting performance and memory usage in large test suites. Utilizing a Page Object Model (POM) with the 'use' of Keywords would be a better approach.

test.use(async ({ browser }) => {

const loginPage = new LoginPage(await browser.newPage()); // Create a Page Object instance

return { loginPage }; // Make loginPage available to tests

});

Have a look at this if you are interested in knowing more about what i said.... https://medium.com/p/b4f7066243b7

--

--

No responses yet