From 46a9dd352cef1e5bb23d814fd06680fd687291a1 Mon Sep 17 00:00:00 2001 From: Diana Date: Fri, 20 Oct 2023 14:34:27 +0300 Subject: [PATCH 1/3] refresh before navigation --- tests/e2e/default/sms/gateway.wdio-spec.js | 1 + tests/page-objects/default/common/common.wdio.page.js | 7 +++++++ tests/page-objects/default/users/user.wdio.page.js | 1 + 3 files changed, 9 insertions(+) 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..f11ea4c33fa 100644 --- a/tests/page-objects/default/common/common.wdio.page.js +++ b/tests/page-objects/default/common/common.wdio.page.js @@ -189,16 +189,19 @@ const refresh = async () => { }; const goToBase = async () => { + await browser.refresh(); await browser.url('/'); await waitForPageLoaded(); }; const goToReports = async () => { + await browser.refresh(); await browser.url('/#/reports'); await waitForPageLoaded(); }; const goToPeople = async (contactId = '', shouldLoad = true) => { + await browser.refresh(); await browser.url(`/#/contacts/${contactId}`); if (shouldLoad) { await waitForPageLoaded(); @@ -206,23 +209,27 @@ const goToPeople = async (contactId = '', shouldLoad = true) => { }; const goToMessages = async () => { + await browser.refresh(); await browser.url(`/#/messages`); await (await messagesTab()).waitForDisplayed(); }; const goToTasks = async () => { + await browser.refresh(); await browser.url(`/#/tasks`); await (await taskTab()).waitForDisplayed(); await waitForPageLoaded(); }; const goToAnalytics = async () => { + await browser.refresh(); await browser.url(`/#/analytics`); await (await analyticsTab()).waitForDisplayed(); await waitForPageLoaded(); }; const goToAboutPage = async () => { + await browser.refresh(); await browser.url(`/#/about`); await waitForLoaders(); }; diff --git a/tests/page-objects/default/users/user.wdio.page.js b/tests/page-objects/default/users/user.wdio.page.js index 0d4e2209c69..0782d6de108 100644 --- a/tests/page-objects/default/users/user.wdio.page.js +++ b/tests/page-objects/default/users/user.wdio.page.js @@ -25,6 +25,7 @@ const failedUploadedUsers = () => $('p.text-danger'); const backToUserListButton = () => $('a#back-to-app-btn'); const goToAdminUser = async () => { + await browser.refresh(); await browser.url('/admin/#/users'); }; From c1cca3ed11b700ef4a578999ed3cdd38bb8354df Mon Sep 17 00:00:00 2001 From: Diana Date: Fri, 20 Oct 2023 16:04:57 +0300 Subject: [PATCH 2/3] refresh before navigation --- .../enketo/unauthorized-form.wdio-spec.js | 8 ++--- .../default/common/common.wdio.page.js | 31 ++++++++++--------- .../default/users/user.wdio.page.js | 5 ++- 3 files changed, 22 insertions(+), 22 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/page-objects/default/common/common.wdio.page.js b/tests/page-objects/default/common/common.wdio.page.js index f11ea4c33fa..6cd9b540402 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,54 +184,55 @@ 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.url(url); + } +}; + const refresh = async () => { await browser.refresh(); await waitForPageLoaded(); }; const goToBase = async () => { - await browser.refresh(); - await browser.url('/'); + await goToUrl('/'); await waitForPageLoaded(); }; const goToReports = async () => { - await browser.refresh(); - await browser.url('/#/reports'); + await goToUrl('/#/reports'); await waitForPageLoaded(); }; const goToPeople = async (contactId = '', shouldLoad = true) => { - await browser.refresh(); - await browser.url(`/#/contacts/${contactId}`); + await goToUrl(`/#/contacts/${contactId}`); if (shouldLoad) { await waitForPageLoaded(); } }; const goToMessages = async () => { - await browser.refresh(); - await browser.url(`/#/messages`); + await goToUrl(`/#/messages`); await (await messagesTab()).waitForDisplayed(); }; const goToTasks = async () => { - await browser.refresh(); - await browser.url(`/#/tasks`); + await goToUrl(`/#/tasks`); await (await taskTab()).waitForDisplayed(); await waitForPageLoaded(); }; const goToAnalytics = async () => { - await browser.refresh(); - await browser.url(`/#/analytics`); + await goToUrl(`/#/analytics`); await (await analyticsTab()).waitForDisplayed(); await waitForPageLoaded(); }; const goToAboutPage = async () => { - await browser.refresh(); - await browser.url(`/#/about`); + await goToUrl(`/#/about`); await waitForLoaders(); }; @@ -456,4 +458,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 0782d6de108..8cfcd765bc1 100644 --- a/tests/page-objects/default/users/user.wdio.page.js +++ b/tests/page-objects/default/users/user.wdio.page.js @@ -25,12 +25,11 @@ const failedUploadedUsers = () => $('p.text-danger'); const backToUserListButton = () => $('a#back-to-app-btn'); const goToAdminUser = async () => { - await browser.refresh(); - 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 () => { From 6fbb6f87b62678a527b10c6ccaf952840127c1ff Mon Sep 17 00:00:00 2001 From: Diana Date: Fri, 20 Oct 2023 16:51:22 +0300 Subject: [PATCH 3/3] refresh before navigation --- tests/page-objects/default/common/common.wdio.page.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/page-objects/default/common/common.wdio.page.js b/tests/page-objects/default/common/common.wdio.page.js index 6cd9b540402..9cc1086d490 100644 --- a/tests/page-objects/default/common/common.wdio.page.js +++ b/tests/page-objects/default/common/common.wdio.page.js @@ -187,7 +187,9 @@ const getLogoutMessage = async () => { const goToUrl = async (url) => { const currentUrl = await browser.getUrl(); const desiredUrl = `${constants.BASE_URL}${url}`; - if (currentUrl !== desiredUrl) { + if (currentUrl === desiredUrl) { + await browser.refresh(); + } else { await browser.url(url); } };