
| Current Path : /var/www/html/store1/web/core/tests/Drupal/Nightwatch/Commands/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/store1/web/core/tests/Drupal/Nightwatch/Commands/drupalLoginAsAdmin.js |
const { execSync } = require('child_process');
const { URL } = require('url');
const { commandAsWebserver } = require('../globals');
/**
* Logs in as the admin user.
*
* @param {function} callback
* A callback which will allow running commands as an administrator.
* @return {object}
* The drupalLoginAsAdmin command.
*/
exports.command = function drupalLoginAsAdmin(callback) {
const self = this;
this.drupalUserIsLoggedIn((sessionExists) => {
if (sessionExists) {
this.drupalLogout();
}
const userLink = execSync(
commandAsWebserver(
`php ./scripts/test-site.php user-login 1 --site-path ${this.globals.drupalSitePath}`,
),
);
this.drupalRelativeURL(userLink.toString());
this.drupalUserIsLoggedIn((sessionExists) => {
if (!sessionExists) {
throw new Error('Logging in as an admin user failed.');
}
});
});
if (typeof callback === 'function') {
callback.call(self);
}
this.drupalLogout({ silent: true });
return this;
};