elementCount.js 777 B

1234567891011121314151617181920212223242526
  1. // A custom Nightwatch assertion.
  2. // the name of the method is the filename.
  3. // can be used in tests like this:
  4. //
  5. // browser.assert.elementCount(selector, count)
  6. //
  7. // for how to write 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. }