Last active
April 12, 2017 06:24
-
-
Save thom-nic/84f529dd0a2f446043dff6fac6256d1c to your computer and use it in GitHub Desktop.
Chromedriver auto-start service for WebdriverIO without Selenium
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 chromedriver = require('chromedriver'); | |
const retry = require('p-retry'); | |
const http = require('axios'); | |
/** | |
* Start chromedriver and waits for it to become available before the tests start. | |
* Call this on wdio.confg `onPrepare`, passing `this` (the wdio config) | |
*/ | |
function start(config) { | |
const pollUrl = `http://${config.host || 'localhost'}:${config.port || 4444}${config.path || '/wd/hub'}/status`; | |
console.log('chromedriver starting on:', pollUrl); | |
const proc = chromedriver.start([`--url-base=${config.path ||'/wd/hub'}`, `--port=${config.port||4444}`]); | |
process.on('exit', () => proc.kill()); // attempt to cleanup this subprocess | |
return retry((() => http.get(pollUrl)), {retries:5, minDelay: 200}); | |
} | |
/** | |
* Call this on wdio.config `after` hook. May not strictly be necessary | |
* because the child process should be killed when this test exits. | |
*/ | |
function stop() { | |
chromedriver.stop(); | |
} | |
module.exports = { | |
start, | |
stop | |
} |
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
exports.config = { | |
// add other options here as normal | |
capabilities: [ | |
{ browserName: 'chrome'}, | |
], | |
// This is the important part!!! | |
onPrepare: () => { | |
if ( this.config.chromeDriver ) require('./chromedriver').start(this.config); | |
}, | |
after: () => { | |
if ( this.config.chromeDriver ) require('./chromedriver').stop(); | |
}, | |
// custom option: | |
chromeDriver: true, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment