Skip to content

Commit

Permalink
Merge branch 'releases/v0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Jun 11, 2017
2 parents 10f94de + f568f7b commit ecd1909
Show file tree
Hide file tree
Showing 23 changed files with 355 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tests_output
\#*
\.#*
output
/test/hooks_output
9 changes: 5 additions & 4 deletions lib/runner/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ Reporter.prototype.getTestsFailedMessage = function() {
skipped = format(' and %s skipped', colors.cyan(this.testResults.skipped));
}

if (this.globalResults.errors) {
var suffix = this.globalResults.errors > 1 ? 's' : '';
errorsMsg += format('%s error%s during execution, ', colors.red(this.globalResults.errors), suffix);
var globalErrors = this.globalResults.errors || this.testResults.errors;
if (globalErrors) {
var suffix = globalErrors > 1 ? 's' : '';
errorsMsg += format('%s error%s during execution, ', colors.red(globalErrors), suffix);
}

return format('%s %s %s failed, %s%s.', errorsMsg, colors.red(this.globalResults.failed), failedMsg, passedMsg, skipped);
Expand Down Expand Up @@ -273,7 +274,7 @@ Reporter.prototype.printFailureSummary = function() {
}
}.bind(this));

if (Array.isArray(this.globalResults.errmessages)) {
if (Array.isArray(this.globalResults.errmessages) && Object.keys(this.globalResults.modules).length === 0) {
this.globalResults.errmessages.forEach(function(err) {
console.log('');
Utils.showStackTrace(err);
Expand Down
1 change: 0 additions & 1 deletion lib/runner/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ module.exports = new (function() {

fs.writeFile(filename, rendered, function(err) {
callback(err);
globalResults.errmessages.length = 0;
});
}

Expand Down
15 changes: 9 additions & 6 deletions lib/runner/reporters/junit.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
for (var i = 0; i < assertions.length; i++) { %><% if (assertions[i].failure) { %> <failure message="<%= assertions[i].message %>"><%= assertions[i].stackTrace %></failure><% } %>
<% if (assertions[i].screenshots && assertions[i].screenshots.length > 0) { %><system-out><% for (var j = 0; j < assertions[i].screenshots.length; j++) { %>[[ATTACHMENT|<%= assertions[i].screenshots[j] %>]]<% } %></system-out><% } %>
<% }
if (testcase.failed > 0 && testcase.stackTrace) {
%><failure message="<%= testcase.message %>"><%= testcase.stackTrace %></failure><% } %>
</testcase><% if (systemerr != '') {%>
<system-err>
<%= systemerr %>
</system-err><% } %>
if (testcase.failed > 0 && testcase.stackTrace) { %><failure message="<%= testcase.message %>"><%= testcase.stackTrace %></failure><% } %>
</testcase>
<% } %>

<% if (systemerr != '') { %>
<system-err>
<%= systemerr %>
</system-err>
<% } %>

<% if (module.skipped && (module.skipped.length > 0)) { %>
<% for (var j = 0; j < module.skipped.length; j++) { %>
<testcase
Expand Down
4 changes: 4 additions & 0 deletions lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ Runner.prototype.runTestModule = function(modulePath, fullPaths) {
}
});

if (testResults.errmessages) {
this.globalResults.errmessages = this.globalResults.errmessages.concat(testResults.errmessages);
}
testSuiteResult.errmessages = testResults.errmessages || [];
testSuiteResult.failures = failures;
testSuiteResult.errors = errors;
Expand Down Expand Up @@ -262,6 +265,7 @@ Runner.prototype.run = function runner() {
try {
self.doneCb(null, self.globalResults);
deferred.resolve(self.globalResults);
self.globalResults.errmessages.length = 0;
} catch (err) {
deferred.reject(err);
}
Expand Down
75 changes: 65 additions & 10 deletions lib/runner/testsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ TestSuite.prototype.initHooks = function() {
var called = false;
var originalFn = self.module.get(key);

var doneFn = function() {
var doneFn = function(err) {
called = true;

if (err && key == 'after') {
self.executeHookCallback(err, done);
return;
}

if (callbackDeffered) {
return;
}
return done();

return done(err, true);
};


self.runHookMethod(item, context, argsCount, key, doneFn, this.deferred);

if (originalFn && (originalFn.length == self.expectedAsyncArgs) && self.client.shouldRestartQueue()) {
Expand Down Expand Up @@ -177,8 +185,8 @@ TestSuite.prototype.initAfterEachHook = function() {
if (self.options.compatible_testcase_support) {
asyncFn.call(module, doneFn);
} else {
asyncFn.call(module, api, function() {
doneFn();
asyncFn.call(module, api, function(err) {
self.executeHookCallback(err, doneFn);
});
}

Expand All @@ -190,6 +198,15 @@ TestSuite.prototype.initAfterEachHook = function() {
return this;
};

TestSuite.prototype.executeHookCallback = function(potentialErr, doneFn) {
if (potentialErr instanceof Error) {
this.testResults.errors++;
this.client.handleException(potentialErr);
}

doneFn();
};

TestSuite.prototype.run = function() {
var self = this;
this.print();
Expand Down Expand Up @@ -481,8 +498,7 @@ TestSuite.prototype.adaptGlobalHook = function(hookName) {

TestSuite.prototype.onGlobalHookError = function(err, hookErr, done) {
if (err && err.message) {
this.testResults.errors++;
this.testResults.errmessages = [err.message];
this.addErrorToResults(err);
}

return done(err, hookErr);
Expand All @@ -509,9 +525,8 @@ TestSuite.prototype.adaptDoneCallback = function(done, hookName, deferred) {
TestSuite.prototype.makePromise = function (fn) {
var deferred = Q.defer();
try {
fn.call(this, function(err, hookErr) {
// in case of an exception thrown inside a global hook, we need to reject the promise here
if (hookErr && Utils.isErrorObject(err)) {
fn.call(this, function(err, rejectOnError) {
if (rejectOnError && Utils.isErrorObject(err)) {
deferred.reject(err);
} else {
deferred.resolve();
Expand Down Expand Up @@ -573,7 +588,47 @@ TestSuite.prototype.runHookMethod = function(fn, context, asyncArgCount, hookNam
return hookFn.call(context, doneFn);
}

return hookFn.call(context, this.client.api(), doneFn);
return hookFn.call(context, this.client.api(), function(err) {
var doneCalled = false;
if (err instanceof Error) {
if (hookName != 'after') {
this.testResults.errors++;
}

this.testResults.errmessages = [err.stack];

if (hookName == 'beforeEach') {
// FIXME: hack to close the session properly after an error thrown in the beforeEach
(function() {
if (this.sessionId) {
doneCalled = true;
setImmediate(function() {
this.queue.reset();
this.queue.empty();
this.terminate();
doneFn();
}.bind(this));
} else {
this.once('selenium:session_create', function() {
// we need to wait for the session to be created to attempt to close it
this.queue.reset();
this.queue.empty();
setImmediate(function() {
this.terminate();
}.bind(this));
}.bind(this));
}
}.bind(this.client['@client'])());
} else {
this.client.terminate();
}
}

if (!doneCalled) {
doneFn((hookName == 'afterEach' || hookName == 'after') ? err : undefined);
}

}.bind(this));
};

TestSuite.prototype.adaptHookMethod = function(fn, context, asyncArgCount) {
Expand Down
4 changes: 2 additions & 2 deletions lib/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ Util.setCallbackTimeout = function(done, fnName, timeMs, onCatch, onTimerStarted
onTimerStarted(timeout);
}

return function(ex) {
return function(err) {
clearTimeout(timeout);
done(ex, true);
done(err, true);
};
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nightwatch",
"description": "A node.js bindings implementation for selenium 2.0/webdriver",
"version": "0.9.15",
"version": "0.9.16",
"author": {
"name": "Andrei Rusu",
"email": "[email protected]"
Expand Down Expand Up @@ -41,7 +41,8 @@
"mocha-lcov-reporter": "^1.2.0",
"mock-spawn": "^0.2.1",
"mockery": "~1.4.0",
"nock": "~0.45.0"
"nock": "~0.45.0",
"xml2json": "^0.11.0"
},
"bin": {
"nightwatch": "./bin/nightwatch"
Expand Down
11 changes: 11 additions & 0 deletions test/asynchookstests/async-provide-error/after.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

after : function(client, done) {
done(new Error('Provided error after'));
}
};
13 changes: 13 additions & 0 deletions test/asynchookstests/async-provide-error/afterAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

after : function(client, done) {
setTimeout(function() {
done(new Error('Provided error afterAsync'));
}, 10);
}
};
11 changes: 11 additions & 0 deletions test/asynchookstests/async-provide-error/afterEach.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

afterEach : function(client, done) {
done(new Error('Provided error afterEach'));
}
};
13 changes: 13 additions & 0 deletions test/asynchookstests/async-provide-error/afterEachAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

afterEach : function(client, done) {
setTimeout(function() {
done(new Error('Provided error afterEachAsync'));
}, 10);
}
};
13 changes: 13 additions & 0 deletions test/asynchookstests/async-provide-error/afterEachWithClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

afterEach : function(client, done) {
client.end(function() {
done(new Error('Provided error afterEachWithClient'));
});
}
};
13 changes: 13 additions & 0 deletions test/asynchookstests/async-provide-error/afterWithClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

after : function(client, done) {
client.end(function() {
done(new Error('Provided error afterWithClient'));
});
}
};
11 changes: 11 additions & 0 deletions test/asynchookstests/async-provide-error/before.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

before : function(client, done) {
done(new Error('Provided error before'));
}
};
13 changes: 13 additions & 0 deletions test/asynchookstests/async-provide-error/beforeAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

before : function(client, done) {
setTimeout(function() {
done(new Error('Provided error beforeAsync'));
}, 10);
}
};
11 changes: 11 additions & 0 deletions test/asynchookstests/async-provide-error/beforeEach.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

beforeEach : function(client, done) {
done(new Error('Provided error beforeEach'));
}
};
13 changes: 13 additions & 0 deletions test/asynchookstests/async-provide-error/beforeEachAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

beforeEach : function(client, done) {
setTimeout(function() {
done(new Error('Provided error beforeEachAsync'));
}, 10);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
},

beforeEach : function(client, done) {
client.perform(function() {
setTimeout(function() {
done(new Error('Provided error beforeEachAsyncWithClient'));
}, 10);
});
}
};
Loading

0 comments on commit ecd1909

Please sign in to comment.