Skip to content

Instantly share code, notes, and snippets.

@tpaksu
Created September 9, 2019 09:09
Show Gist options
  • Save tpaksu/481ba83e6f32dae397782e33c617e622 to your computer and use it in GitHub Desktop.
Save tpaksu/481ba83e6f32dae397782e33c617e622 to your computer and use it in GitHub Desktop.
nightwatch assert.visibleCount
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