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

test: use playwright text locator waitFor in live app smoke tests #8062

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions apps/ledger-live-desktop/tests/models/LiveAppWebview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Locator, Page } from "@playwright/test";
import { WebviewTag } from "~/renderer/components/Web3AppWebview/types";
import { waitFor } from "../utils/waitFor";

import { getLiveAppManifest, startDummyServer, stopDummyServer } from "@ledgerhq/test-utils";
import { AppManifest } from "@ledgerhq/live-common/wallet-api/types";

Expand Down Expand Up @@ -106,11 +106,11 @@ export class LiveAppWebview {
}

async waitForCorrectTextInWebview(textToCheck: string) {
return waitFor(() => this.textIsPresent(textToCheck));
return this.page.getByText(textToCheck);
}

async waitForLoaded() {
return this.page.waitForLoadState("domcontentloaded");
return this.page.waitForLoadState("load");
}

async textIsPresent(textToCheck: string) {
Expand Down
16 changes: 8 additions & 8 deletions apps/ledger-live-desktop/tests/specs/market/market.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@
await expect
.soft(page)
.toHaveScreenshot("market-btc-buy-page.png", { mask: [page.locator("webview")] });
await expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();

Check failure on line 167 in apps/ledger-live-desktop/tests/specs/market/market.spec.ts

View workflow job for this annotation

GitHub Actions / Test Desktop / Desktop Tests E2E (Ubuntu)

[mocked_tests] › specs/market/market.spec.ts:34:5 › Market

1) [mocked_tests] › specs/market/market.spec.ts:34:5 › Market › buy bitcoin from market page ───── Error: Timed out 41000ms waiting for expect(locator).toBeVisible() Locator: getByText('theme: dark') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 41000ms - waiting for getByText('theme: dark') 165 | .soft(page) 166 | .toHaveScreenshot("market-btc-buy-page.png", { mask: [page.locator("webview")] }); > 167 | await expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible(); | ^ 168 | await expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBeVisible(); 169 | await expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBeVisible(); 170 | await expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible(); at /home/runner/_work/ledger-live/ledger-live/apps/ledger-live-desktop/tests/specs/market/market.spec.ts:167:83 at /home/runner/_work/ledger-live/ledger-live/apps/ledger-live-desktop/tests/specs/market/market.spec.ts:162:3
await expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBeVisible();
await expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBeVisible();
await expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();

await layout.goToMarket();
});
Expand All @@ -188,9 +188,9 @@
await expect
.soft(page)
.toHaveScreenshot("market-btc-buy-page.png", { mask: [page.locator("webview")] });
await expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
await expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();
await expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBeVisible();
await expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBeVisible();
await expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();
});
});
68 changes: 34 additions & 34 deletions apps/ledger-live-desktop/tests/specs/services/buy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
await test.step("Navigate to Buy app from portfolio banner", async () => {
await portfolioPage.startBuyFlow();
await liveAppWebview.waitForLoaded();
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();

Check failure on line 60 in apps/ledger-live-desktop/tests/specs/services/buy.spec.ts

View workflow job for this annotation

GitHub Actions / Test Desktop / Desktop Tests E2E (Ubuntu)

[mocked_tests] › specs/services/buy.spec.ts:42:5 › Buy / Sell @smoke

2) [mocked_tests] › specs/services/buy.spec.ts:42:5 › Buy / Sell @smoke ────────────────────────── Error: expect(locator).toBeVisible() Locator: getByText('theme: dark') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 41000ms - waiting for getByText('theme: dark') 58 | await portfolioPage.startBuyFlow(); 59 | await liveAppWebview.waitForLoaded(); > 60 | expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible(); | ^ 61 | expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible(); 62 | expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible(); 63 | expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible(); at /home/runner/_work/ledger-live/ledger-live/apps/ledger-live-desktop/tests/specs/services/buy.spec.ts:60:77 at /home/runner/_work/ledger-live/ledger-live/apps/ledger-live-desktop/tests/specs/services/buy.spec.ts:57:3
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible();
await expect
.soft(page)
.toHaveScreenshot("buy-app-opened.png", { mask: [page.locator("webview")] });
Expand All @@ -69,61 +69,61 @@
await test.step("Navigate to Buy app from market", async () => {
await layout.goToMarket();
await marketPage.openBuyPage("usdt");
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();
expect(
await liveAppWebview.waitForCorrectTextInWebview(
"currency: ethereum/erc20/usd_tether__erc20_",
),
).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible();
});

await test.step("Navigate to Buy app from asset", async () => {
await layout.goToPortfolio();
await portfolioPage.navigateToAsset("ethereum");
await assetPage.startBuyFlow();

expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currency: ethereum")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currency: ethereum")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBeVisible();
});

await test.step("Navigate to Buy app from account", async () => {
await layout.goToAccounts();
await accountsPage.navigateToAccountByName("Bitcoin 1 (legacy)");
await accountPage.navigateToBuy();

expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBeVisible();
expect(
await liveAppWebview.waitForCorrectTextInWebview("account: mock:1:bitcoin:true_bitcoin_0:"),
).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBeVisible();
});

await test.step("Navigate to Buy app from account", async () => {
await layout.goToAccounts();
await accountsPage.navigateToAccountByName("Bitcoin 1 (legacy)");
await accountPage.navigateToSell();

expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currency: bitcoin")).toBeVisible();
expect(
await liveAppWebview.waitForCorrectTextInWebview("account: mock:1:bitcoin:true_bitcoin_0:"),
).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: sell")).toBe(true);
).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: sell")).toBeVisible();
});

await test.step("Navigate to Buy app from sidebar with light theme and French Language", async () => {
Expand All @@ -132,9 +132,9 @@
await settingsPage.changeTheme();
await layout.goToBuyCrypto();

expect(await liveAppWebview.waitForCorrectTextInWebview("theme: light")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: fr")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: light")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: fr")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible();
});
});
14 changes: 8 additions & 6 deletions apps/ledger-live-desktop/tests/specs/services/earn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
const layout = new Layout(page);
const liveAppWebview = new LiveAppWebview(page);

await test.step("Navigate to Buy app from portfolio banner", async () => {
await test.step("Navigate to Earn app from main side drawer navigation", async () => {
await layout.goToEarn();
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("discreetMode: false")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
await liveAppWebview.waitForLoaded();

expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible();

Check failure on line 46 in apps/ledger-live-desktop/tests/specs/services/earn.spec.ts

View workflow job for this annotation

GitHub Actions / Test Desktop / Desktop Tests E2E (Ubuntu)

[mocked_tests] › specs/services/earn.spec.ts:33:5 › Earn @smoke

3) [mocked_tests] › specs/services/earn.spec.ts:33:5 › Earn @smoke ─────────────────────────────── Error: expect(locator).toBeVisible() Locator: getByText('theme: dark') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 41000ms - waiting for getByText('theme: dark') 44 | await liveAppWebview.waitForLoaded(); 45 | > 46 | expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBeVisible(); | ^ 47 | expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible(); 48 | expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible(); 49 | expect(await liveAppWebview.waitForCorrectTextInWebview("discreetMode: false")).toBeVisible(); at /home/runner/_work/ledger-live/ledger-live/apps/ledger-live-desktop/tests/specs/services/earn.spec.ts:46:77 at /home/runner/_work/ledger-live/ledger-live/apps/ledger-live-desktop/tests/specs/services/earn.spec.ts:42:3
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("discreetMode: false")).toBeVisible();
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBeVisible();
await expect
.soft(page)
.toHaveScreenshot("earn-app-opened.png", { mask: [page.locator("webview")] });
Expand Down
6 changes: 3 additions & 3 deletions apps/ledger-live-desktop/tests/specs/services/swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@
await swapPage.navigateToExchangeDetails();
await swapPage.waitForExchangeDetails();
await expect.soft(swapPage.detailsSwapId).toHaveText("12345");
await expect.soft(drawer.swapAmountFrom).toContainText("-1.280"); // regex /-1.280\d+ BTC/ not working with toHaveText() and value can change after the first 3 decimals so this will have to do for now - see LIVE-8642
await expect.soft(drawer.swapAmountTo).toContainText("+17.8943438531 ETH");
await expect.soft(drawer.swapAmountFrom).toContainText(/^-1.280/); // regex value can change after the first 3 decimals so this will have to do for now - see LIVE-8642
await expect.soft(drawer.swapAmountTo).toContainText(/^\+17[.,]+8943438531 ETH$/); // match +17,8943438531 ETH or +17.8943438531 ETH

Check failure on line 207 in apps/ledger-live-desktop/tests/specs/services/swap.spec.ts

View workflow job for this annotation

GitHub Actions / Test Desktop / Desktop Tests E2E (Ubuntu)

[mocked_tests] › specs/services/swap.spec.ts:108:7 › Swap › Full Swap with Centralised Exchange @smoke

4) [mocked_tests] › specs/services/swap.spec.ts:108:7 › Swap › Full Swap with Centralised Exchange @smoke › Verify Swap details are present in the exchange drawer Error: Timed out 41000ms waiting for expect(locator).toContainText(expected) Locator: getByTestId('swap-amount-to').first() Expected pattern: /^\+17[.,]+8943438531 ETH$/ Received string: "+17.8943438531 ETH" Call log: - expect.soft.toContainText with timeout 41000ms - waiting for getByTestId('swap-amount-to').first() - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-size="6" color="#8b80db" data-testid="swap-amount-to" class="sc-aXZVg sc-bVHCgj ebBOjU cSoJFC">+17.8943438531 ETH</div> - unexpected value "+17.8943438531 ETH" - locator resolved to <div font-s
await expect.soft(drawer.swapAccountFrom).toHaveText("Bitcoin 2 (legacy)");
await expect.soft(drawer.swapAccountTo).toHaveText("Ethereum 2");

// Flaky due to LIVE-8642 - the formatting is sometimes different values - therefore we are doing the above text checks
// Screenshot verification is flaky due to LIVE-8642 - the formatting is sometimes rounding to different values - therefore we are doing the above text checks (this seems to relate to locale formatting)
// await expect.soft(drawer.content).toHaveScreenshot("verify-swap-details.png");
});

Expand Down
Loading