Skip to content
Open
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
25 changes: 25 additions & 0 deletions test/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ export function elementById(selector: string): ChainablePromiseElement {
}
}

/**
* Like elementById, but matches ids that start with `prefix` (suffix is often dynamic).
* Android: resourceId regex. iOS: predicate on `name` (the accessibility identifier).
*/
export function elementByIdPrefix(prefix: string): ChainablePromiseElement {
if (driver.isAndroid) {
return $(`android=new UiSelector().resourceIdMatches(".*${prefix}.*")`);
}
return $(`-ios predicate string:name BEGINSWITH '${prefix}'`);
}

// Find a child testID within an ancestor testID (compatible with both Android and iOS.)
export async function elementByIdWithin(
ancestorId: string,
Expand Down Expand Up @@ -387,6 +398,20 @@ export async function tap(testId: string, { timeout = 30_000 }: { timeout?: numb
await sleep(100);
}

/**
* Taps the first element whose accessibility id starts with `prefix`.
*/
export async function tapFirstByAccessibilityIdPrefix(
prefix: string,
{ timeout = 30_000 }: { timeout?: number } = {}
) {
const el = elementByIdPrefix(prefix);
await el.waitForExist({ timeout });
await sleep(200);
await el.click();
await sleep(100);
}

export async function multiTap(testId: string, count: number) {
await elementById(testId).waitForDisplayed();
await sleep(300); // Allow time for the element to settle
Expand Down
25 changes: 8 additions & 17 deletions test/helpers/hardware-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
acknowledgeReceivedPaymentIfPresent,
doNavigationClose,
elementById,
elementByText,
enterAmount,
expectBalanceWithWait,
expectTextWithin,
Expand All @@ -14,6 +15,7 @@ import {
getAmountUnder,
sleep,
tap,
tapFirstByAccessibilityIdPrefix,
typeText,
handleAndroidAlert,
waitForToast,
Expand Down Expand Up @@ -134,7 +136,10 @@ export async function expectHardwareWalletInSettings(

export async function renameHardwareWalletFromSettings(currentLabel: string, newLabel: string) {
await expectHardwareWalletInSettings(currentLabel, { visible: true });
await tapFirstHardwareWalletName();
const nameEl = await elementByText(currentLabel, 'contains');
await nameEl.waitForDisplayed({ timeout: 30_000 });
await sleep(200);
await nameEl.click();
await elementById('RenameHardwareWalletInput').waitForDisplayed({ timeout: 30_000 });
await typeText('RenameHardwareWalletInput', newLabel);
await tap('RenameHardwareWalletSave');
Expand Down Expand Up @@ -237,6 +242,7 @@ export async function transferHardwareWalletToSpending({
// Local backend does not have Blocktank,
// so we don't wait for the transfer success screen.
await tap('TransferSuccess-button');
await dismissBackupTimedSheet({ triggerTimedSheet: false });
} else {
await mineBlocks(1);
if (waitForSync) {
Expand Down Expand Up @@ -266,7 +272,7 @@ export async function transferHardwareWalletToSpending({
export async function removeHardwareWalletFromSettings(label: string) {
await openHardwareWalletSettings();
await expectHardwareWalletInSettings(label, { visible: true });
await tapFirstHardwareWalletDelete();
await tapFirstByAccessibilityIdPrefix('HardwareWalletRowDelete_');
await tap('DialogConfirm');
await sleep(500);
await expectHardwareWalletInSettings(label, { visible: false });
Expand Down Expand Up @@ -328,18 +334,3 @@ async function dismissSpendingBalanceToastIfShown() {
}
}

async function tapFirstHardwareWalletDelete() {
const deleteButton = await $(
'android=new UiSelector().resourceIdMatches(".*HardwareWalletRowDelete_.*")'
);
await deleteButton.waitForDisplayed({ timeout: 30_000 });
await deleteButton.click();
}

async function tapFirstHardwareWalletName() {
const nameButton = await $(
'android=new UiSelector().resourceIdMatches(".*HardwareWalletRowName.*")'
);
await nameButton.waitForDisplayed({ timeout: 30_000 });
await nameButton.click();
}