From 7b017cc218c01e7950266b7a32b686894eb3279b Mon Sep 17 00:00:00 2001 From: Alex Humphries Date: Mon, 10 Mar 2025 15:43:21 -0400 Subject: [PATCH 1/3] Overhaul validation logic Now, rather than retrying until we get a correct URL or a timeout, we check once, then, if the URL is wrong, we wait for a URL change and check again. (Unless, the current page is a bailout, in which case we know that the page isn't going to change) --- playwright-tests/pages/BasePage.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/playwright-tests/pages/BasePage.ts b/playwright-tests/pages/BasePage.ts index e538ee34..d2d03356 100644 --- a/playwright-tests/pages/BasePage.ts +++ b/playwright-tests/pages/BasePage.ts @@ -116,12 +116,22 @@ export class BasePage { } async validateURL(issPageValue: string) { + let pass = false; + let currentUrl = this.page.url(); + pass = currentUrl.includes(issPageValue); + const isBailout = currentUrl.includes('bailout-page'); + if(!pass && !isBailout) { + await this.waitForURLToChange(currentUrl); + currentUrl = this.page.url(); + pass = currentUrl.includes(issPageValue); + } + expect(pass).toBeTruthy(); + } + + async waitForURLToChange(startingUrl: string) { await expect(async () => { const currentUrl = this.page.url(); - expect(currentUrl).toContain(issPageValue); - }).toPass({ - intervals: [1_000], - timeout: 15_000 - }); + expect(currentUrl).not.toEqual(startingUrl); + }).toPass({ timeout: 180_000 }); } } \ No newline at end of file From f417b331f605f3d5b18e3b36e97bda885a48f519 Mon Sep 17 00:00:00 2001 From: Alex Humphries Date: Mon, 10 Mar 2025 16:21:46 -0400 Subject: [PATCH 2/3] Re-add some logging --- playwright-tests/pages/BasePage.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/playwright-tests/pages/BasePage.ts b/playwright-tests/pages/BasePage.ts index d2d03356..a40bad06 100644 --- a/playwright-tests/pages/BasePage.ts +++ b/playwright-tests/pages/BasePage.ts @@ -116,13 +116,17 @@ export class BasePage { } async validateURL(issPageValue: string) { + console.log(`Checking for page value: ${issPageValue}`); let pass = false; let currentUrl = this.page.url(); + console.log(`Current URL: ${currentUrl}`); pass = currentUrl.includes(issPageValue); const isBailout = currentUrl.includes('bailout-page'); if(!pass && !isBailout) { + console.log('Waiting for URL to change'); await this.waitForURLToChange(currentUrl); - currentUrl = this.page.url(); + currentUrl = this.page.url(); + console.log(`New URL: ${currentUrl}`); pass = currentUrl.includes(issPageValue); } expect(pass).toBeTruthy(); From 4059bd4a881c675f97f486b3c8347c9e59dec68c Mon Sep 17 00:00:00 2001 From: Alex Humphries Date: Tue, 11 Mar 2025 10:29:12 -0400 Subject: [PATCH 3/3] Add special validation for order confirmation --- playwright-tests/pages/BasePage.ts | 9 ++++---- .../pages/OrderConfirmationPage.ts | 22 +++++++++++++++++++ playwright-tests/tests/0000__M.test.ts | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/playwright-tests/pages/BasePage.ts b/playwright-tests/pages/BasePage.ts index a40bad06..0b853baa 100644 --- a/playwright-tests/pages/BasePage.ts +++ b/playwright-tests/pages/BasePage.ts @@ -126,16 +126,15 @@ export class BasePage { console.log('Waiting for URL to change'); await this.waitForURLToChange(currentUrl); currentUrl = this.page.url(); - console.log(`New URL: ${currentUrl}`); - pass = currentUrl.includes(issPageValue); + console.log(`New URL: ${currentUrl}`); } - expect(pass).toBeTruthy(); + expect(currentUrl).toContain(issPageValue); } async waitForURLToChange(startingUrl: string) { await expect(async () => { const currentUrl = this.page.url(); - expect(currentUrl).not.toEqual(startingUrl); - }).toPass({ timeout: 180_000 }); + expect(currentUrl).not.toEqual(startingUrl); + }).toPass({ timeout: 180_000 }); } } \ No newline at end of file diff --git a/playwright-tests/pages/OrderConfirmationPage.ts b/playwright-tests/pages/OrderConfirmationPage.ts index 2a4d6104..c0005cdb 100644 --- a/playwright-tests/pages/OrderConfirmationPage.ts +++ b/playwright-tests/pages/OrderConfirmationPage.ts @@ -112,4 +112,26 @@ export class OrderConfirmationPage extends BasePage { console.log(`SessionStorage Work Order Number:${workOrderNumber}`); }); } + + async validateURL() { + console.log("Order confirmation validation override") + console.log(`Checking for page value: ${this.issPageValue}`); + let pass = false; + let currentUrl = this.page.url(); + console.log(`Current URL: ${currentUrl}`); + pass = currentUrl.includes(this.issPageValue); + while(!pass && currentUrl.includes('payment')) { + await this.waitForURLToChange(currentUrl); + currentUrl = this.page.url(); + pass = currentUrl.includes(this.issPageValue); + } + const isBailout = currentUrl.includes('bailout-page'); + if(!pass && !isBailout) { + console.log('Waiting for URL to change'); + await this.waitForURLToChange(currentUrl); + currentUrl = this.page.url(); + console.log(`New URL: ${currentUrl}`); + } + expect(currentUrl).toContain(this.issPageValue); + } } \ No newline at end of file diff --git a/playwright-tests/tests/0000__M.test.ts b/playwright-tests/tests/0000__M.test.ts index 5499792d..c1f76764 100644 --- a/playwright-tests/tests/0000__M.test.ts +++ b/playwright-tests/tests/0000__M.test.ts @@ -735,7 +735,7 @@ async function runWorkflow(page: Page, testCase: TestCase) { } await test.step('OrderConfirmationPage >> Validate order', async () => { - await orderConfirmationPage.validateURL(orderConfirmationPage.issPageValue); + await orderConfirmationPage.validateURL(); await orderConfirmationPage.validateOrderConfirmationPage(testCase.testData); }); }