Skip to content
Snippets Groups Projects
Commit 86d54d40 authored by ilyaukin's avatar ilyaukin
Browse files

Teardown for cypress

parent 6414748d
No related tags found
1 merge request!22Teardown for cypress
......@@ -21,6 +21,9 @@ import atkConfig from '../../../cypress.atk.config';
import qaUserAccounts from '../../data/qaUsers.json';
describe('Entity tests.', () => {
// Node IDs to clean up after the test run.
const ctx = { tmpNid: [] }
//
// Create a page with an image, confirm it, update it, confirm update then delete it via the UI.
//
......@@ -65,6 +68,7 @@ describe('Entity tests.', () => {
// Get the nid.
const nid = parseInt(match[1], 10);
ctx.tmpNid.push(nid);
// Update the node.
const nodeEditUrl = atkConfig.nodeEditUrl.replace('{nid}', nid);
......@@ -136,6 +140,7 @@ describe('Entity tests.', () => {
// Get the nid.
const nid = parseInt(match[1], 10);
ctx.tmpNid.push(nid);
// Update the node.
const nodeEditUrl = atkConfig.nodeEditUrl.replace('{nid}', nid);
......@@ -162,4 +167,10 @@ describe('Entity tests.', () => {
cy.deleteNodeViaUiWithNid(nid);
});
});
after(() => {
for (const nid of ctx.tmpNid) {
cy.deleteNodeWithNid(nid);
}
});
});
......@@ -21,6 +21,16 @@ import atkConfig from '../../../cypress.atk.config';
import qaUserAccounts from '../../data/qaUsers.json';
describe('User registration and login tasks.', () => {
const ctx = {
tmpUsers: [],
newUser() {
const user = atkUtilities.createRandomUser();
this.tmpUsers.push(user);
return user;
}
}
//
// Register the created user.
//
......@@ -28,7 +38,7 @@ describe('User registration and login tasks.', () => {
const testId = 'ATK-CY-1000'; // eslint-disable-line no-unused-vars
// Begin registration.
const user = atkUtilities.createRandomUser();
const user = ctx.newUser();
cy.visit(atkConfig.registerUrl).then(() => {
cy.get('#edit-mail').type(user.userEmail);
cy.get('#edit-name').type(user.userName);
......@@ -77,7 +87,7 @@ describe('User registration and login tasks.', () => {
it('(ATK-CY-1020) Create user with Drush, delete by email.', { tags: ['@ATK-CY-1020', '@register-login', '@smoke', 'alters-db'] }, () => {
const testId = 'ATK-CY-1020'; // eslint-disable-line no-unused-vars
const user = atkUtilities.createRandomUser();
const user = ctx.newUser();
cy.createUserWithUserObject(user, []);
cy.deleteUserWithEmail(user.userEmail, [], ['--delete-content']);
});
......@@ -88,7 +98,7 @@ describe('User registration and login tasks.', () => {
it('(ATK-CY-1021) Create user with Drush, delete by UID.', { tags: ['@ATK-CY-1021', '@register-login', '@smoke', 'alters-db'] }, () => {
const testId = 'ATK-CY-1021'; // eslint-disable-line no-unused-vars
const user = atkUtilities.createRandomUser();
const user = ctx.newUser();
cy.createUserWithUserObject(user, []);
cy.getUidWithEmail(user.userEmail).then((uid) => {
cy.deleteUserWithUid(uid, [], ['--delete-content']);
......@@ -101,7 +111,7 @@ describe('User registration and login tasks.', () => {
it('(ATK-CY-1030) Reset password.', { tags: ['@ATK-CY-1030', '@register-login', '@smoke'] }, () => {
const testId = 'ATK-CY-1030'; // eslint-disable-line no-unused-vars
const user = atkUtilities.createRandomUser();
const user = ctx.newUser();
cy.createUserWithUserObject(user, []);
......@@ -119,4 +129,10 @@ describe('User registration and login tasks.', () => {
cy.deleteUserWithEmail(user.userEmail, [], ['--delete-content']);
});
after(() => {
for (const user of ctx.tmpUsers) {
cy.deleteUserWithUserName(user.userName);
}
});
});
......@@ -57,12 +57,12 @@ Cypress.Commands.add('createUserWithUserObject', (user, roles = [], args = [], o
// Attempt to add the roles.
// Role(s) may come from the user object or the function arguments.
if (user.hasOwnProperty('userRoles')) {
user.userRoles.forEach(function (role) {
user.userRoles.forEach((role) => {
roles.push(role)
})
}
roles.forEach(function (role) {
roles.forEach((role) => {
cmd = `user:role:add '${role}' '${user.userName}'`
cy.execDrush(cmd)
cy.log(`${role}: If role exists, role assigned to the user ${user.userName}`)
......@@ -89,6 +89,15 @@ Cypress.Commands.add('deleteNodeViaUiWithNid', (nid) => {
cy.get('.messages--status').invoke('text').should('include', 'has been deleted.')
})
/**
* Delete nod via Drush with nid.
*
* @param {number} nid Node ID of item to be deleted.
*/
Cypress.Commands.add('deleteNodeWithNid', (nid) => {
cy.execDrush(`entity:delete node ${nid}`)
})
/**
* Delete user via Drush given an account email.
*
......@@ -235,7 +244,7 @@ Cypress.Commands.add('execPantheonDrush', (cmd) => {
* @return {Cypress.Chainable<HTMLElement>} input.
*/
Cypress.Commands.add('getByLabel', (label) => {
//cy.log('**getByLabel**')
// cy.log('**getByLabel**')
cy.contains('label', label)
.invoke('attr', 'for')
.then((id) => {
......@@ -268,14 +277,13 @@ function getDrushAlias() {
* Get the iframe > document > body
* and retry until the body element is not empty
*/
Cypress.Commands.add('getIframeBodyWithId', () =>
cy.get('iframe[id=mvActiveArea]')
.its('0.contentDocument.body')
.should('not.be.empty')
// Wraps “body” DOM element to allow
// chaining more Cypress commands, like “.find(...)”
// https://on.cypress.io/wrap
.then(cy.wrap, { log: false }))
Cypress.Commands.add('getIframeBodyWithId', () => cy.get('iframe[id=mvActiveArea]')
.its('0.contentDocument.body')
.should('not.be.empty')
// Wraps “body” DOM element to allow
// chaining more Cypress commands, like “.find(...)”
// https://on.cypress.io/wrap
.then(cy.wrap, { log: false }))
/**
* Return the UID of a user given an email.
......@@ -368,7 +376,7 @@ Cypress.Commands.add('logInViaForm', (account) => {
// Optional.
// should('include.text', 'user')
},
}
},
)
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment