Skip to content

Commit 8273828

Browse files
committed
Fixed #1394 - locateStrategy was not reset when test suite is retried
1 parent 6d456bd commit 8273828

File tree

8 files changed

+73
-10
lines changed

8 files changed

+73
-10
lines changed

lib/api/assertions/elementPresent.js

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
var util = require('util');
1717
exports.assertion = function(selector, msg) {
18-
1918
this.message = msg || util.format('Testing if element <%s> is present.', selector);
2019
this.expected = 'present';
2120

lib/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ var Utils = require('./util/utils.js');
1414
function Nightwatch(options) {
1515
events.EventEmitter.call(this);
1616

17-
this.locateStrategy = 'css selector';
18-
1917
this.api = {
2018
capabilities : {},
2119
globals : options && options.persist_globals && options.globals || {},
@@ -96,9 +94,7 @@ Nightwatch.prototype.setOptions = function(options) {
9694
};
9795
}
9896

99-
if (this.options.use_xpath) {
100-
this.locateStrategy = 'xpath';
101-
}
97+
this.setLocateStrategy();
10298

10399
if (this.options.silent) {
104100
Logger.disable();
@@ -186,6 +182,11 @@ Nightwatch.prototype.setCapabilities = function() {
186182
return this;
187183
};
188184

185+
Nightwatch.prototype.setLocateStrategy = function () {
186+
this.locateStrategy = this.options.use_xpath ? 'xpath' : 'css selector';
187+
return this;
188+
};
189+
189190
Nightwatch.prototype.loadKeyCodes = function() {
190191
this.api.Keys = require('./util/keys.json');
191192
return this;

lib/runner/clientmanager.js

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ ClientManager.prototype.terminate = function() {
142142
return this;
143143
};
144144

145+
ClientManager.prototype.setLocateStrategy = function() {
146+
this['@client'].setLocateStrategy();
147+
return this;
148+
};
145149

146150
ClientManager.prototype.resetTerminated = function() {
147151
this['@client'].resetTerminated();

lib/runner/testsuite.js

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ TestSuite.prototype.printRetry = function() {
280280

281281
TestSuite.prototype.retryTestSuiteModule = function() {
282282
this.client.resetTerminated();
283+
this.client.setLocateStrategy();
283284
this.clearResult();
284285
this.suiteRetries +=1;
285286
this.resetTestCases();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var failFirstTime = true;
2+
3+
module.exports = {
4+
before: function (client) {
5+
client.url('http://localhost')
6+
},
7+
8+
after: function (client) {
9+
client.end();
10+
},
11+
12+
demoStep1 : function (client) {
13+
client
14+
.assert.elementPresent('#weblogin')
15+
.elements('css selector', '#weblogin', function() {
16+
if (failFirstTime) {
17+
client.useRecursion();
18+
}
19+
})
20+
.perform(function() {
21+
if (failFirstTime) {
22+
failFirstTime = false;
23+
client.assert.ok(false);
24+
}
25+
});
26+
}
27+
28+
};

test/src/runner/cli/testParallelExecution.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module.exports = {
9898
done(err);
9999
return;
100100
}
101-
assert.equal(self.allArgs.length, 21);
101+
assert.equal(self.allArgs.length, 22);
102102
assert.ok(path.join('sampletests', 'async', 'sample_1') in runner.runningProcesses);
103103
assert.ok(path.join('sampletests', 'before-after', 'sampleSingleTest_2') in runner.runningProcesses);
104104

@@ -156,7 +156,7 @@ module.exports = {
156156

157157
runner.setup({}, function () {
158158
assert.ok(!runner.isParallelMode());
159-
assert.equal(self.allArgs.length, 21);
159+
assert.equal(self.allArgs.length, 22);
160160
done();
161161
});
162162

@@ -184,7 +184,7 @@ module.exports = {
184184
return;
185185
}
186186
assert.ok(!runner.isParallelMode());
187-
assert.equal(self.allArgs.length, 21);
187+
assert.equal(self.allArgs.length, 22);
188188
done();
189189
});
190190

test/src/runner/testRunTestsuite.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,38 @@ module.exports = {
9191
});
9292
},
9393

94+
testRunSuiteRetriesWithLocateStrategy : function(done) {
95+
var testsPath = path.join(__dirname, '../../sampletests/suiteretries/locate-strategy');
96+
var globals = {
97+
calls : 0
98+
};
99+
100+
var runner = new Runner([testsPath], {
101+
seleniumPort : 10195,
102+
silent : true,
103+
output : false,
104+
persist_globals : true,
105+
globals : globals,
106+
skip_testcases_on_fail: false
107+
}, {
108+
output_folder : false,
109+
start_session : true,
110+
suite_retries: 1
111+
}, function(err, results) {
112+
if (err) {
113+
throw err;
114+
}
115+
assert.equal(runner.currentTestSuite.client['@client'].locateStrategy, 'css selector');
116+
done();
117+
});
118+
119+
runner.run().catch(function(err) {
120+
done(err);
121+
});
122+
},
123+
94124
'test clear command queue when run with suiteRetries' : function(done) {
95-
var testsPath = path.join(__dirname, '../../sampletests/suiteretries');
125+
var testsPath = path.join(__dirname, '../../sampletests/suiteretries/sample');
96126
var globals = {
97127
calls : 0
98128
};

0 commit comments

Comments
 (0)