-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebdriver.js
More file actions
71 lines (63 loc) · 1.83 KB
/
webdriver.js
File metadata and controls
71 lines (63 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var DEBUG = false;
var VERBOSE = false;
var started = false;
var startSeleniumServer = function(done) {
var selenium = require('selenium-standalone');
var server = selenium({ stdio: 'pipe' },
[DEBUG ? "-debug" : ""]
);
server.stdout.setEncoding("utf8");
server.stdout.on('data', function(output) {
if (VERBOSE) console.log(output);
if (!started) {
started = true;
done();
}
});
};
var startWebDriver = function(done) {
var desiredCapabilities = {
browserName: process.env.BROWSER || 'phantomjs',
};
if (desiredCapabilities.browserName === "phantomjs") {
if (/^win/.test(process.platform)) {
// Selenium 2.42.0 bug:
// Selenium tries to execute phantomjs instead of phantomjs.cmd on Windows
desiredCapabilities["phantomjs.binary.path"] = __dirname + "/../node_modules/.bin/phantomjs.cmd";
}
}
var client = require('webdriverjs').remote({
desiredCapabilities: desiredCapabilities,
logLevel: (DEBUG ? "debug" : "")
});
startSeleniumServer(done);
if (desiredCapabilities.browserName === "phantomjs") {
// PhantomJs 1.9.7-8 bug:
// end doesn't call back
client.oldEnd = client.end;
client.end = function(done) {
this.oldEnd();
setTimeout(done, 200);
};
}
return client;
}
var startAppServer = function(done) {
if (process.env.URL) {
return done(process.env.URL);
}
var app = require('../app');
var server = app.listen(0, function() {
var port = server.address().port;
done("http://localhost:" + port + "/");
});
};
module.exports = function(done) {
var client = startWebDriver(function() {
startAppServer(function(url) {
console.log("Running tests with " + url);
client.init().url(url, done);
});
});
return client;
};