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.

Test hook

Test hook

In this lesson, we'll learn about the test hooks which we can add to any other fixture. Let's say we like to perform some things before and after each page object gets used by a test function. For that, let's go ahead and create two test functions. so the first is like test page has let's say docs link and we will change this to docs and to ensure that our link is visible we can simply use assert the link is visible like this so it will return true if it's visible false if it's not now on to the second function we have the get started link and instead we can say something like test get started visits the docs so again we just get the link click on the same and make sure it goes to the docs url so these are our two functions and here you can see we duplicate two things that is visiting the playwright website. Now you can extract it as its own fixture and provide as a playwright page. So let's go ahead and create the same. We will import pytest and then we'll go ahead and use the pytest…

Contents