cssProperty.js 1.4 KB

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