urlContains.js 849 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Checks if the current URL contains the given value.
  3. *
  4. * ```
  5. * this.demoTest = function (client) {
  6. * browser.assert.urlContains('google');
  7. * };
  8. * ```
  9. *
  10. * @method urlContains
  11. * @param {string} expected The value expected to exist within the current URL.
  12. * @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
  13. * @api assertions
  14. */
  15. var util = require('util');
  16. exports.assertion = function(expected, msg) {
  17. this.message = msg || util.format('Testing if the URL contains "%s".', expected);
  18. this.expected = expected;
  19. this.pass = function(value) {
  20. return value.indexOf(this.expected) > -1;
  21. };
  22. this.value = function(result) {
  23. return result.value;
  24. };
  25. this.command = function(callback) {
  26. this.api.url(callback);
  27. return this;
  28. };
  29. };