5fccdfc4aeea624571865cb29cdfd552edefb5df
[yaffs-website] / web / core / tests / Drupal / Nightwatch / Commands / drupalLogin.js
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
32   return this;
33 };