Chrome DevTools Protocol Driver
See Chrome DevTools Protocol Viewer for all the awesome things you can do with your browser.
Installation
npm install --save @automationcloud/cdp
Usage
Launch Chrome/Chromium browser
import { ChromeLauncher } from '@automationcloud/cdp';
export const launcher = new ChromeLauncher({
chromePort: 9123,
chromePath: '/Applications/Chromium 72.app/Contents/MacOS/Chromium',
userDataDir: '.tmp/chromedata',
additionalArgs: [
'--site-per-process',
],
});
await launcher.launch();
await launcher.shutdown();
launcher.stop();
Connect to browser via CDP
import { Browser } from '@automationcloud/cdp';
const browser = new Browser({
chromePort: 9123,
});
await browser.connect();
const tab = await browser.newTab();
await tab.navigate('https://github.com');
const h1 = await tab.querySelector('h1');
const { text } = await h1.getInfo();
Running tests
- Copy
.env.example
to .env
. - Specify environment variables (notably, the path to Chromium browser)
- Note: you should not use your regular browser for testing, install a separate one which you don't normally use.
- Note: make sure you don't have test browser running before running the tests.
- Run
npm run dev
in separate terminal for incremental TypeScript compilation (in case you want to iterate on the tests or source code). - Run
npm test
.