elementCount.js 645 B

1234567891011121314151617181920
  1. // A custom Nightwatch assertion.
  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. exports.assertion = function elementCount (selector, count) {
  10. this.message = `Testing if element <${selector}> has count: ${count}`
  11. this.expected = count
  12. this.pass = val => val === count
  13. this.value = res => res.value
  14. function evaluator (_selector) {
  15. return document.querySelectorAll(_selector).length
  16. }
  17. this.command = cb => this.api.execute(evaluator, [selector], cb)
  18. }