Skip to content

Commit d414c1c

Browse files
authored
Merge pull request #42 from synonymdev/ios/alerts
Handle Ios/android alerts
2 parents 0bd1fc6 + 3f14490 commit d414c1c

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

test/helpers/actions.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,3 +806,56 @@ export async function waitForBackup() {
806806
await allSynced.waitForDisplayed();
807807
await doNavigationClose();
808808
}
809+
810+
type alertAction = 'confirm' | 'cancel';
811+
export async function handleCommonAlert(
812+
action: alertAction = 'confirm',
813+
androidId: string,
814+
iosText: string
815+
) {
816+
if (driver.isAndroid) {
817+
await elementById(androidId).waitForDisplayed();
818+
} else {
819+
// iOS alert is system modal
820+
// check if alert text includes iosText
821+
await driver.waitUntil(
822+
async () => {
823+
try {
824+
const alertText = await driver.getAlertText();
825+
return alertText.includes(iosText);
826+
} catch {
827+
return false;
828+
}
829+
},
830+
{
831+
timeout: 10_000,
832+
interval: 300,
833+
timeoutMsg: `Timed out waiting for alert with text: ${iosText}`,
834+
}
835+
);
836+
}
837+
838+
if (action === 'confirm') {
839+
if (driver.isAndroid) {
840+
await tap('DialogConfirm');
841+
} else {
842+
await driver.acceptAlert();
843+
}
844+
} else {
845+
if (driver.isAndroid) {
846+
await tap('DialogCancel');
847+
} else {
848+
await driver.dismissAlert();
849+
}
850+
}
851+
}
852+
853+
// sending over 50% of balance warning
854+
export async function handleOver50PercentAlert(action: alertAction = 'confirm') {
855+
await handleCommonAlert(action, 'SendDialog2', 'over 50%');
856+
}
857+
858+
// sending over $100 warning
859+
export async function handleOver100Alert(action: alertAction = 'confirm') {
860+
await handleCommonAlert(action, 'SendDialog1', 'over $100');
861+
}

test/specs/onchain.e2e.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
acknowledgeHighBalanceWarning,
2323
enterAddress,
2424
dismissBackupTimedSheet,
25+
handleOver50PercentAlert,
26+
handleOver100Alert,
2527
} from '../helpers/actions';
2628
import { ciIt } from '../helpers/suite';
2729

@@ -161,8 +163,7 @@ describe('@onchain - Onchain', () => {
161163
await dragOnElement('GRAB', 'right', 0.95);
162164

163165
await sleep(1000);
164-
await elementById('SendDialog2').waitForDisplayed(); // sending over 50% of balance warning
165-
await tap('DialogConfirm');
166+
await handleOver50PercentAlert();
166167
await elementById('SendSuccess').waitForDisplayed();
167168
await tap('Close');
168169

@@ -271,6 +272,7 @@ describe('@onchain - Onchain', () => {
271272

272273
// enter amount that would leave dust
273274
let amountStr = await (await elementByIdWithin('AvailableAmount', 'MoneyText')).getText();
275+
await tap('AvailableAmount');
274276
amountStr = amountStr.replace('₿', '').replace(/\s/g, '');
275277
let amount = parseInt(amountStr, 10);
276278
amount = amount - 300; // = 99 999 588
@@ -284,12 +286,10 @@ describe('@onchain - Onchain', () => {
284286
await dragOnElement('GRAB', 'right', 0.95);
285287

286288
// sending over 50% of balance warning
287-
await elementById('SendDialog2').waitForDisplayed();
288-
await tap('DialogConfirm');
289+
await handleOver50PercentAlert();
289290

290291
// sending over 100$ warning
291-
await elementById('SendDialog1').waitForDisplayed();
292-
await tap('DialogConfirm');
292+
await handleOver100Alert();
293293

294294
await elementById('SendSuccess').waitForDisplayed();
295295
await tap('Close');

wdio.conf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const config: WebdriverIO.Config = {
7676
'appium:platformVersion': '26.0',
7777
'appium:app': path.join(__dirname, 'aut', 'Bitkit.app'),
7878
'appium:autoGrantPermissions': true,
79-
'appium:autoAcceptAlerts': true,
79+
'appium:autoAcceptAlerts': false,
8080
// 'appium:fullReset': true,
8181
'appium:noReset': false,
8282

0 commit comments

Comments
 (0)