Created
March 5, 2019 08:20
-
-
Save johnpaulada/d6fa407de93cf7b7883920508d8eb6c9 to your computer and use it in GitHub Desktop.
Sample Puppeteer Test
This file contains hidden or 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 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