From ade7086ff34e1fc7a99e3bffd1b3a654f979b69f Mon Sep 17 00:00:00 2001 From: Diana Barsan <35681649+dianabarsan@users.noreply.github.com> Date: Fri, 20 Oct 2023 19:47:02 +0300 Subject: [PATCH] chore: fix e2e tests post chrome update (#8654) (cherry picked from commit 9c472f7eb72f1fc3f17bb27387d4d502c89d47a1) --- .../enketo/unauthorized-form.wdio-spec.js | 8 +++--- tests/e2e/default/sms/gateway.wdio-spec.js | 1 + .../default/common/common.wdio.page.js | 26 ++++++++++++++----- .../default/users/user.wdio.page.js | 4 +-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/e2e/default/enketo/unauthorized-form.wdio-spec.js b/tests/e2e/default/enketo/unauthorized-form.wdio-spec.js index e55b23dc771..5543479021e 100644 --- a/tests/e2e/default/enketo/unauthorized-form.wdio-spec.js +++ b/tests/e2e/default/enketo/unauthorized-form.wdio-spec.js @@ -38,9 +38,7 @@ describe('Unauthorized form', () => { afterEach(async () => await utils.revertSettings(true)); it('should display unauthorized error message in reports tab when form expression does not match', async () => { - await commonPage.goToReports(); - - await browser.url('#/reports/add/pregnancy'); + await browser.url('/#/reports/add/pregnancy'); await commonPage.waitForPageLoaded(); expect(await genericFormPage.getErrorMessage()).to.equal(EXPECTED_UNAUTHORIZED_MESSAGE); @@ -50,7 +48,7 @@ describe('Unauthorized form', () => { await commonPage.goToPeople(); await updateSettings(customPlaceType); - await browser.url(`#/contacts/add/${customPlaceType.id}`); + await commonPage.goToUrl(`#/contacts/add/${customPlaceType.id}`); await commonPage.waitForPageLoaded(); expect(await genericFormPage.getErrorMessage()).to.equal(EXPECTED_UNAUTHORIZED_MESSAGE); @@ -60,7 +58,7 @@ describe('Unauthorized form', () => { await commonPage.goToPeople(); await updateSettings(customPlaceType, { can_create_clinic: [ 'chw' ] }); - await browser.url(`#/contacts/add/${customPlaceType.id}`); + await commonPage.goToUrl(`#/contacts/add/${customPlaceType.id}`); await commonPage.waitForPageLoaded(); expect(await genericFormPage.getFormTitle()).to.equal('contact.type.unauthorized-contact-form.new'); diff --git a/tests/e2e/default/sms/gateway.wdio-spec.js b/tests/e2e/default/sms/gateway.wdio-spec.js index b01fc10128f..b10196cf398 100644 --- a/tests/e2e/default/sms/gateway.wdio-spec.js +++ b/tests/e2e/default/sms/gateway.wdio-spec.js @@ -16,6 +16,7 @@ const pollSmsApi = body => { describe('sms-gateway api', () => { before(async () => { await loginPage.cookieLogin(); + await commonElements.waitForPageLoaded(); }); describe('- gateway submits new WT sms messages', () => { diff --git a/tests/page-objects/default/common/common.wdio.page.js b/tests/page-objects/default/common/common.wdio.page.js index 70b2b584903..9cc1086d490 100644 --- a/tests/page-objects/default/common/common.wdio.page.js +++ b/tests/page-objects/default/common/common.wdio.page.js @@ -1,4 +1,5 @@ const modalPage = require('./modal.wdio.page'); +const constants = require('@constants'); const hamburgerMenu = () => $('#header-dropdown-link'); const userSettingsMenuOption = () => $('[test-id="user-settings-menu-option"]'); @@ -183,47 +184,57 @@ const getLogoutMessage = async () => { return modal.body; }; +const goToUrl = async (url) => { + const currentUrl = await browser.getUrl(); + const desiredUrl = `${constants.BASE_URL}${url}`; + if (currentUrl === desiredUrl) { + await browser.refresh(); + } else { + await browser.url(url); + } +}; + const refresh = async () => { await browser.refresh(); await waitForPageLoaded(); }; const goToBase = async () => { - await browser.url('/'); + await goToUrl('/'); await waitForPageLoaded(); }; const goToReports = async () => { - await browser.url('/#/reports'); + await goToUrl('/#/reports'); await waitForPageLoaded(); }; const goToPeople = async (contactId = '', shouldLoad = true) => { - await browser.url(`/#/contacts/${contactId}`); + await goToUrl(`/#/contacts/${contactId}`); if (shouldLoad) { await waitForPageLoaded(); } }; const goToMessages = async () => { - await browser.url(`/#/messages`); + await goToUrl(`/#/messages`); await (await messagesTab()).waitForDisplayed(); }; const goToTasks = async () => { - await browser.url(`/#/tasks`); + await goToUrl(`/#/tasks`); await (await taskTab()).waitForDisplayed(); await waitForPageLoaded(); }; const goToAnalytics = async () => { - await browser.url(`/#/analytics`); + await goToUrl(`/#/analytics`); await (await analyticsTab()).waitForDisplayed(); await waitForPageLoaded(); }; const goToAboutPage = async () => { - await browser.url(`/#/about`); + await goToUrl(`/#/about`); await waitForLoaders(); }; @@ -449,4 +460,5 @@ module.exports = { closeReportBug, getAllButtonLabelsNames, loadNextInfiniteScrollPage, + goToUrl, }; diff --git a/tests/page-objects/default/users/user.wdio.page.js b/tests/page-objects/default/users/user.wdio.page.js index 0d4e2209c69..8cfcd765bc1 100644 --- a/tests/page-objects/default/users/user.wdio.page.js +++ b/tests/page-objects/default/users/user.wdio.page.js @@ -25,11 +25,11 @@ const failedUploadedUsers = () => $('p.text-danger'); const backToUserListButton = () => $('a#back-to-app-btn'); const goToAdminUser = async () => { - await browser.url('/admin/#/users'); + await commonElements.goToUrl('/admin/#/users'); }; const goToAdminUpgrade = async () => { - await browser.url('/admin/#/upgrade'); + await commonElements.goToUrl('/admin/#/upgrade'); }; const openAddUserDialog = async () => {