Skip to content

Commit 7f6878c

Browse files
committed
refactor: Enhance integration tests with improved visibility checks and timing adjustments
This change: - Adds visibility checks for widgets before interaction in various test flows. - Introduces consistent pump and settle durations to ensure UI stability during tests. - Refines scrolling logic to confirm wallet types are visible before selection. - Updates tap actions to include warnings for missed taps, improving test reliability.
1 parent 593da39 commit 7f6878c

File tree

7 files changed

+125
-49
lines changed

7 files changed

+125
-49
lines changed

integration_test/components/common_test_cases.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_test/flutter_test.dart';
3-
import 'package:integration_test/integration_test.dart';
43

54
class CommonTestCases {
65
WidgetTester tester;
@@ -16,8 +15,14 @@ class CommonTestCases {
1615
bool shouldPumpAndSettle = true,
1716
int pumpDuration = 100,
1817
}) async {
19-
final widget = find.byKey(ValueKey(key)).first;
20-
await tester.tap(widget);
18+
await tester.pump(Duration(milliseconds: 500));
19+
20+
final widgetFinder = find.byKey(ValueKey(key));
21+
22+
expect(tester.any(widgetFinder), true, reason: 'Widget with key "$key" should be visible');
23+
24+
final widget = widgetFinder.first;
25+
await tester.tap(widget, warnIfMissed: false);
2126
shouldPumpAndSettle
2227
? await tester.pumpAndSettle(Duration(milliseconds: pumpDuration))
2328
: await tester.pump();
@@ -213,7 +218,7 @@ class CommonTestCases {
213218
itemFinder,
214219
scrollPixels,
215220
scrollable: scrollableFinder,
216-
maxScrolls: 10,
221+
maxScrolls: 10,
217222
);
218223

219224
// Wait for the scroll to complete

integration_test/components/common_test_flows.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class CommonTestFlows {
126126
//* ========== Handles creating new wallet flow from wallet list/menu ===============
127127
Future<void> createNewWalletFromWalletMenu(WalletType walletTypeToCreate) async {
128128
_tester.printToConsole('Creating ${walletTypeToCreate.name} Wallet');
129+
130+
await _tester.pumpAndSettle(Duration(milliseconds: 1000));
131+
129132
await _walletListPageRobot.navigateToCreateNewWalletPage();
130133
await _commonTestCases.defaultSleepTime();
131134

@@ -221,17 +224,32 @@ class CommonTestFlows {
221224
//* ============ Handles New Wallet Type Page ==================
222225
Future<void> _selectWalletTypeForWallet(WalletType type) async {
223226
// ----------- NewWalletType Page -------------
224-
// Confirm scroll behaviour works properly
227+
_tester.printToConsole('Selecting wallet type: ${type.name}');
228+
229+
await _tester.pumpAndSettle(Duration(milliseconds: 1000));
230+
225231
await _newWalletTypePageRobot.findParticularWalletTypeInScrollableList(type);
226232

227-
// Select a wallet and route to next page
233+
_tester.printToConsole('Tapping wallet type: ${type.name}');
228234
await _newWalletTypePageRobot.selectWalletType(type);
235+
await _tester.pumpAndSettle(Duration(milliseconds: 500));
236+
237+
_tester.printToConsole('Pressing next button');
229238
await _newWalletTypePageRobot.onNextButtonPressed();
239+
240+
await _tester.pumpAndSettle(Duration(milliseconds: 2000));
241+
242+
_tester.printToConsole('Wallet type selection completed for: ${type.name}');
230243
}
231244

232245
//* ============ Handles New Wallet Page ==================
233246
Future<void> _generateNewWalletDetails() async {
247+
_tester.printToConsole('Attempting to find NewWalletPage...');
248+
249+
await _tester.pumpAndSettle(Duration(milliseconds: 1000));
250+
234251
await _newWalletPageRobot.isNewWalletPage();
252+
_tester.printToConsole('NewWalletPage found successfully');
235253

236254
await _newWalletPageRobot.generateWalletName();
237255

integration_test/robots/dashboard_page_robot.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:cake_wallet/generated/i18n.dart';
22
import 'package:cake_wallet/src/screens/dashboard/dashboard_page.dart';
33
import 'package:cake_wallet/src/screens/dashboard/pages/balance/crypto_balance_widget.dart';
44
import 'package:cw_core/wallet_type.dart';
5+
import 'package:flutter/material.dart';
56
import 'package:flutter_test/flutter_test.dart';
67

78
import '../components/common_test_cases.dart';
@@ -93,7 +94,20 @@ class DashboardPageRobot {
9394
}
9495

9596
Future<void> navigateToWalletsListPage() async {
96-
await commonTestCases.tapItemByKey('dashboard_page_${S.current.wallets}_action_button_key');
97+
await tester.pumpAndSettle(Duration(milliseconds: 1000));
98+
99+
final dashboardFinder = find.byType(DashboardPage);
100+
expect(tester.any(dashboardFinder), true, reason: 'Dashboard page should be visible');
101+
102+
final walletsButtonKey = 'dashboard_page_${S.current.wallets}_action_button_key';
103+
final walletsButtonFinder = find.byKey(ValueKey(walletsButtonKey));
104+
105+
await tester.pumpAndSettle(Duration(milliseconds: 500));
106+
expect(tester.any(walletsButtonFinder), true, reason: 'Wallets button should be visible');
107+
108+
await commonTestCases.tapItemByKey(walletsButtonKey);
109+
110+
await tester.pumpAndSettle(Duration(milliseconds: 2000));
97111
}
98112

99113
Future<void> navigateToSendPage() async {

integration_test/robots/new_wallet_type_page_robot.dart

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,43 @@ class NewWalletTypePageRobot {
3838
}
3939

4040
Future<void> findParticularWalletTypeInScrollableList(WalletType type) async {
41+
await tester.pump(Duration(milliseconds: 1000));
42+
4143
final scrollableWidget = find.descendant(
4244
of: find.byKey(Key('new_wallet_type_scrollable_key')),
4345
matching: find.byType(Scrollable),
4446
);
4547

48+
final targetWidget = find.byKey(ValueKey('new_wallet_type_${type.name}_button_key'));
49+
50+
tester.printToConsole('Attempting to scroll to wallet type ${type.name}');
51+
52+
await tester.pump(Duration(milliseconds: 500));
53+
4654
await tester.scrollUntilVisible(
47-
find.byKey(ValueKey('new_wallet_type_${type.name}_button_key')),
55+
targetWidget,
4856
300,
4957
scrollable: scrollableWidget,
58+
maxScrolls: 20,
59+
);
60+
61+
await tester.pumpAndSettle(Duration(milliseconds: 1000));
62+
63+
expect(tester.any(targetWidget), true,
64+
reason: 'Wallet type ${type.name} should be visible after scrolling');
65+
66+
// Additional check to ensure the widget is actually on screen
67+
final widgetRect = tester.getRect(targetWidget);
68+
final screenSize = tester.view.physicalSize;
69+
final screenRect = Rect.fromLTWH(0, 0, screenSize.width, screenSize.height);
70+
71+
expect(
72+
screenRect.overlaps(widgetRect),
73+
true,
74+
reason: 'Wallet type ${type.name} should be within screen bounds',
5075
);
76+
77+
tester.printToConsole('Wallet type ${type.name} is now visible and tappable');
5178
}
5279

5380
Future<void> selectWalletType(WalletType type) async {

integration_test/robots/security_and_backup_page_robot.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class SecurityAndBackupPageRobot {
2020
}
2121

2222
Future<void> navigateToShowKeysPage() async {
23+
await tester.pumpAndSettle(Duration(milliseconds: 1000));
24+
2325
await commonTestCases.tapItemByKey('security_backup_page_show_keys_button_key');
26+
await tester.pumpAndSettle(Duration(milliseconds: 1000));
2427
}
2528
}

integration_test/robots/wallet_keys_robot.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ class WalletKeysAndSeedPageRobot {
181181

182182
Future<void> backToDashboard() async {
183183
tester.printToConsole('Going back to dashboard from credentials page');
184+
await tester.pumpAndSettle(Duration(milliseconds: 1000));
185+
184186
await commonTestCases.goBack();
187+
await tester.pumpAndSettle(Duration(milliseconds: 1000));
188+
185189
await commonTestCases.goBack();
190+
await tester.pumpAndSettle(Duration(milliseconds: 2000));
186191
}
187192
}

integration_test/test_suites/confirm_seeds_flow_test.dart

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,66 @@ void main() {
2424
testWidgets(
2525
'Confirm if the seeds display properly',
2626
(tester) async {
27-
// Set up error handling to prevent FlutterError.onError assertion
27+
// Store the original FlutterError.onError handler
28+
final originalOnError = FlutterError.onError;
29+
2830
FlutterError.onError = (FlutterErrorDetails details) {
29-
// We log the error but don't throw it
3031
debugPrint('FlutterError caught: ${details.exception}');
3132
};
32-
33-
authPageRobot = AuthPageRobot(tester);
34-
commonTestFlows = CommonTestFlows(tester);
35-
dashboardPageRobot = DashboardPageRobot(tester);
36-
walletKeysAndSeedPageRobot = WalletKeysAndSeedPageRobot(tester);
37-
securityAndBackupPageRobot = SecurityAndBackupPageRobot(tester);
38-
39-
// Start the app
40-
await commonTestFlows.startAppFlow(
41-
ValueKey('confirm_creds_display_correctly_flow_app_key'),
42-
);
43-
44-
await commonTestFlows.welcomePageToCreateNewWalletFlow(
45-
WalletType.solana,
46-
CommonTestConstants.pin,
47-
);
48-
49-
await dashboardPageRobot.confirmWalletTypeIsDisplayedCorrectly(WalletType.solana);
50-
51-
await _confirmSeedsFlowForWalletType(
52-
WalletType.solana,
53-
authPageRobot,
54-
dashboardPageRobot,
55-
securityAndBackupPageRobot,
56-
walletKeysAndSeedPageRobot,
57-
tester,
58-
);
59-
60-
// Do the same for other available wallet types
61-
for (var walletType in availableWalletTypes) {
62-
if (walletType == WalletType.solana) {
63-
continue;
64-
}
6533

66-
await dashboardPageRobot.navigateToWalletsListPage();
34+
try {
35+
authPageRobot = AuthPageRobot(tester);
36+
commonTestFlows = CommonTestFlows(tester);
37+
dashboardPageRobot = DashboardPageRobot(tester);
38+
walletKeysAndSeedPageRobot = WalletKeysAndSeedPageRobot(tester);
39+
securityAndBackupPageRobot = SecurityAndBackupPageRobot(tester);
6740

68-
await commonTestFlows.createNewWalletFromWalletMenu(walletType);
41+
await commonTestFlows.startAppFlow(
42+
ValueKey('confirm_creds_display_correctly_flow_app_key'),
43+
);
6944

70-
await dashboardPageRobot.confirmWalletTypeIsDisplayedCorrectly(walletType);
45+
await commonTestFlows.welcomePageToCreateNewWalletFlow(
46+
WalletType.solana,
47+
CommonTestConstants.pin,
48+
);
49+
50+
await dashboardPageRobot.confirmWalletTypeIsDisplayedCorrectly(WalletType.solana);
7151

7252
await _confirmSeedsFlowForWalletType(
73-
walletType,
53+
WalletType.solana,
7454
authPageRobot,
7555
dashboardPageRobot,
7656
securityAndBackupPageRobot,
7757
walletKeysAndSeedPageRobot,
7858
tester,
7959
);
80-
}
8160

82-
await Future.delayed(Duration(seconds: 15));
61+
// Do the same for other available wallet types
62+
for (var walletType in availableWalletTypes) {
63+
if (walletType == WalletType.solana) {
64+
continue;
65+
}
66+
67+
await dashboardPageRobot.navigateToWalletsListPage();
68+
69+
await commonTestFlows.createNewWalletFromWalletMenu(walletType);
70+
71+
await dashboardPageRobot.confirmWalletTypeIsDisplayedCorrectly(walletType);
72+
73+
await _confirmSeedsFlowForWalletType(
74+
walletType,
75+
authPageRobot,
76+
dashboardPageRobot,
77+
securityAndBackupPageRobot,
78+
walletKeysAndSeedPageRobot,
79+
tester,
80+
);
81+
}
82+
83+
await Future.delayed(Duration(seconds: 15));
84+
} finally {
85+
FlutterError.onError = originalOnError;
86+
}
8387
},
8488
);
8589
}

0 commit comments

Comments
 (0)