Skip to content

Instantly share code, notes, and snippets.

@etc-tiago
Created October 14, 2020 12:07
Show Gist options
  • Save etc-tiago/88d37649f22cde02569f6c5231ac2c1f to your computer and use it in GitHub Desktop.
Save etc-tiago/88d37649f22cde02569f6c5231ac2c1f to your computer and use it in GitHub Desktop.
Playwright helper
const browserOpen = async (browser, url, headless = true) => {
const browserRef = await chromium.launch({ headless: false });
page = await browserRef.newPage();
await page.goto(url);
const element = async (selector) => await page.$(selector);
const click = async (selector) => await page.click(selector);
const inputFill = async (selector) => await page.click(selector);
const waitTimeout = async (milliseconds) => await page.waitForTimeout(milliseconds);
const countElement = async (selector) => await page.$$eval(selector, (el) => el.length);
const waitFor = async (selector) => await page.waitForSelector(selector);
const closeBrowser = async () => await browser.close();
return {
actions: { element, click, inputFill, waitTimeout, countElement, waitFor },
closeBrowser,
browser: browserRef,
page,
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment