Skip to content
Snippets Groups Projects

Add new functions to atk_commands.js and update for D7.

1 file
+ 67
0
Compare changes
  • Side-by-side
  • Inline
@@ -20,6 +20,8 @@ import atkConfig from '../../playwright.atk.config.js'
import etherealUser from '../data/etherealUser.json';
module.exports = {
addRolePerm,
checkEmail,
createUserWithUserObject,
deleteNodeViaUiWithNid,
deleteUserWithEmail,
@@ -27,6 +29,7 @@ module.exports = {
deleteUserWithUserName,
execDrush,
execPantheonDrush,
expectMessage,
getDrushAlias,
getUidWithEmail,
getUsernameWithEmail,
@@ -42,6 +45,55 @@ module.exports = {
const baseUrl = playwrightConfig.use.baseURL;
/**
* Add specified permission to the role.
*
* @param role {string}
* @param perm {string}
*/
function addRolePerm(role, perm) {
const cmd = `role-add-perm '${role}' '${perm}'`;
execDrush(cmd);
}
/**
* Verify that email at Ethereal.email is sent to the given recipient with expected subject.
*
* @param page Playwright page object.
* @param userEmail Email address of the recipient. If null, only subject is verified.
* @param subjectValue Expected subject.
* @return {Promise<void>}
*/
async function checkEmail(page, userEmail, subjectValue) {
const etherealUrl = 'https://ethereal.email';
await page.goto(`${etherealUrl}/login`);
await page.getByPlaceholder('Enter email').fill(etherealUser.userEmail);
await page.getByPlaceholder('Password').fill(etherealUser.userPassword);
await page.getByRole('button', { name: 'Log in' }).click();
let textContent;
textContent = await page.textContent('body');
expect(textContent).toContain(`Logged in as ${etherealUser.userEmail}`);
await page.goto(`${etherealUrl}/messages`);
textContent = await page.textContent('body');
expect(textContent).toContain(`Messages for ${etherealUser.userEmail}`);
let expectedValue;
// There may be two emails, one for the user and one for the admin.
// Look for email in the first column and the username + userCode generated above
// in the second column; that's the user email.
if (!userEmail) {
expectedValue = subjectValue;
} else {
const toValue = `To: <${userEmail}>`;
expectedValue = `${toValue} ${subjectValue}`;
}
await expect(page.getByRole('row', { name: expectedValue })).toBeVisible();
}
/**
* Create a user via Drush using a JSON user object.
* See qaUsers.json for the definition.
@@ -240,6 +292,21 @@ function execPantheonDrush(cmd) {
return result
}
/**
* Assert presence of a message with given text on the page.
*
* @param page Playwright page object.
* @param text Text that the message box should partially match.
* @return {Promise<void>}
*/
async function expectMessage(page, text) {
// The status box needs a moment to appear.
const message = await page.waitForSelector('.messages.status');
// Should see the thank-you message.
expect(await message.textContent()).toContain(text);
}
/**
* Returns Drush alias per environment.
* Adapt this to the mechanism that communicates to the remote server.
Loading