elementCount.js 786 B

12345678910111213141516171819202122232425262728
  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(selector, count) {
  10. this.message = 'Testing if element <' + selector + '> has count: ' + count
  11. this.expected = count
  12. this.pass = function(val) {
  13. return val === this.expected
  14. }
  15. this.value = function(res) {
  16. return res.value
  17. }
  18. this.command = function(cb) {
  19. var self = this
  20. return this.api.execute(function(selector) {
  21. return document.querySelectorAll(selector).length
  22. }, [selector], function(res) {
  23. cb.call(self, res)
  24. })
  25. }
  26. }