Skip to content

Commit f23f0a3

Browse files
Lee EggebrotenJohn Doherty
authored andcommitted
To avoid "order of inclusion" bugs with regard to the web driver, extracted the driver construction to their own files.
1 parent fee0c39 commit f23f0a3

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

runtime/chromeDriver.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
(function(){
3+
var chromedriver = require('chromedriver');
4+
5+
module.exports = function () {
6+
return new selenium.Builder().withCapabilities({
7+
browserName: 'chrome',
8+
javascriptEnabled: true,
9+
acceptSslCerts: true,
10+
chromeOptions: {
11+
args: ['start-maximized']
12+
},
13+
path: chromedriver.path
14+
}).build();
15+
}
16+
})();

runtime/firefoxDriver.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
(function(){
3+
var firefox = require('geckodriver');
4+
5+
module.exports = function () {
6+
return new selenium.Builder().withCapabilities({
7+
browserName: 'firefox',
8+
javascriptEnabled: true,
9+
acceptSslCerts: true,
10+
'webdriver.firefox.bin': firefox.path
11+
}).build();
12+
}
13+
})();

runtime/phantomDriver.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
(function(){
3+
var phantomjs = require('phantomjs-prebuilt');
4+
5+
module.exports = function () {
6+
return new selenium.Builder().withCapabilities({
7+
browserName: 'phantomjs',
8+
javascriptEnabled: true,
9+
acceptSslCerts: true,
10+
'phantomjs.binary.path': phantomjs.path
11+
}).build();
12+
}
13+
})();

runtime/world.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ var requireDir = require('require-dir');
1111
var merge = require('merge');
1212
var chalk = require('chalk');
1313
var selenium = require('selenium-webdriver');
14-
var phantomjs = require('phantomjs-prebuilt');
15-
var chromedriver = require('chromedriver');
16-
var firefox = require('geckodriver');
1714
var expect = require('chai').expect;
1815
var assert = require('chai').assert;
1916
var reporter = require('cucumber-html-reporter');
@@ -28,38 +25,15 @@ function getDriverInstance() {
2825
switch (browserName || '') {
2926

3027
case 'firefox': {
31-
32-
driver = new selenium.Builder().withCapabilities({
33-
browserName: 'firefox',
34-
javascriptEnabled: true,
35-
acceptSslCerts: true,
36-
'webdriver.firefox.bin': firefox.path
37-
}).build();
38-
28+
driver = require("./firefoxDriver")();
3929
} break;
4030

4131
case 'phantomjs': {
42-
43-
driver = new selenium.Builder().withCapabilities({
44-
browserName: 'phantomjs',
45-
javascriptEnabled: true,
46-
acceptSslCerts: true,
47-
'phantomjs.binary.path': phantomjs.path
48-
}).build();
49-
32+
driver = require("./phantomDriver")();
5033
} break;
5134

5235
case 'chrome': {
53-
54-
driver = new selenium.Builder().withCapabilities({
55-
browserName: 'chrome',
56-
javascriptEnabled: true,
57-
acceptSslCerts: true,
58-
chromeOptions: {
59-
args: ['start-maximized']
60-
},
61-
path: chromedriver.path
62-
}).build();
36+
driver = require("./chromeDriver")();
6337
} break;
6438

6539
// try to load from file

0 commit comments

Comments
 (0)