Created
September 9, 2019 09:09
-
-
Save tpaksu/481ba83e6f32dae397782e33c617e622 to your computer and use it in GitHub Desktop.
nightwatch assert.visibleCount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.assertion = function(selector, count, message = null) { | |
this.message = | |
message || | |
`Asserting that there are "${count}" visible elements that match "${selector}"`; | |
this.expected = count; | |
this.pass = function(value) { | |
return value === this.expected; | |
}; | |
this.value = function(result) { | |
return result.value; | |
}; | |
this.command = function(callback) { | |
const self = this; | |
return this.api.execute( | |
function(selector) { | |
var count = 0; | |
document.querySelectorAll(selector).forEach(function(node) { | |
if (node.offsetHeight !== 0) { | |
count++; | |
} | |
}); | |
return count; | |
}, | |
[selector], | |
function(result) { | |
return callback.call(self, result); | |
} | |
); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment