X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FNightwatch%2FCommands%2FdrupalLogin.js;fp=web%2Fcore%2Ftests%2FDrupal%2FNightwatch%2FCommands%2FdrupalLogin.js;h=5fccdfc4aeea624571865cb29cdfd552edefb5df;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js b/web/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js new file mode 100644 index 000000000..5fccdfc4a --- /dev/null +++ b/web/core/tests/Drupal/Nightwatch/Commands/drupalLogin.js @@ -0,0 +1,33 @@ +/** + * Logs into Drupal as the given user. + * + * @param {string} name + * The user name. + * @param {string} password + * The user password. + * @return {object} + * The drupalUserIsLoggedIn command. + */ +exports.command = function drupalLogin({ name, password }) { + this.drupalUserIsLoggedIn(sessionExists => { + // Log the current user out if necessary. + if (sessionExists) { + this.drupalLogout(); + } + // Log in with the given credentials. + this.drupalRelativeURL('/user/login') + .setValue('input[name="name"]', name) + .setValue('input[name="pass"]', password) + .submitForm('#user-login-form'); + // Assert that a user is logged in. + this.drupalUserIsLoggedIn(sessionExists => { + this.assert.equal( + sessionExists, + true, + `The user "${name}" was logged in.`, + ); + }); + }); + + return this; +};