enabled.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Property that checks if an element is currently enabled.
  3. *
  4. * ```
  5. * this.demoTest = function (browser) {
  6. * browser.expect.element('#weblogin').to.be.enabled;
  7. * browser.expect.element('#main').to.not.be.enabled;
  8. * browser.expect.element('#main').to.be.enabled.before(100);
  9. * };
  10. * ```
  11. *
  12. * @method enabled
  13. * @display .enabled
  14. * @since v0.7
  15. * @api expect
  16. */
  17. var util = require('util');
  18. var events = require('events');
  19. var BaseAssertion = require('./_baseAssertion.js');
  20. function EnabledAssertion() {
  21. BaseAssertion.call(this);
  22. this.message = 'Expected element <%s> to ' + (this.negate ? 'not be enabled' : 'be enabled');
  23. this.start();
  24. }
  25. util.inherits(EnabledAssertion, BaseAssertion);
  26. EnabledAssertion.prototype.executeCommand = function(callback) {
  27. this.protocol.elementIdEnabled(this.elementResult.ELEMENT, callback);
  28. };
  29. EnabledAssertion.prototype.elementFound = function() {
  30. if (this.retries > 0 && this.negate) {
  31. return;
  32. }
  33. this.passed = this.negate ? !this.resultValue : this.resultValue;
  34. this.expected = this.negate ? 'not enabled' : 'enabled';
  35. this.actual = this.resultValue ? 'enabled' : 'not enabled';
  36. if (this.passed && this.waitForMs) {
  37. this.elapsedTime = this.getElapsedTime();
  38. this.messageParts.push(' - condition was met in ' + this.elapsedTime + 'ms');
  39. }
  40. };
  41. EnabledAssertion.prototype.elementNotFound = function() {
  42. this.passed = false;
  43. this.expected = this.negate ? 'not enabled' : 'enabled';
  44. this.actual = 'not found';
  45. };
  46. module.exports = EnabledAssertion;