This repo contains examples of how to create page objects and tests using puppeteer and TypeScript. The application under test is tourdedave's "the-internet" project which contains examples of hard to automate pages. The test framework is mocha.
- Node.js version 8 or greater
To run the tests, execute npm install
, npm run build
then npm test
.
./node_modules/.bin/mocha --timeout 10000 --require ts-node/register <spec_file>.ts
./node_modules/.bin/mocha --timeout 10000 --require ts-node/register src/tests/brokenimages.spec.ts
Add eslint, I had to remove tslint to get the tests to pass.s
Still works after all these years! Puppeteer rocks!
$ npm install && npm run build && npm test
up to date, audited 298 packages in 849ms
40 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
> [email protected] build
> rimraf lib && npm run moveJsonFiles && tsc --outDir lib
> [email protected] moveJsonFiles
> copyfiles -u 1 src/selectors/* src/config/* lib
> [email protected] test
> mocha --timeout 999999 --reporter mochawesome lib/index.js
Key presses test
Puppeteer old Headless deprecation warning:
In the near future `headless: true` will default to the new Headless mode
for Chrome instead of the old Headless implementation. For more
information, please see https://developer.chrome.com/articles/new-headless/.
Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
✔ Press F5 key, scrape result (1502ms)
✔ Press a key, scrape result (257ms)
✔ Press 1 key, scrape result (273ms)
✔ Press b key, scrape result (275ms)
✔ Press Alt key, scrape result (268ms)
✔ Press Shift key, scrape result (231ms)
Authentication test:
Puppeteer old Headless deprecation warning:
In the near future `headless: true` will default to the new Headless mode
for Chrome instead of the old Headless implementation. For more
information, please see https://developer.chrome.com/articles/new-headless/.
Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
✔ Login test (768ms)
✔ Validation Message Test (1124ms)
✔ Close Validation Message Test (741ms)
Hover over image test:
Puppeteer old Headless deprecation warning:
In the near future `headless: true` will default to the new Headless mode
for Chrome instead of the old Headless implementation. For more
information, please see https://developer.chrome.com/articles/new-headless/.
Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
✔ Hover over images test, user 0 (1159ms)
✔ Hover over images test, user 1 (624ms)
✔ Hover over images test, user 2 (589ms)
JavaScript alerts test
Puppeteer old Headless deprecation warning:
In the near future `headless: true` will default to the new Headless mode
for Chrome instead of the old Headless implementation. For more
information, please see https://developer.chrome.com/articles/new-headless/.
Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
✔ JavaScript alert test
13 passing (11s)