Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sitespeed.io preScript for logging in using username+password before running tests.
module.exports = {
run(context) {
return context.runWithDriver((driver) => {
return driver.get(context.options.loginUrl)
.then(() => {
const webdriver = context.webdriver;
const until = webdriver.until;
const By = webdriver.By;
const userName = context.options.username || 'admin';
const password = context.options.password || 'password';
driver.findElement(By.css(context.options.usernameFieldCSS || 'input[name="username"]')).sendKeys(userName);
driver.findElement(By.css(context.options.passwordFieldCSS || 'input[name="password"][type="password"]')).sendKeys(password);
const loginButton = driver.findElement(By.css(context.options.loginButtonCSS || '[type="submit"]')).click();
return driver.wait(until.elementLocated(By.css(context.options.postLoginSelectors)), 10000);
});
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.