Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API. Macaca Playwright is a long-term maintained browser driver as a candidate for Macaca Playwright driver.
xudafeng |
snapre |
Jodeee |
ilimei |
yihuineng |
---|
This project follows the git-contributor spec, auto updated at Fri Aug 19 2022 14:33:15 GMT+0800
.
$ npm i macaca-playwright --save-dev
const fs = require('fs');
const path = require('path');
const Playwright = require('macaca-playwright');
const playwright = new Playwright();
async function() {
/**
default options
{
headless: false,
x: 0,
y: 0,
width: 800,
height: 600,
userAgent: 'userAgent string'
}
*/
await playwright.startDevice({
headless: true // in silence
});
await playwright.maximize();
await playwright.setWindowSize(null, 500, 500);
await playwright.get('https://www.baidu.com');
const imgData = await playwright.getScreenshot();
const img = new Buffer(imgData, 'base64');
const p = path.join(__dirname, '..', 'screenshot.png')
fs.writeFileSync(p, img.toString('binary'), 'binary');
console.log(`screenshot: ${p}`);
await playwright.stopDevice();
};