From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Page object model usage

Page object model usage

Now that we have defined our page object model, let's go ahead and make use of the same in our test. So I'll go ahead and remove the test hook, the locators from this function right here. Now we can go ahead and start creating the login page object by importing that in our test. So from our models dot login page, we'll import the login page. Then we'll go ahead and create a instance of the same using login page and giving it the page object which is right here. Now we can go ahead and use the login page dot login method. We can give it the username and the password to log in. Next we can go ahead and expect this login page objects that is login page objects label because we have that as a attribute. We can expect the same to have this message. Notice how much cleaner this code is compared to this right here. So we'll go ahead and change all of this code. So I remove the locators, take the login page code, paste it here, it will work just fine. And now I can go ahead and use the label…

Contents