Skip to content

Commit 3800934

Browse files
rchettribeatfactor
rchettri
authored andcommitted
Fixed #764 - use custom waitFor when available instead of implicit waitFor
1 parent f0126ef commit 3800934

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

lib/api/expect/_baseAssertion.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ BaseAssertion.prototype['@afterFlag'] = function(value) {};
287287

288288
BaseAssertion.prototype['@haveFlag'] = function(value) {};
289289
BaseAssertion.prototype['@waitForFlag'] = function(value) {
290-
if ((this.waitForMs === null) && value) {
290+
if (this.waitForMs !== value) {
291291
this.waitForMs = value;
292292
if (!this.customMessage) {
293293
this.messageParts.push(this.checkWaitForMsg(this.waitForMs));

tests/src/expect/testExpectAttribute.js

+96
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ module.exports = {
5454
test.done();
5555
})
5656
},
57+
58+
59+
'to have attribute with implicit and custom waitFor [PASSED]' : function(test) {
60+
Nocks.elementFound().attributeValue('hp vasq');
61+
this.client.api.globals.abortOnAssertionFailure = false;
62+
this.client.api.globals.waitForConditionTimeout = 65;
63+
64+
var expect = this.client.api.expect.element('#weblogin').to.have.attribute('class').before(100);
65+
this.client.on('nightwatch:finished', function(results, errors) {
66+
test.equals(expect.assertion.waitForMs, 100);
67+
test.equals(expect.assertion.passed, true);
68+
test.equals(expect.assertion.message, 'Expected element <#weblogin> to have attribute "class" in 100ms - attribute was present in '+ expect.assertion.elapsedTime +'ms');
69+
test.done();
70+
})
71+
},
5772

5873
'to have attribute with waitFor [FAILED]' : function(test) {
5974
this.client.api.globals.waitForConditionPollInterval = 50;
@@ -70,6 +85,21 @@ module.exports = {
7085
})
7186
},
7287

88+
'to have attribute with implicit and custom waitFor [FAILED]' : function(test) {
89+
this.client.api.globals.waitForConditionPollInterval = 50;
90+
Nocks.elementFound().attributeValue(null);
91+
this.client.api.globals.waitForConditionTimeout = 65;
92+
93+
var expect = this.client.api.expect.element('#weblogin').to.have.attribute('class').before(100);
94+
this.client.on('nightwatch:finished', function(results, errors) {
95+
test.equals(expect.assertion.waitForMs, 100);
96+
test.equals(expect.assertion.passed, false);
97+
test.equals(expect.assertion.abortOnFailure, true);
98+
test.equals(expect.assertion.message, 'Expected element <#weblogin> to have attribute "class" in 100ms - attribute was not found');
99+
test.done();
100+
})
101+
},
102+
73103
'to have attribute with message [PASSED]' : function(test) {
74104
Nocks.elementFound().attributeValue('hp vasq');
75105

@@ -125,6 +155,7 @@ module.exports = {
125155
this.client.on('nightwatch:finished', function(results, errors) {
126156
test.equals(expect.assertion.selector, '#weblogin');
127157
test.equals(expect.assertion.negate, true);
158+
test.equals(expect.assertion.waitForMs, null);
128159
test.equals(expect.assertion.passed, true);
129160
test.equals(expect.assertion.expected, 'not found');
130161
test.equals(expect.assertion.actual, 'not found');
@@ -267,6 +298,23 @@ module.exports = {
267298
})
268299
},
269300

301+
'to have attribute equal with custom waitFor [PASSED]' : function(test) {
302+
this.client.api.globals.waitForConditionPollInterval = 50;
303+
this.client.api.globals.waitForConditionTimeout = 100;
304+
Nocks.elementFound();
305+
306+
var expect = this.client.api.expect.element('#weblogin').to.have.attribute('class').equal('hp vasq').before(60);
307+
Nocks.attributeValue(null).attributeValue('hp vasq');
308+
309+
this.client.on('nightwatch:finished', function(results, errors) {
310+
test.equals(expect.assertion.waitForMs, 60);
311+
test.equals(expect.assertion.passed, true);
312+
test.equals(expect.assertion.retries, 1);
313+
test.equals(expect.assertion.message, 'Expected element <#weblogin> to have attribute "class" equal to: "hp vasq" in 60ms - condition was met in ' + expect.assertion.elapsedTime + 'ms');
314+
test.done();
315+
})
316+
},
317+
270318
'to have attribute equal and waitFor [FAILED] - attribute not found' : function(test) {
271319
this.client.api.globals.waitForConditionPollInterval = 50;
272320

@@ -284,6 +332,23 @@ module.exports = {
284332
})
285333
},
286334

335+
'to have attribute equal and custom waitFor [FAILED] - attribute not found' : function(test) {
336+
this.client.api.globals.waitForConditionPollInterval = 50;
337+
this.client.api.globals.waitForConditionTimeout = 100;
338+
Nocks.elementFound();
339+
340+
var expect = this.client.api.expect.element('#weblogin').to.have.attribute('class').equal('hp vasq').before(60);
341+
Nocks.attributeValue(null).attributeValue(null);
342+
343+
this.client.on('nightwatch:finished', function(results, errors) {
344+
test.equals(expect.assertion.waitForMs, 60);
345+
test.equals(expect.assertion.passed, false);
346+
test.ok(expect.assertion.retries > 1);
347+
test.equals(expect.assertion.message, 'Expected element <#weblogin> to have attribute "class" equal to: "hp vasq" in 60ms - attribute was not found');
348+
test.done();
349+
})
350+
},
351+
287352
'to have attribute equal and waitFor [FAILED] - attribute not equal' : function(test) {
288353
this.client.api.globals.waitForConditionPollInterval = 10;
289354
Nocks.elementFound().attributeValue('xx').attributeValue('xx');
@@ -507,6 +572,21 @@ module.exports = {
507572
})
508573
},
509574

575+
'to have attribute with custom waitFor - element not found' : function(test) {
576+
this.client.api.globals.waitForConditionPollInterval = 50;
577+
this.client.api.globals.waitForConditionTimeout = 50;
578+
579+
Nocks.elementNotFound().elementNotFound().elementNotFound();
580+
581+
var expect = this.client.api.expect.element('#weblogin').to.have.attribute('class').before(100);
582+
this.client.on('nightwatch:finished', function(results, errors) {
583+
test.equal(expect.assertion.waitForMs, 100);
584+
test.equals(expect.assertion.passed, false);
585+
test.equals(expect.assertion.message, 'Expected element <#weblogin> to have attribute "class" in 100ms - element was not found');
586+
test.done();
587+
})
588+
},
589+
510590
'to have attribute with waitFor - element found on retry' : function(test) {
511591
this.client.api.globals.waitForConditionPollInterval = 50;
512592

@@ -522,6 +602,22 @@ module.exports = {
522602
})
523603
},
524604

605+
'to have attribute with custom waitFor - element found on retry' : function(test) {
606+
this.client.api.globals.waitForConditionPollInterval = 50;
607+
this.client.api.globals.waitForConditionTimeout = 60;
608+
Nocks.elementNotFound().elementFound().attributeValue('hp vasq');
609+
610+
var expect = this.client.api.expect.element('#weblogin').to.have.attribute('class').before(100);
611+
612+
this.client.on('nightwatch:finished', function(results, errors) {
613+
test.equal(expect.assertion.waitForMs, 100);
614+
test.equals(expect.assertion.passed, true);
615+
test.equals(expect.assertion.message, 'Expected element <#weblogin> to have attribute "class" in 100ms - attribute was present in ' + expect.assertion.elapsedTime + 'ms');
616+
test.done();
617+
})
618+
},
619+
620+
525621
'to have attribute match - throws exception on invalid regex' : function(test) {
526622
Nocks.elementFound().attributeValue('xx');
527623

0 commit comments

Comments
 (0)