From the course: Playwright: Design Patterns

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Creating reusable and maintainable page object models

Creating reusable and maintainable page object models - Microsoft Playwright Tutorial

From the course: Playwright: Design Patterns

Creating reusable and maintainable page object models

- [Instructor] We have already seen how to interact with the login form using our login page class. Now, let's take it a step further by making our page object model more reusable and maintainable. We'll introduce a method that handles the login process, helping us avoid repeating code across multiple tasks and keeping our test suite clean and scalable. So as you can see, we have got these lines from line number 15 to line number 18, which may be reusable for other tests where we need to do the same login process and then verify some details. So what I'm going to do is I'm going to move that into the page object model. So let's cut the lines from here and go into our page object model and create a new function, called async login, which will take two parameters, email, which is a string and password, which is also a string. Because we are already inside the page object model, we don't need an object to access it. So I will change this to this. And because we are passing two…

Contents