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.

Trace generator and viewer

Trace generator and viewer

In this lesson, we'll learn how to save a trace of our testing session and view the same later using Playwright's Trace Viewer. To save a trace of our test session, we'll require the context. So when we start our test, we just start the tracing and when we're done with our test, we stop the tracing. A very good case for test hooks. So let's go ahead and create one. So we'll go ahead and import pytest. Create a pytest fixture. And make it auto use. And I'll set the auto use to true. And then we can define our function. Let's say trace our test. will request the browser context using the context fixture and I'll go ahead and input the browser context class and a hint on its type which is this right here now I can go ahead and start the actual tracing that is well go ahead and start or set up the hook then the setup is context dot tracing dot start so it goes ahead and starts the tracing and to this start we can provide a lot of arguments and customize the tracing first of all we can…

Contents