Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update Market spec test to handle flacky test on Bitcoin search #8910

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/heavy-kings-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

Update Market spec test to handle flacky test on "Bitcoin" search
49 changes: 36 additions & 13 deletions apps/ledger-live-desktop/tests/specs/market/market.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "@playwright/test";
import { expect, Locator, Page } from "@playwright/test";
import { getEnv } from "@ledgerhq/live-env";
import test from "../../fixtures/common";
import { MarketPage } from "../../page/market.page";
Expand Down Expand Up @@ -37,23 +37,36 @@ test("Market", async ({ page }) => {
const layout = new Layout(page);
const liveAppWebview = new LiveAppWebview(page);

const maskItems = {
mask: [
function createBaseMask(page: Page) {
return [
page.getByTestId("market-small-graph"),
page.getByTestId("market-coin-price"),
page.getByTestId("market-cap"),
page.getByTestId("market-price-change"),
page.getByRole("row").filter({ hasText: new RegExp("^(?!.*(?:Bitcoin|Ethereum)).*$") }),
//Fix for Test App (external) workflow
// Fix for Test App (external) workflow
page.getByRole("row").nth(6),
page.getByRole("row").nth(7),
],
};
];
}

function createMaskExcluding(page: Page, excludedPatterns: string[]): Locator[] {
const baseMask = createBaseMask(page);
const exclusionRegex = new RegExp(`^(?!.*(?:${excludedPatterns.join("|")})).*$`);
return [...baseMask, page.getByRole("row").filter({ hasText: exclusionRegex })];
}

// Masks
const maskEverythingExceptBitcoinAndEthereum = {
mask: createMaskExcluding(page, ["Bitcoin", "Ethereum"]),
}; // Exclude all except Bitcoin and Ethereum
const maskEverythingExceptBitcoin = { mask: createMaskExcluding(page, ["Bitcoin"]) }; // Exclude all except Bitcoin

await test.step("go to market", async () => {
await layout.goToMarket();
await marketPage.waitForLoadingWithSwapbtn();
await expect.soft(page).toHaveScreenshot("market-page-no-scrollbar.png", maskItems);
await expect
.soft(page)
.toHaveScreenshot("market-page-no-scrollbar.png", maskEverythingExceptBitcoinAndEthereum);
});

await page.route(`${getEnv("LEDGER_COUNTERVALUES_API")}/v3/supported/fiat`, async route => {
Expand Down Expand Up @@ -128,31 +141,41 @@ test("Market", async ({ page }) => {
await test.step("change countervalue", async () => {
await marketPage.switchCountervalue("THB");
await marketPage.waitForLoadingWithSwapbtn();
await expect.soft(page).toHaveScreenshot("market-page-thb-countervalue.png", maskItems);
await expect
.soft(page)
.toHaveScreenshot("market-page-thb-countervalue.png", maskEverythingExceptBitcoinAndEthereum);
});

await test.step("change market range", async () => {
await marketPage.switchMarketRange("7d");
await marketPage.waitForLoadingWithSwapbtn();
await expect.soft(page).toHaveScreenshot("market-page-7d-range.png", maskItems);
await expect
.soft(page)
.toHaveScreenshot("market-page-7d-range.png", maskEverythingExceptBitcoinAndEthereum);
});

await test.step("star bitcoin", async () => {
await marketPage.starCoin("btc");
await expect.soft(page).toHaveScreenshot("market-page-btc-star.png", maskItems);
await expect
.soft(page)
.toHaveScreenshot("market-page-btc-star.png", maskEverythingExceptBitcoinAndEthereum);
});

await test.step("search bitcoin", async () => {
await marketPage.search("bitcoin");
await marketPage.waitForLoading();
await expect.soft(page).toHaveScreenshot("market-page-search-bitcoin.png", maskItems);
await expect
.soft(page)
.toHaveScreenshot("market-page-search-bitcoin.png", maskEverythingExceptBitcoin);
});

await test.step("filter starred", async () => {
await marketPage.toggleStarFilter();
await marketPage.waitForLoadingWithSwapbtn();
// await marketPage.waitForSearchBarToBeEmpty(); // windows was showing the search bar still containing text. This wait prevents that
await expect.soft(page).toHaveScreenshot("market-page-filter-starred.png", maskItems);
await expect
.soft(page)
.toHaveScreenshot("market-page-filter-starred.png", maskEverythingExceptBitcoinAndEthereum);
});

await test.step("swap available to bitcoin", async () => {
Expand Down
Loading