visible.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Property that asserts the visibility of a specified element.
  3. *
  4. * ```
  5. * this.demoTest = function (browser) {
  6. * browser.expect.element('#main').to.be.visible;
  7. * browser.expect.element('#main').to.not.be.visible;
  8. * browser.expect.element('#main').to.be.visible.before(100);
  9. * };
  10. * ```
  11. *
  12. * @display .visible
  13. * @method visible
  14. * @api expect
  15. */
  16. var util = require('util');
  17. var BaseAssertion = require('./_baseAssertion.js');
  18. function VisibleAssertion() {
  19. BaseAssertion.call(this);
  20. this.message = 'Expected element <%s> to ' + (this.negate ? 'not be visible' : 'be visible');
  21. this.start();
  22. }
  23. util.inherits(VisibleAssertion, BaseAssertion);
  24. VisibleAssertion.prototype.executeCommand = function(callback) {
  25. this.protocol.elementIdDisplayed(this.elementResult.ELEMENT, callback);
  26. };
  27. VisibleAssertion.prototype.elementFound = function() {
  28. this.passed = this.negate ? this.resultValue === false : this.resultValue;
  29. this.expected = this.negate ? 'not visible' : 'visible';
  30. this.actual = this.resultValue ? 'visible' : 'not visible';
  31. if (this.passed && this.waitForMs) {
  32. this.elapsedTime = this.getElapsedTime();
  33. this.messageParts.push(' - condition was met in ' + this.elapsedTime + 'ms');
  34. }
  35. };
  36. VisibleAssertion.prototype.elementNotFound = function() {
  37. this.passed = false;
  38. this.expected = this.negate ? 'not visible' : 'visible';
  39. this.actual = 'not found';
  40. };
  41. module.exports = VisibleAssertion;