drupalLogin.js 870 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Logs into Drupal as the given user.
  3. *
  4. * @param {string} name
  5. * The user name.
  6. * @param {string} password
  7. * The user password.
  8. * @return {object}
  9. * The drupalUserIsLoggedIn command.
  10. */
  11. exports.command = function drupalLogin({ name, password }) {
  12. this.drupalUserIsLoggedIn(sessionExists => {
  13. // Log the current user out if necessary.
  14. if (sessionExists) {
  15. this.drupalLogout();
  16. }
  17. // Log in with the given credentials.
  18. this.drupalRelativeURL('/user/login')
  19. .setValue('input[name="name"]', name)
  20. .setValue('input[name="pass"]', password)
  21. .submitForm('#user-login-form');
  22. // Assert that a user is logged in.
  23. this.drupalUserIsLoggedIn(sessionExists => {
  24. this.assert.equal(
  25. sessionExists,
  26. true,
  27. `The user "${name}" was logged in.`,
  28. );
  29. });
  30. });
  31. return this;
  32. };