7. Integration with Microsoft Playwright

< All Topics

As Imagium can be integrated with any automation tool on the planet. Microsoft Playwright is a no exception.

There are various ways to make API calls in Node.js. We are using Axios library in this example(However you can use your preferred library if you have one). Axios is promise based HTTP client for the browser and node.js

npm i axios

The below code use Playwright to convert screenshot into Base64 image then send Post request using Axios

const { chromium } = require("playwright");
const axios = require('axios');

var testNameImagium = "Playwright Integration";
var projectKeyImagium = '7991bf3d-060d-481d-9da4-4b885373f58b';
var uidEndPointImagium = '';
var validateEndPointImagium = '';
var testUID;

    //Get unique test ID from Imagium project
 await  axios.post(uidEndPointImagium, {TestName: testNameImagium, ProjectKey: projectKeyImagium })
    .then((res) => {
        console.log(`Status: ${res.status}`);   
        //Store unique test ID
        testUID = res.data;
        console.log('Body: ', res.data);
    }).catch((err) => {
const browser = await chromium.launch({headless:false});
const page = await browser.newPage();
await page.goto("http://google.com");
const buffer = await page.screenshot({ path: 'screenshot.png', fullPage: true });

//Validate the page screenshot inside Imagium
await  axios.post(validateEndPointImagium, {StepName: 'Step 1', TestRunID: testUID, ImageBase64:  buffer.toString('base64')})
.then((res) => {
    console.log(`Status: ${res.status}`);
    console.log('Body: ', res.data);
}).catch((err) => {

await browser.close();


Previous 6. Automatic Test Creation (Web Crawlers)
Next 8. Integration with Cypress.io
Table of Contents