Skip to content

Commit

Permalink
add retry logic to circumvent intermittent issue clicking on accept b…
Browse files Browse the repository at this point in the history
…utton
  • Loading branch information
stephan-thibodeau committed Oct 5, 2023
1 parent 4f27dae commit 9ac58ae
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
48 changes: 37 additions & 11 deletions packages/client/e2e/credit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, Page } from "@playwright/test"

import { test } from "./fixtures"
import { OPENFIN_PROJECT_NAME,Timeout } from "./utils"
import { OPENFIN_PROJECT_NAME, TestTimeout, Timeout } from "./utils"

test.describe("Credit", () => {
let newRfqPage: Page
Expand Down Expand Up @@ -49,6 +49,7 @@ test.describe("Credit", () => {
})

test.describe("New RFQ", () => {
test.setTimeout(TestTimeout.EXTENDED)
test("Create RFQ for GOOGL @smoke", async () => {
await newRfqPage.getByPlaceholder(/Enter a CUSIP/).click()
await newRfqPage
Expand Down Expand Up @@ -81,15 +82,41 @@ test.describe("Credit", () => {
.first()
.locator("div")
.first()
// Wait for first quote response
await expect(firstQuote).not.toContainText("Awaiting response", {
timeout: Timeout.LONG,
})

await firstQuote.hover()

await firstQuote.getByText(/Accept/).waitFor({state: "visible"})
await firstQuote.getByText(/Accept/).click()
// retry logic to circumvent intermittent failures at clicking on the accept button
const MAX_ATTEMPT = 2
let isAcceptBtnClicked = false

const acceptQuote = async () => {
try {
await firstQuote.hover()
await firstQuote
.getByText(/Accept/)
.click({ timeout: Timeout.AGGRESSIVE })
isAcceptBtnClicked = true
} catch (exception) {
console.warn(`Failed to click on the 'accept' button, retrying ...`)
console.warn(`Error: ${exception}`)
isAcceptBtnClicked = false
}
}

await expect(firstQuote)
.not.toContainText("Awaiting response", {
timeout: Timeout.LONG,
})
.then(async () => {
let attempt = 1
while (!isAcceptBtnClicked) {
expect(
attempt,
"Max attempts to click on accept button is reach",
).toBeLessThanOrEqual(MAX_ATTEMPT)
await acceptQuote()
attempt++
}
return
})

await rfqsPage.locator("li").getByText(/All/).nth(0).click()
const btnTxt = await rfqsPage
Expand Down Expand Up @@ -146,14 +173,13 @@ test.describe("Credit", () => {

await expect(rfqsPage.getByTestId("quotes").first()).toContainText(
"$100",
{ timeout: Timeout.NORMAL},
{ timeout: Timeout.NORMAL },
)
})
})

test.describe("Respond to RFQ with Pass", () => {
test("Passing a newly created RFQ ", async ({ context }) => {

await newRfqPage.getByPlaceholder(/Enter a CUSIP/).click()
await newRfqPage.getByTestId("search-result-item").nth(5).click()

Expand Down
4 changes: 4 additions & 0 deletions packages/client/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export enum Timeout {
NORMAL = 10000,
LONG = 20000,
}
export enum TestTimeout {
NORMAL = 30000,
EXTENDED = 60000
}

export const assertGridRow = async ({
row,
Expand Down
4 changes: 3 additions & 1 deletion packages/client/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { PlaywrightTestConfig } from "@playwright/test"
import { devices } from "@playwright/test"

import { TestTimeout } from "./e2e/utils"

const config: PlaywrightTestConfig = {
testDir: "./e2e",
/* Maximum time one test can run for. */
timeout: 60_000,
timeout: TestTimeout.NORMAL,
workers: 1,
projects: [
{
Expand Down

0 comments on commit 9ac58ae

Please sign in to comment.