Skip to content

Instantly share code, notes, and snippets.

@johnpaulada
Created March 5, 2019 08:20
Show Gist options
  • Select an option

  • Save johnpaulada/d6fa407de93cf7b7883920508d8eb6c9 to your computer and use it in GitHub Desktop.

Select an option

Save johnpaulada/d6fa407de93cf7b7883920508d8eb6c9 to your computer and use it in GitHub Desktop.
Sample Puppeteer Test
const puppeteer = require("puppeteer")
const isDebuggingMode = mode => {
const debuggingMode = {
headless: false,
slowMo: 1000,
devTools: true
}
const isTestModeDebug = mode === "debug"
const config = isTestModeDebug ? debuggingMode : {}
return config
}
const isDebugging = isDebuggingMode(process.env.TEST_MODE)
let browser = null
let page = null
beforeAll(async done => {
browser = await puppeteer.launch(isDebugging)
page = await browser.newPage()
await page.goto("http://localhost:8080")
page.setViewport({
width: 500,
height: 2400
})
return done
}, 10000)
describe("When loading login", () => {
test("h1 loads correctly", async () => {
await page.evaluateHandle(`document.querySelector('shadow').shadowRoot`)
expect(true).toBe(true)
}, 16000)
})
afterAll(() => {
if (isDebugging) browser.close()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment