Skip to content

Commit

Permalink
test: fix for webview check
Browse files Browse the repository at this point in the history
  • Loading branch information
abdurrahman-ledger committed Dec 11, 2024
1 parent daf397f commit d7abb17
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
12 changes: 11 additions & 1 deletion apps/ledger-live-mobile/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { by, element, waitFor, device } from "detox";
import { by, element, waitFor, device, web } from "detox";
import { Direction } from "detox/detox";
import { findFreePort, close as closeBridge, init as initBridge } from "./bridge/server";

Expand Down Expand Up @@ -52,6 +52,16 @@ export function getElementByText(text: string | RegExp, index = 0) {
return element(by.text(text)).atIndex(index);
}

export function getWebElementById(id: string, index = 0) {
if (!isAndroid()) sync_delay(200); // Issue with RN75 : QAA-370
return web.element(by.web.id(id)).atIndex(index);
}

export function getWebElementByTag(tag: string, index = 0) {
if (!isAndroid()) sync_delay(200); // Issue with RN75 : QAA-370
return web.element(by.web.tag(tag)).atIndex(index);
}

export async function tapById(id: string | RegExp, index = 0) {
return getElementById(id, index).tap();
}
Expand Down
4 changes: 2 additions & 2 deletions apps/ledger-live-mobile/e2e/models/liveApps.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { randomUUID } from "crypto";
import { web, by } from "detox";
import { e2eBridgeServer } from "../bridge/server";
import { first, filter, map } from "rxjs/operators";
import { startDummyServer, stopDummyServer as stopDummyServer } from "@ledgerhq/test-utils";
import { firstValueFrom } from "rxjs";
import { getWebElementById } from "../helpers";

export async function startLiveApp(liveAppDirectory: string, liveAppPort = 3000) {
try {
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function stopServer() {
}

export async function send(params: Record<string, unknown>) {
const webview = web.element(by.web.id("root"));
const webview = getWebElementById("root");
const id = randomUUID();
const json = JSON.stringify({
id,
Expand Down
5 changes: 2 additions & 3 deletions apps/ledger-live-mobile/e2e/page/discover/buyDevice.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { web, by } from "detox";
import { getElementById, isAndroid, tapByElement } from "../../helpers";
import { getElementById, getWebElementById, isAndroid, tapByElement } from "../../helpers";

const expectedUrl = "https://shop.ledger.com/";

Expand All @@ -13,7 +12,7 @@ export default class BuyDevicePage {
async expectBuyNanoWebPage() {
// Webview testing is flaky on Android
if (!isAndroid()) {
const url = await web.element(by.web.id("__next")).getCurrentUrl();
const url = await getWebElementById("__next").getCurrentUrl();
expect(url).toContain(expectedUrl);
} else {
console.warn("Skipping webview check on Android");
Expand Down
16 changes: 11 additions & 5 deletions apps/ledger-live-mobile/e2e/page/discover/discover.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { getElementById, openDeeplink, waitForElementByText } from "../../helpers";
import { by, expect, log, web } from "detox";
import {
getElementById,
getWebElementById,
getWebElementByTag,
openDeeplink,
waitForElementByText,
} from "../../helpers";
import { expect, log } from "detox";
import jestExpect from "expect";

const baseLink = "discover/";
Expand Down Expand Up @@ -51,16 +57,16 @@ export default class DiscoverPage {
}

async expect1inchParams() {
const title = await web.element(by.web.id("__next")).getTitle();
const title = await getWebElementById("__next").getTitle();
jestExpect(title).toBe("Ledger Platform Apps");

const url = await web.element(by.web.id("__next")).getCurrentUrl();
const url = await getWebElementById("__next").getCurrentUrl();
jestExpect(url).toContain("app.1inch.io");
jestExpect(url).toContain("usdt");
jestExpect(url).toContain("sourceTokenAmount%3D");
jestExpect(url).toContain("currency%22%3A%22ethereum");
jestExpect(url).toContain("accountId=d9d1d396-2081-53e1-9c67-f0623e0c4d3a");

await expect(web.element(by.web.tag("iframe"))).toExist();
await expect(getWebElementByTag("iframe")).toExist();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { web, by } from "detox";
import { send, startLiveApp, stopServer } from "../../models/liveApps";
import DiscoverPage from "../discover/discover.page";
import { getWebElementById } from "../../helpers";

const port = 52619;

Expand All @@ -16,10 +16,10 @@ export default class DummyWalletApp {
}

async expectApp() {
const title = await web.element(by.web.id("image-container")).getTitle();
const title = await getWebElementById("image-container").getTitle();
expect(title).toBe("Dummy Wallet API App");

const url = await web.element(by.web.id("param-container")).getCurrentUrl();
const url = await getWebElementById("param-container").getCurrentUrl();
expect(url).toBe(
`http://localhost:${port}/?theme=light&lang=en&name=Dummy+Wallet+API+Live+App`,
);
Expand Down

0 comments on commit d7abb17

Please sign in to comment.