提交 | 用户 | age
|
36e1de
|
1 |
// A custom Nightwatch assertion. |
L |
2 |
// The assertion name is the filename. |
|
3 |
// Example usage: |
|
4 |
// |
|
5 |
// browser.assert.elementCount(selector, count) |
|
6 |
// |
|
7 |
// For more information on custom assertions see: |
|
8 |
// http://nightwatchjs.org/guide#writing-custom-assertions |
|
9 |
|
|
10 |
exports.assertion = function (selector, count) { |
|
11 |
this.message = 'Testing if element <' + selector + '> has count: ' + count |
|
12 |
this.expected = count |
|
13 |
this.pass = function (val) { |
|
14 |
return val === this.expected |
|
15 |
} |
|
16 |
this.value = function (res) { |
|
17 |
return res.value |
|
18 |
} |
|
19 |
this.command = function (cb) { |
|
20 |
var self = this |
|
21 |
return this.api.execute(function (selector) { |
|
22 |
return document.querySelectorAll(selector).length |
|
23 |
}, [selector], function (res) { |
|
24 |
cb.call(self, res) |
|
25 |
}) |
|
26 |
} |
|
27 |
} |