Created
October 14, 2020 12:07
-
-
Save etc-tiago/88d37649f22cde02569f6c5231ac2c1f to your computer and use it in GitHub Desktop.
Playwright helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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