Use playwright instead of puppeteer

This commit is contained in:
Jon Bockhorst
2020-02-10 16:56:37 -06:00
parent 1bb2fc912b
commit 7515ed6146
15 changed files with 562 additions and 380 deletions
@@ -3,26 +3,26 @@
* @license MIT
*/
import * as puppeteer from 'puppeteer';
import * as playwright from 'playwright';
import { assert } from 'chai';
import { ITerminalOptions } from 'xterm';
import WebSocket = require('ws');
const APP = 'http://127.0.0.1:3000/test';
let browser: puppeteer.Browser;
let page: puppeteer.Page;
let browser: playwright.Browser;
let page: playwright.Page;
const width = 800;
const height = 600;
describe('AttachAddon', () => {
before(async function(): Promise<any> {
before(async function (): Promise<any> {
this.timeout(20000);
browser = await puppeteer.launch({
browser = await getBrowserType().launch({
headless: process.argv.indexOf('--headless') !== -1,
args: [`--window-size=${width},${height}`, `--no-sandbox`]
});
page = (await browser.pages())[0];
page = (await browser.defaultContext().pages())[0];
await page.setViewport({ width, height });
});
@@ -30,12 +30,12 @@ describe('AttachAddon', () => {
await browser.close();
});
beforeEach(async function(): Promise<any> {
beforeEach(async function (): Promise<any> {
this.timeout(20000);
await page.goto(APP);
});
it('string', async function(): Promise<any> {
it('string', async function (): Promise<any> {
this.timeout(20000);
await openTerminal({ rendererType: 'dom' });
const port = 8080;
@@ -46,7 +46,7 @@ describe('AttachAddon', () => {
server.close();
});
it('utf8', async function(): Promise<any> {
it('utf8', async function (): Promise<any> {
this.timeout(20000);
await openTerminal({ rendererType: 'dom' });
const port = 8080;
@@ -69,7 +69,7 @@ async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
}
}
async function pollFor(page: puppeteer.Page, fn: string, val: any): Promise<void> {
async function pollFor(page: playwright.Page, fn: string, val: any): Promise<void> {
const result = await page.evaluate(fn);
if (result !== val) {
return new Promise<void>(r => {
@@ -77,3 +77,18 @@ async function pollFor(page: puppeteer.Page, fn: string, val: any): Promise<void
});
}
}
function getBrowserType(): playwright.BrowserType {
// Default to chromium
let browserType: playwright.BrowserType = playwright['chromium'];
const index = process.argv.indexOf('--browser');
if (index !== -1 && process.argv.length > index + 2 && typeof process.argv[index + 1] === 'string') {
const string = process.argv[index + 1];
if (string === 'firefox' || string === 'webkit') {
browserType = playwright[string];
}
}
return browserType;
}