Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form
playwright Tutorial No. 03

Playwright Tutorial for Beginners 3 – Trace Viewer

Posted on February 20, 2022February 20, 2022 By myustaadg.com No Comments on Playwright Tutorial for Beginners 3 – Trace Viewer
Spread the love

In this tutorial, we will learn about another GUI tool provided by Playwright called the Trace Viewer.

The Playwright Trace Viewer is a GUI tool that helps in exploring recorded Playwright traces after a tests script is executed.

Recording a Trace

We set the trace configuration in the Playwright configuration file,

playwright.config.js.

For instance:

// playwright.config.js

const config = {
    retries: 1,
    use: {
        trace: 'on-first-retry'
    }
};

module.exports = config;

When you run a test with the above configuration, a trace.zip file would be created for each test that was retried.

When you specify the retries key in the config file, Playwright retries the test until the test is passed or the maximum number of retries specified is reached.

Available options for the trace key:

  • off – does not record a trace at all
  • on – records a trace for each test ran
  • retain-on-failure – record trace for each test but removes it when the test runs successfully
  • on-first-retry – record a trace only when retrying a test for the first time

Let’s practice now

  • Let’s configure trace to run on every test in the playwright.config.js file and make use of the Desktop Chrome device:
  // playwright.config.js

  // @ts-check
  const { devices } = require('@playwright/test');

  /** @type {import('@playwright/test').PlayWrightConfig} */
  const config = {
      use: {
          trace: 'on'         // runs on every test
      },
      projects: [
          {
              name: 'chrome',
              use: {...devices['Desktop Chrome']}
          }
      ]
  };
  module.exports = config;
  • Let’s create a test:
  // simple_test.spec.js
  const { test } = require('@playwright/test');

  test.describe('Simple tests',() => {
      test('simple passing test', async ({page}) => {
          await page.goto('https://demoblaze.com')
          await page.locator('text=Phones').click()
      });
  });
  • Running the test with npx playwright test simple_test.spec.js would generate a trace.zip file.
  • You can view the trace by running this command in the CLI. (The trace.zip file is stored in the test-results folder:
  npx playwright show-trace path/to/trace.zip
  • Doing this would open the Trace Viewer window now you can see the actions performed by the script.
trace-viewer
  • The trace-viewer shows the action on the script on the left side of the window and clicking each of the actions reveals:
    • action snapshot
    • action log
    • source code location
    • network log for the action
  • For instance, clicking on the locator.click text=Phones:
trace-viewer

The trace viewer is a really useful tool when you want to trace how some of your tests ran (flaky or failing).

Playwright Tutorials Tags:Everything about the Playwright framework, Getting started | Playwright, Getting started with Playwright, How do I run a playwright test in applitools?, How do I use playwright with Node JS?, how to install playwright, playwright automation tool, playwright documentation, playwright example, playwright python tutorial, playwright test, playwright test framework, playwright tutorial, Playwright tutorial example

Post navigation

Previous Post: Playwright Tutorial for Beginners 2 – Code Generator
Next Post: Playwright Tutorial for Beginners 4 – Selectors and Locators

More Related Articles

playwright Tutorial No. 05 Playwright Tutorial for Beginners 5 – Performing Actions Playwright Tutorials
playwright Tutorial No. 09 Playwright Tutorial for Beginners 9 – Assertions Playwright Tutorials
playwright Tutorial No. 07 Playwright Tutorial For Beginners 7 – Videos Playwright Tutorials
playwright Tutorial No. 04 Playwright Tutorial for Beginners 4 – Selectors and Locators Playwright Tutorials
playwright Tutorial No. 06 Playwright Tutorial for Beginners 6 – Demo 1 Playwright Tutorials
playwright Tutorial No. 02 Playwright Tutorial for Beginners 2 – Code Generator Playwright Tutorials

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme