Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ chromedriver.start(args);
chromedriver.stop();

```

With the latest version, you can optionally receive a Promise from the `chromedriver.start` function:

```javascript
var returnPromise = true;
chromedriver
.start(args, returnPromise)
.then(() => {
console.log('chromedriver is ready');
});
```

Note: if your tests are ran asynchronously, chromedriver.stop() will have to be
executed as a callback at the end of your tests

Expand Down
28 changes: 26 additions & 2 deletions lib/chromedriver.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
var path = require('path');
var tcpPortUsed = require('tcp-port-used');
function getPortFromArgs(args) {
var port = 9515;
if (!args){
return port;
}
var portRegexp = /--port=(\d*)/;
var portArg = args.find(function (arg) {
return portRegexp.test(arg);
});
if (portArg){
port = parseInt(portRegexp.exec(portArg)[1]);
}
return port;
};
process.env.PATH = path.join(__dirname, 'chromedriver') + path.delimiter + process.env.PATH;
exports.path = process.platform === 'win32' ? path.join(__dirname, 'chromedriver', 'chromedriver.exe') : path.join(__dirname, 'chromedriver', 'chromedriver');
exports.version = '2.43';
exports.start = function(args) {
exports.start = function(args, returnPromise) {
var cp = require('child_process').spawn(exports.path, args);
cp.stdout.pipe(process.stdout);
cp.stderr.pipe(process.stderr);
exports.defaultInstance = cp;
return cp;
if (!returnPromise) {
return cp;
}
var port = getPortFromArgs(args);
var pollInterval = 100;
var timeout = 10000;
return tcpPortUsed.waitUntilUsed(port, pollInterval, timeout)
.then(function () {
return cp;
});
};
exports.stop = function () {
if (exports.defaultInstance != null){
Expand Down
44 changes: 44 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"extract-zip": "^1.6.7",
"kew": "^0.7.0",
"mkdirp": "^0.5.1",
"request": "^2.87.0"
"request": "^2.87.0",
"tcp-port-used": "^1.0.0"
}
}