PlaywrightJS Tutorial

PlaywrightJS Tutorial

  • Docs

›Cookbook

Setup

  • PlaywrightJS Installation
  • Install Mocha and Chai
  • Installation Test

First Steps

  • Create a PlaywrightJS Test
  • Using Mocha and Chai

The Playwright Library

  • The Browser Object
  • The Context Object
  • The Page Object
  • Selectors
  • Navigation
  • Interactions
  • Auditing

Using PlayWright on web pages

  • A real world case

Code Generation

  • Code Generation

Cookbook

  • Timers
  • Using SQL
  • Database Connection
  • Email Setup

Timers

Timers

Mocha test have a built-in benchmarking tool for each unit tested. When Mocha is not used or a specific test is needed, the process.hrtime() can be used.

process.hrtime() is called each time a timer needs to be started and stopped. When the time between two events is required, the starting value is passed as a parameter.

const pw = require('playwright');
const assert = require('assert');

(async () => {
    const browser = await pw.chromium.launch();
    const context = await browser.newContext();
    const page = await context.newPage();
    let start = process.hrtime();
    await page.goto('http://leafground.com/');

    let title = await page.title();
    try {
        await assert.strictEqual(title, 'TestLeaf - Selenium Playground', 'Title match!');
    }
    catch (e) {
        console.log(e);
    }
    let end = process.hrtime(start); // time between start and here 
    let start2 = process.hrtime();
    await page.close();
    await context.close();
    await browser.close();
    let end2 = process.hrtime(start2); // time between start2 and here
    console.log('Time 1: ' + end); 
    console.log('Time 2: ' + end2);
})();
← Code GenerationUsing SQL →
  • Timers