hidden.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Checks if the given element is not visible on the page.
  3. *
  4. * ```
  5. * this.demoTest = function (client) {
  6. * browser.assert.hidden(".should_not_be_visible");
  7. * };
  8. * ```
  9. *
  10. * @method hidden
  11. * @param {string} selector The selector (CSS / Xpath) used to locate the element.
  12. * @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
  13. * @api assertions
  14. */
  15. var util = require('util');
  16. exports.assertion = function(selector, msg) {
  17. var MSG_ELEMENT_NOT_FOUND = 'Testing if element <%s> is hidden. ' +
  18. 'Element could not be located.';
  19. this.message = msg || util.format('Testing if element <%s> is hidden.', selector);
  20. this.expected = true;
  21. this.pass = function(value) {
  22. return value === this.expected;
  23. };
  24. this.failure = function(result) {
  25. var failed = result === false || result && result.status === -1;
  26. if (failed) {
  27. this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector);
  28. }
  29. return failed;
  30. };
  31. this.value = function(result) {
  32. return !result.value;
  33. };
  34. this.command = function(callback) {
  35. return this.api.isVisible(selector, callback);
  36. };
  37. };