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 Mar 11, 2017
2 parents aca797a + 1415623 commit a8c1652
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 29 deletions.
1 change: 0 additions & 1 deletion lib/api/assertions/elementPresent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

var util = require('util');
exports.assertion = function(selector, msg) {

this.message = msg || util.format('Testing if element <%s> is present.', selector);
this.expected = 'present';

Expand Down
11 changes: 6 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ var Utils = require('./util/utils.js');
function Nightwatch(options) {
events.EventEmitter.call(this);

this.locateStrategy = 'css selector';

this.api = {
capabilities : {},
globals : options && options.persist_globals && options.globals || {},
Expand Down Expand Up @@ -96,9 +94,7 @@ Nightwatch.prototype.setOptions = function(options) {
};
}

if (this.options.use_xpath) {
this.locateStrategy = 'xpath';
}
this.setLocateStrategy();

if (this.options.silent) {
Logger.disable();
Expand Down Expand Up @@ -186,6 +182,11 @@ Nightwatch.prototype.setCapabilities = function() {
return this;
};

Nightwatch.prototype.setLocateStrategy = function () {
this.locateStrategy = this.options.use_xpath ? 'xpath' : 'css selector';
return this;
};

Nightwatch.prototype.loadKeyCodes = function() {
this.api.Keys = require('./util/keys.json');
return this;
Expand Down
4 changes: 4 additions & 0 deletions lib/runner/clientmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ ClientManager.prototype.terminate = function() {
return this;
};

ClientManager.prototype.setLocateStrategy = function() {
this['@client'].setLocateStrategy();
return this;
};

ClientManager.prototype.resetTerminated = function() {
this['@client'].resetTerminated();
Expand Down
16 changes: 10 additions & 6 deletions lib/runner/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,28 @@ module.exports = new (function() {
var module = globalResults.modules[moduleKey];
var pathParts = moduleKey.split(path.sep);
var moduleName = pathParts.pop();
var className = moduleName;
var output_folder = opts.output_folder;

adaptAssertions(module);

if (pathParts.length) {
output_folder = path.join(output_folder, pathParts.join(path.sep));
mkpath.sync(output_folder);
className = pathParts.join('.') + '.' + moduleName;
}

var filename = path.join(output_folder, opts.filename_prefix + moduleName + '.xml');

var rendered = ejs.render(data, {
locals: {
module : module,
moduleName : moduleName,
className : className,
systemerr : globalResults.errmessages.join('\n')
}
});

if (pathParts.length) {
output_folder = path.join(output_folder, pathParts.join(path.sep));
mkpath.sync(output_folder);
}

var filename = path.join(output_folder, opts.filename_prefix + moduleName + '.xml');
fs.writeFile(filename, rendered, function(err) {
callback(err);
globalResults.errmessages.length = 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/runner/reporters/junit.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
failures="<%= module.failures %>"
tests="<%= module.tests %>">

<testsuite name="<%= moduleName %>"
<testsuite name="<%= className %>"
errors="<%= module.errors %>" failures="<%= module.failures %>" hostname="" id="" package="<%= module.group || moduleName %>" skipped="<%= (Array.isArray(module.skipped)) ? module.skipped.length : 0 %>"
tests="<%= module.tests %>" time="<%= module.time %>" timestamp="<%= module.timestamp %>">
<% for (var item in module.completed) {
var testcase = module.completed[item];
var assertions = testcase.assertions %>
<testcase name="<%= item %>" time="<%= testcase.time %>" assertions="<%= assertions.length %>"><%
<testcase name="<%= item %>" classname="<%= className %>" time="<%= testcase.time %>" assertions="<%= assertions.length %>"><%
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><% } %>
<% }
Expand All @@ -23,7 +23,7 @@
<% if (module.skipped && (module.skipped.length > 0)) { %>
<% for (var j = 0; j < module.skipped.length; j++) { %>
<testcase
name="<%= module.skipped[j] %>">
name="<%= module.skipped[j] %>" classname="<%= className %>">
<skipped />
</testcase>
<% } %>
Expand Down
1 change: 1 addition & 0 deletions lib/runner/testsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ TestSuite.prototype.printRetry = function() {

TestSuite.prototype.retryTestSuiteModule = function() {
this.client.resetTerminated();
this.client.setLocateStrategy();
this.clearResult();
this.suiteRetries +=1;
this.resetTestCases();
Expand Down
18 changes: 9 additions & 9 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.12",
"version": "0.9.13",
"author": {
"name": "Andrei Rusu",
"email": "[email protected]"
Expand All @@ -16,15 +16,15 @@
},
"dependencies": {
"chai-nightwatch": "~0.1.x",
"ejs": "~0.8.3",
"lodash.clone": "^3.0.3",
"lodash.defaultsdeep": "^4.3.2",
"minimatch": "~0.2.14",
"mkpath": ">=0.1.0",
"ejs": "0.8.3",
"lodash.clone": "3.0.3",
"lodash.defaultsdeep": "4.3.2",
"minimatch": "3.0.3",
"mkpath": "1.0.0",
"mocha-nightwatch": "2.2.9",
"optimist": ">=0.3.5",
"proxy-agent": ">=2.0.0",
"q": "^1.1.2"
"optimist": "0.6.1",
"proxy-agent": "2.0.0",
"q": "1.4.1"
},
"devDependencies": {
"chai": "^3.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var failFirstTime = true;

module.exports = {
before: function (client) {
client.url('http://localhost')
},

after: function (client) {
client.end();
},

demoStep1 : function (client) {
client
.assert.elementPresent('#weblogin')
.elements('css selector', '#weblogin', function() {
if (failFirstTime) {
client.useRecursion();
}
})
.perform(function() {
if (failFirstTime) {
failFirstTime = false;
client.assert.ok(false);
}
});
}

};
6 changes: 3 additions & 3 deletions test/src/runner/cli/testParallelExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = {
done(err);
return;
}
assert.equal(self.allArgs.length, 21);
assert.equal(self.allArgs.length, 22);
assert.ok(path.join('sampletests', 'async', 'sample_1') in runner.runningProcesses);
assert.ok(path.join('sampletests', 'before-after', 'sampleSingleTest_2') in runner.runningProcesses);

Expand Down Expand Up @@ -156,7 +156,7 @@ module.exports = {

runner.setup({}, function () {
assert.ok(!runner.isParallelMode());
assert.equal(self.allArgs.length, 21);
assert.equal(self.allArgs.length, 22);
done();
});

Expand Down Expand Up @@ -184,7 +184,7 @@ module.exports = {
return;
}
assert.ok(!runner.isParallelMode());
assert.equal(self.allArgs.length, 21);
assert.equal(self.allArgs.length, 22);
done();
});

Expand Down
32 changes: 31 additions & 1 deletion test/src/runner/testRunTestsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,38 @@ module.exports = {
});
},

testRunSuiteRetriesWithLocateStrategy : function(done) {
var testsPath = path.join(__dirname, '../../sampletests/suiteretries/locate-strategy');
var globals = {
calls : 0
};

var runner = new Runner([testsPath], {
seleniumPort : 10195,
silent : true,
output : false,
persist_globals : true,
globals : globals,
skip_testcases_on_fail: false
}, {
output_folder : false,
start_session : true,
suite_retries: 1
}, function(err, results) {
if (err) {
throw err;
}
assert.equal(runner.currentTestSuite.client['@client'].locateStrategy, 'css selector');
done();
});

runner.run().catch(function(err) {
done(err);
});
},

'test clear command queue when run with suiteRetries' : function(done) {
var testsPath = path.join(__dirname, '../../sampletests/suiteretries');
var testsPath = path.join(__dirname, '../../sampletests/suiteretries/sample');
var globals = {
calls : 0
};
Expand Down
16 changes: 15 additions & 1 deletion test/src/runner/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,21 @@ module.exports = {

assert.ok(fileExistsSync(simpleReportFile), 'The simple report file was not created.');
assert.ok(fileExistsSync(tagsReportFile), 'The tags report file was not created.');
done();

fs.readFile(simpleReportFile, function(err, data) {
if (err) {
return done(err);
}

var content = data.toString();
try {
assert.ok(/<testsuite[\s]+name="simple\.sample"[\s]+errors="0"[\s]+failures="0"[\s]+hostname=""[\s]+id=""[\s]+package="simple"[\s]+skipped="0"[\s]+tests="1"/.test(content), 'Report does not contain correct testsuite information.');
assert.ok(/<testcase[\s]+name="simpleDemoTest"[\s]+classname="simple\.sample"[\s]+time="[.\d]+"[\s]+assertions="1">/.test(content), 'Report does not contain the correct testcase element.');
done();
} catch (err) {
done(err);
}
});
} catch (err) {
done(err);
}
Expand Down

0 comments on commit a8c1652

Please sign in to comment.