title.js 810 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Checks if the page title equals the given value.
  3. *
  4. * ```
  5. * this.demoTest = function (client) {
  6. * browser.assert.title("Nightwatch.js");
  7. * };
  8. * ```
  9. *
  10. * @method title
  11. * @param {string} expected The expected page title.
  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 page title equals "%s".', expected);
  18. this.expected = expected;
  19. this.pass = function(value) {
  20. return value === this.expected;
  21. };
  22. this.value = function(result) {
  23. return result.value;
  24. };
  25. this.command = function(callback) {
  26. this.api.title(callback);
  27. return this;
  28. };
  29. };