selected.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected.
  3. *
  4. * ```
  5. * this.demoTest = function (browser) {
  6. * browser.expect.element('#main').to.be.selected;
  7. * browser.expect.element('#main').to.not.be.selected;
  8. * browser.expect.element('#main').to.be.selected.before(100);
  9. * };
  10. * ```
  11. *
  12. * @method selected
  13. * @display .selected
  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 SelectedAssertion() {
  21. BaseAssertion.call(this);
  22. this.message = 'Expected element <%s> to ' + (this.negate ? 'not be selected' : 'be selected');
  23. this.start();
  24. }
  25. util.inherits(SelectedAssertion, BaseAssertion);
  26. SelectedAssertion.prototype.executeCommand = function(callback) {
  27. this.protocol.elementIdSelected(this.elementResult.ELEMENT, callback);
  28. };
  29. SelectedAssertion.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 selected' : 'selected';
  35. this.actual = this.resultValue ? 'selected' : 'not selected';
  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. SelectedAssertion.prototype.elementNotFound = function() {
  42. this.passed = false;
  43. this.expected = this.negate ? 'not selected' : 'selected';
  44. this.actual = 'not found';
  45. };
  46. module.exports = SelectedAssertion;