value.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Property that retrieves the value (i.e. the value attributed) of an element. Can be chained to check if contains/equals/matches the specified text or regex.
  3. *
  4. * ```
  5. * this.demoTest = function (browser) {
  6. * browser.expect.element('#q').to.have.value.that.equals('search');
  7. * browser.expect.element('#q').to.have.value.not.equals('search');
  8. * browser.expect.element('#q').to.have.value.which.contains('search');
  9. * browser.expect.element('#q').to.have.value.which.matches(/search/);
  10. * };
  11. * ```
  12. *
  13. * @display .value
  14. * @method value
  15. * @api expect
  16. */
  17. var util = require('util');
  18. var events = require('events');
  19. var BaseAssertion = require('./_baseAssertion.js');
  20. function ValueAssertion() {
  21. this.flag('valueFlag', true);
  22. BaseAssertion.call(this);
  23. this.message = 'Expected element <%s> to have value' + (this.negate ? ' not' : '');
  24. this.start();
  25. }
  26. util.inherits(ValueAssertion, BaseAssertion);
  27. ValueAssertion.prototype.executeCommand = function(callback) {
  28. this.protocol.elementIdValue(this.elementResult.ELEMENT, callback);
  29. };
  30. ValueAssertion.prototype.elementFound = function() {
  31. if (this.retries > 0 && this.negate) {
  32. return;
  33. }
  34. if (this.passed && this.waitForMs) {
  35. var message = '';
  36. if (this.hasCondition()) {
  37. message = 'condition was met';
  38. }
  39. this.elapsedTime = this.getElapsedTime();
  40. this.messageParts.push(' - ' + message + ' in ' + this.elapsedTime + 'ms');
  41. }
  42. };
  43. ValueAssertion.prototype.elementNotFound = function() {
  44. this.passed = false;
  45. };
  46. module.exports = ValueAssertion;