Skip to content

Commit

Permalink
Fixed nightwatchjs#1394 - locateStrategy was not reset when test suit…
Browse files Browse the repository at this point in the history
…e is retried
  • Loading branch information
beatfactor committed Mar 11, 2017
1 parent 6d456bd commit 8273828
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 10 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
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
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

0 comments on commit 8273828

Please sign in to comment.