Skip to content

Commit 65e6aba

Browse files
committed
switching to dj-selenium to temp handle selenium bug SeleniumHQ/selenium#378 and some code cleanup
1 parent e0d7c9c commit 65e6aba

5 files changed

Lines changed: 44 additions & 50 deletions

File tree

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"unused": false,
77
"indent": 2,
88
"maxcomplexity": 3,
9-
"maxparams": 4,
9+
"maxparams": 3,
1010
"maxdepth": 2
1111
}

lib/fiveby.js

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* global promise, run */
2-
var webdriver = require('selenium-webdriver');
2+
var webdriver = require('dj-webdriver');
33
var Hook = require('mocha').Hook;
44
var tb = require('traceback');
55
var LogManager = require('./logManager');
@@ -38,7 +38,7 @@ fiveby.prototype.localServer = function () {
3838

3939
fiveby.prototype.runSeleniumServer = function () {
4040
console.info('spinning up local server ...');
41-
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
41+
var SeleniumServer = require('dj-webdriver/remote').SeleniumServer;
4242
var server = new SeleniumServer(Helper.getLocation(), { port: 4444 });
4343
server.start();
4444
global.fivebyConfig.hubUrl = this.config.hubUrl = server.address();
@@ -91,27 +91,24 @@ fiveby.prototype.runSuiteInBrowsers = function (test) {
9191
}
9292
self.logManager.setAdditionalLogOptions(capabilities);
9393

94-
//setup post driver step
95-
var promo = function () {
96-
var describe = test(driver);
94+
//build driver
95+
var driver = new webdriver.Builder()
96+
.usingServer(self.config.hubUrl)
97+
.withCapabilities(capabilities)
98+
.build();
99+
driver.name = elem;
100+
driver.manage().timeouts().implicitlyWait(self.config.implicitWait);
97101

98-
//register hooks with mocha
99-
self.registerHook('fiveby error handling', describe, 'beforeEach', function () {
100-
this.currentTest.parent.file = this.currentTest.file = file; //correct file name bug with async execution and mocha
101-
webdriver.promise.controlFlow().on('uncaughtException', function (e) { //map errors to test when appropriate
102-
if (this.currentTest) {
103-
this.currentTest.callback(e);
104-
} else {
105-
console.error('Failed in setup or teardown, test result may not be valid for this file'); //failed in non-test
106-
throw(e);
107-
}
108-
});
109-
});
102+
//hook and execute tests
103+
webdriver.promise.controlFlow().execute(function () {
104+
var describe = test(driver);
110105

111-
self.registerHook('fiveby cleanup', describe, 'afterAll', function () {
106+
self.registerHook(describe, 'afterAll-first', function () {
112107
testComplete.fulfill();
113108
self.logManager.onAfterHook(driver);
109+
});
114110

111+
self.registerHook(describe, 'afterAll-last', function () {
115112
if (driver.session_) { //in case the tests already killed the session
116113
return driver.quit();
117114
}
@@ -120,35 +117,32 @@ fiveby.prototype.runSuiteInBrowsers = function (test) {
120117
run();
121118

122119
return webdriver.promise.fulfilled();
123-
};
124-
125-
//build driver
126-
var driver = new webdriver.Builder()
127-
.usingServer(self.config.hubUrl)
128-
.withCapabilities(capabilities)
129-
.build();
130-
driver.name = elem;
131-
driver.manage().timeouts().implicitlyWait(self.config.implicitWait);
132-
133-
webdriver.promise.controlFlow().execute(promo);
120+
});
134121

135122
});
136123
});
137124
};
138125

139-
fiveby.prototype.registerHook = function (name, suite, hookarr, func) {
140-
var hook = new Hook(name, func);
126+
fiveby.prototype.registerHook = function (suite, pos, func) {
127+
var hook = new Hook('fiveby '+pos+' hook', func);
128+
129+
pos = pos.split('-');
130+
var key = pos[0];
131+
var loc = pos[1];
132+
141133
hook.parent = suite;
142134
if (suite && suite.ctx) {
143135
hook.ctx = suite.ctx;
144136
} else {
145137
console.error('ERROR: Please return test suite (describe) in the fiveby constructor callback.');
146138
return process.exit(2);
147139
}
140+
148141
hook.timeout(5000);
149-
if (hookarr.indexOf('before') > -1) {
150-
suite['_' + hookarr].unshift(hook);
142+
143+
if (loc === 'first') {
144+
suite['_' + key].unshift(hook);
151145
} else {
152-
suite['_' + hookarr].push(hook);
146+
suite['_' + key].push(hook);
153147
}
154148
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fiveby",
3-
"version": "2.0.0-beta2",
3+
"version": "2.0.0-beta.3",
44
"description": "Package up testing options, levels, apis, and dependencies into one simple lib",
55
"scripts": {
66
"test": "gulp test"

test/fiveby.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ describe('fiveby hooks', function () {
182182

183183
it('before', function () {
184184
var arr = ['mark'];
185-
fb.registerHook('derper', {ctx:'yup', '_before': arr}, 'before', function () {});
185+
fb.registerHook({ctx:'yup', '_before': arr}, 'before-first', function () {});
186186
arr.length.should.equal(2);
187187
arr[1].should.equal('mark');
188188
});
189189

190190
it('after', function () {
191191
var arr = ['mark'];
192-
fb.registerHook('derper', {ctx:'yup', '_after': arr}, 'after', function () {});
192+
fb.registerHook({ctx:'yup', '_after': arr}, 'after-last', function () {});
193193
arr.length.should.equal(2);
194194
arr[0].should.equal('mark');
195195
});
@@ -199,7 +199,7 @@ describe('fiveby hooks', function () {
199199
code.should.equal(2);
200200
done();
201201
};
202-
fb.registerHook('derper', {'_after': []}, 'after', function () {});
202+
fb.registerHook({'_after': []}, 'after-first', function () {});
203203
});
204204

205205
});
@@ -224,7 +224,7 @@ describe('fiveby local server', function () {
224224
}
225225
};
226226

227-
var fiveby = proxyquire('../lib/fiveby', { 'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub});
227+
var fiveby = proxyquire('../lib/fiveby', { 'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub});
228228
var fb = new fiveby({browsers:{}});
229229
return fb.localServer().then(function () {
230230
count.should.equal(1);
@@ -250,7 +250,7 @@ describe('fiveby local server', function () {
250250
}
251251
};
252252

253-
var fiveby = proxyquire('../lib/fiveby', { 'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub});
253+
var fiveby = proxyquire('../lib/fiveby', { 'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub});
254254
var fb = new fiveby({browsers:{}});
255255
global.fivebyConfig.hubUrl='http://sample.stuff.xyz';
256256
global.serverPromise = null;
@@ -278,7 +278,7 @@ describe('fiveby local server', function () {
278278
}
279279
};
280280

281-
var fiveby = proxyquire('../lib/fiveby', { 'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub});
281+
var fiveby = proxyquire('../lib/fiveby', { 'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub});
282282
var fb = new fiveby({browsers:{}});
283283
global.serverPromise = promise.fulfilled();
284284
return fb.localServer().then(function () {
@@ -299,7 +299,7 @@ describe('runSuiteInBrowsers', function () {
299299
};
300300

301301
it('bad browser name', function (done) {
302-
var fiveby = proxyquire('../lib/fiveby', {'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub});
302+
var fiveby = proxyquire('../lib/fiveby', {'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub});
303303
var fb = new fiveby({browsers:{shmul:1}});
304304
console.warn = function (msg, browser) {
305305
msg.should.equal('No such browser: %s');
@@ -310,7 +310,7 @@ describe('runSuiteInBrowsers', function () {
310310
});
311311

312312
it('no browsers provided', function (done) {
313-
var fiveby = proxyquire('../lib/fiveby', {'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub});
313+
var fiveby = proxyquire('../lib/fiveby', {'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub});
314314
var fb = new fiveby({});
315315
console.warn = function (msg) {
316316
msg.should.equal('No browsers provided, must provide at least one');
@@ -320,22 +320,22 @@ describe('runSuiteInBrowsers', function () {
320320
});
321321

322322
it('browser 0 arg bail', function () {
323-
var fiveby = proxyquire('../lib/fiveby', {'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub});
323+
var fiveby = proxyquire('../lib/fiveby', {'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub});
324324
var fb = new fiveby({browsers:{chrome:1}});
325325
fb.runSuiteInBrowsers(function () {});
326326
});
327327

328328
it('exercise', function () {
329-
var fiveby = proxyquire('../lib/fiveby', { 'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub, 'selenium-webdriver': webDriverStub});
329+
var fiveby = proxyquire('../lib/fiveby', { 'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub, 'dj-webdriver': webDriverStub});
330330
var fb = new fiveby({browsers:{chrome:{'chromeOptions': {'args': ['--disable-extensions']}}, ie: 1}});
331-
fb.registerHook = function (name, suite, hookarr, func) {
331+
fb.registerHook = function (suite, hookarr, func) {
332332
func.apply({currentTest:{parent:{}}});
333333
};
334334
fb.runSuiteInBrowsers(function (b) {});
335335
});
336336

337337
it('exercise alt', function () { //refactor anyone =)
338-
var fiveby = proxyquire('../lib/fiveby', { 'selenium-webdriver/remote': webDriverStubRemote, './helper': helperStub, 'selenium-webdriver': webDriverStubFail});
338+
var fiveby = proxyquire('../lib/fiveby', { 'dj-webdriver/remote': webDriverStubRemote, './helper': helperStub, 'dj-webdriver': webDriverStubFail});
339339
var fb = new fiveby({browsers:{chrome:{'chromeOptions': {'args': ['--disable-extensions']}}, ie: 1}});
340340
promise.controlFlow = function () {
341341
return {
@@ -351,7 +351,7 @@ describe('runSuiteInBrowsers', function () {
351351
}
352352
};
353353
};
354-
fb.registerHook = function (name, suite, hookarr, func) {
354+
fb.registerHook = function (suite, hookarr, func) {
355355
func.apply({currentTest:{parent:{}}});
356356
};
357357
fb.runSuiteInBrowsers(function (b) {});

test/logManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global describe, it, before, assert, promise */
22
var proxyquire = require('proxyquire').noPreserveCache();
3-
var webdriver = require('selenium-webdriver');
3+
var webdriver = require('dj-webdriver');
44

55
var fsStub = {
66
existsSync: function () {

0 commit comments

Comments
 (0)