Spike Playwright - Test Execution

1- Playwright Execution using NodeJS API

 

Here's an example of how to can create a Playwright execution microservice using the Node.js API:

https://github.com/asadzakir/playwright-execution-api

Here's how the microservice works:

  1. The microservice uses the Express.js framework to create a web server.

  2. It defines a single endpoint /api/pw/exe that accepts a POST request with a playwright_test_steps property in the request body.

  3. Inside the /api/pw/exe endpoint, the microservice:

    • Launches a new Chromium browser instance using chromium.launch().

    • Creates a new browser context using context.newPage().

    • Executes the provided Playwright script using the eval() function.

    • Closes the browser instance using browser.close().

API Endpoint

http://localhost:5000/api/pw/exe

API Payload

{ "playwright_test_steps": [ "await page.locator('body').click();", "await page.goto('https://sandbox.mabl.com/');", "await page.getByRole('button', { name: 'alert' }).click();", "page.once('dialog', (dialog) => { console.log(`Dialog message: ${dialog.message()}`); dialog.dismiss().catch(() => {}); });", "await page.getByRole('button', { name: 'open alert' }).click();", "await page.getByRole('link', { name: 'mabl' }).click();", "await page.getByRole('button', { name: 'dropdowns' }).click();", "await page.getByLabel('Dropdown select').locator('div').first().click();", "await page.getByLabel('george costanza').click();", "await page.getByRole('link', { name: 'mabl' }).click();" ] }

 

image-20240821-114538.png

2- Playwright Local Execution with in GTP Recorder using the playwright CRX library

here's another way to execute Playwright scripts locally using the Playwright CRX library with in the GTP Recorder:

  1. Install the Playwright CRX library:

    • Run the following command to install the Playwright CRX library:

      npm install @playwright/crx
image-20240821-120411.png

 

Â