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:
The microservice uses the Express.js framework to create a web server.
It defines a single endpoint
/api/pw/exe
that accepts a POST request with aplaywright_test_steps
property in the request body.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
...
Code Block |
---|
{ "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();" ] } |
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:
Install the Playwright CRX library:
Run the following command to install the Playwright CRX library:
Code Block npm install @playwright/crx
...