Skip to content

Commit

Permalink
chore: Fix flaky tests (#8670)
Browse files Browse the repository at this point in the history
This commit fixes some flaky tests:
* test add-user.wdio-spec.js
* test training-cards.wdio-spec.js
* test edit-report-with-attachment.wdio-spec.js
* test reports-subject.wdio-spec.js
  • Loading branch information
tatilepizs authored Oct 27, 2023
1 parent 07bcd95 commit 0cc78cc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
12 changes: 2 additions & 10 deletions tests/e2e/default/enketo/edit-report-with-attachment.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const loginPage = require('@page-objects/default/login/login.wdio.page');
const utils = require('@utils');
const userData = require('@page-objects/default/users/user.data');
const fs = require('fs');
const commonElements = require('@page-objects/default/common/common.wdio.page');
const oneTextForm = fs.readFileSync(`${__dirname}/forms/one-text-form.xml`, 'utf8');

const instanceID = uuid();
Expand Down Expand Up @@ -65,14 +64,11 @@ describe('Edit report with attachmnet', () => {
await utils.seedTestData(userContactDoc, [...docs, formDoc]);
await loginPage.cookieLogin();
await common.hideSnackbar();
});

it('should remove attachment when saving', async () => {
reportDoc._id = uuid();
await utils.saveDoc(reportDoc);
});

await commonElements.goToReports();

it('should remove attachment when saving', async () => {
await reportsPage.editReport(reportDoc._id);
await reportsPage.submitForm();

Expand All @@ -89,10 +85,6 @@ describe('Edit report with attachmnet', () => {
});

it('should save edits', async () => {
reportDoc._id = uuid();
await utils.saveDoc(reportDoc);

await commonElements.goToReports();
await reportsPage.editReport(reportDoc._id);
await (await genericForm.fieldByName(formDoc.internalId, 'intro')).setValue('updated text');
await reportsPage.submitForm();
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/default/enketo/training-cards.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe('Training Cards', () => {
});

it('should cancel training and not save it as completed', async () => {
await commonPage.goToMessages();
await trainingCardsPage.waitForTrainingCards();

const confirmMessage = await trainingCardsPage.quitTraining();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/reports/reports-subject.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Reports Subject', () => {
subject = person.name,
lineage = `${clinic.name}${healthCenter.name}${districtHospital.name}`
}) => {
await commonPage.refresh();
await commonPage.goToPeople();
await commonPage.goToReports();
const firstReport = await reportsPage.firstReport();
await reportsPage.openSelectedReport(firstReport);
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/default/users/add-user.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ describe('User Test Cases ->', () => {
});

beforeEach(async () => {
if (await usersAdminPage.addUserDialog().isDisplayed()) {
await usersAdminPage.closeAddUserDialog();
}
await usersAdminPage.goToAdminUser();
await usersAdminPage.openAddUserDialog();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/page-objects/default/reports/reports.wdio.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ const resetFilter = async () => {
const openReport = async (reportId) => {
await (await firstReport()).waitForDisplayed();
const reportListItem = await reportByUUID(reportId);
await reportListItem.waitForDisplayed();
await reportListItem.waitForClickable();
await reportListItem.click();
await reportBodyDetails().waitForDisplayed();
};
Expand Down
25 changes: 18 additions & 7 deletions tests/page-objects/default/users/user.wdio.page.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const _ = require('lodash');
const commonElements = require('../common/common.wdio.page');
const addUserButton = () => $('a#add-user');
const cancelButton = () => $('a[test-id="modal-cancel-btn"]');
const addUserDialog = () => $('div#edit-user-profile');
const userName = () => $('#edit-username');
const userFullName = () => $('#fullname');
const userPassword = () => $('#edit-password');
const userConfirmPassword = () => $('#edit-password-confirm');
const saveUserButton = () => $('//a[@test-id="modal-submit-btn"]');
const saveUserButton = () => $('a[test-id="modal-submit-btn"]');
const logoutButton = () => $('i.fa-power-off');
const usernameTextSelector = '[test-id="username-list"]';
const usernameText = () => $(usernameTextSelector);
Expand Down Expand Up @@ -48,8 +49,8 @@ const scrollToBottomOfModal = async () => {
};

const inputAddUserFields = async (username, fullname, role, place, contact, password, confirmPassword = password) => {
await (await userName()).addValue(username);
await (await userFullName()).addValue(fullname);
await (await userName()).setValue(username);
await (await userFullName()).setValue(fullname);
await (await $(`#role-select input[value="${role}"]`)).click();

// we need to scroll to the bottom to bring the select2 elements into view
Expand All @@ -64,8 +65,8 @@ const inputAddUserFields = async (username, fullname, role, place, contact, pass
await selectContact(contact);
}

await (await userPassword()).addValue(password);
await (await userConfirmPassword()).addValue(confirmPassword);
await (await userPassword()).setValue(password);
await (await userConfirmPassword()).setValue(confirmPassword);
};

const inputUploadUsersFields = async (filePath) => {
Expand Down Expand Up @@ -96,7 +97,7 @@ const selectContact = async (associatedContact) => {
};

const saveUser = async (isSuccessExpected = true) => {
await (await saveUserButton()).waitForDisplayed();
await (await saveUserButton()).waitForClickable();
await (await saveUserButton()).click();
if (isSuccessExpected) {
await (await addUserDialog()).waitForDisplayed({ reverse: true });
Expand All @@ -123,6 +124,7 @@ const getUsernameErrorText = async () => {
};

const getPasswordErrorText = async () => {
await (await passwordErrorMessage()).waitForDisplayed();
return await (await passwordErrorMessage()).getText();
};

Expand Down Expand Up @@ -163,7 +165,15 @@ const waitForUploadSummary = async () => {
await (await uploadSummaryDialog()).waitForDisplayed();
};

const closeAddUserDialog = async () => {
await (await cancelButton()).waitForClickable();
await (await cancelButton()).click();
await (await addUserDialog()).waitForDisplayed({ reverse: true });
};


module.exports = {
addUserDialog,
goToAdminUser,
goToAdminUpgrade,
openAddUserDialog,
Expand All @@ -182,5 +192,6 @@ module.exports = {
getSuccessfulyUploadedUsers,
getPreviouslyUploadedUsers,
getFailedUploadedUsers,
backToUserList
backToUserList,
closeAddUserDialog,
};

0 comments on commit 0cc78cc

Please sign in to comment.