-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathgeneral.flow.ts
More file actions
174 lines (157 loc) · 6.07 KB
/
general.flow.ts
File metadata and controls
174 lines (157 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { createLogger } from '../framework/logger';
import Assertions from '../framework/Assertions';
import {
Gestures,
PlaywrightAssertions,
PlaywrightGestures,
PlaywrightMatchers,
} from '../framework';
import Matchers from '../framework/Matchers';
import Utilities, { sleep } from '../framework/Utilities';
import LoginView from '../page-objects/wallet/LoginView';
const logger = createLogger({
name: 'GeneralFlow',
});
/**
* Dismisses development build screens.
* Handles 'Development servers' and 'Developer menu' screens.
* These screens are expected to appear when running locally.
*/
export const dismissDevScreens = async (): Promise<void> => {
const port = process.env.METRO_PORT_E2E || process.env.WATCHER_PORT || '8081';
const host = process.env.METRO_HOST_E2E || 'localhost';
const serverUrl = `http://${host}:${port}`;
try {
// 1. Check for Development Servers screen
// We tap the server row matching the current metro port
const devServerRow = Matchers.getElementByText(serverUrl);
await Assertions.expectElementToBeVisible(devServerRow, {
timeout: 2000,
description: 'Dev Server Row should be visible',
});
await Gestures.tap(devServerRow, { elemDescription: 'Dev Server Row' });
// 2. Check for Developer Menu onboarding
const continueButton = Matchers.getElementByText('Continue');
await Assertions.expectElementToBeVisible(continueButton, {
timeout: 5000,
description: 'Dev Menu Continue Button should be visible',
});
// Tap Continue to proceed past the onboarding screen.
await Gestures.tap(continueButton, {
elemDescription: 'Dev Menu Continue Button',
});
// 3. Close the Developer Menu
// After tapping Continue, the Developer Menu options list appears.
// The user provided the ID 'fast-refresh' to tap on.
const fastRefreshButton = Matchers.getElementByID('fast-refresh');
await Assertions.expectElementToBeVisible(fastRefreshButton, {
timeout: 5000,
description: 'Dev Menu Fast Refresh Button should be visible',
});
await Gestures.tap(fastRefreshButton, {
elemDescription: 'Dev Menu Fast Refresh Button',
});
} catch (error) {
logger.debug(
`Dev screens were not dismissed (best effort): ${
error instanceof Error ? error.message : String(error)
}`,
);
}
};
/**
* Dismisses development build screens using Playwright.
* Handles 'Development servers' and 'Developer menu' screens.
* These screens are expected to appear when running locally.
*/
export const dismissDevScreensPlaywright = async (): Promise<void> => {
const port = process.env.METRO_PORT_E2E || process.env.WATCHER_PORT || '8081';
const host = process.env.METRO_HOST_E2E || 'localhost';
const serverUrl = `http://${host}:${port}`;
try {
// 1. Check for Development Servers screen
// We tap the server row matching the current metro port
const devServerRow = await PlaywrightMatchers.getElementByText(serverUrl);
await PlaywrightAssertions.expectElementToBeVisible(devServerRow, {
timeout: 2000,
description: 'Dev Server Row should be visible',
});
await PlaywrightGestures.waitAndTap(devServerRow);
// 2. Check for Developer Menu onboarding
const continueButton =
await PlaywrightMatchers.getElementByText('Continue');
await PlaywrightAssertions.expectElementToBeVisible(continueButton, {
timeout: 5000,
description: 'Dev Menu Continue Button should be visible',
});
// Tap Continue to proceed past the onboarding screen.
await PlaywrightGestures.waitAndTap(continueButton);
// 3. Close the Developer Menu
// After tapping Continue, the Developer Menu options list appears.
// The user provided the ID 'fast-refresh' to tap on.
const fastRefreshButton = await PlaywrightMatchers.getElementById(
'fast-refresh',
{ exact: true },
);
await PlaywrightAssertions.expectElementToBeVisible(fastRefreshButton, {
timeout: 5000,
description: 'Dev Menu Fast Refresh Button should be visible',
});
await PlaywrightGestures.waitAndTap(fastRefreshButton);
} catch (error) {
logger.debug(
`Playwright dev screens were not dismissed (best effort): ${
error instanceof Error ? error.message : String(error)
}`,
);
}
};
/**
* Waits for app initialization and rehydration to complete.
* This ensures the app is in a stable state before proceeding with tests.
* Handles the case where React Native reload triggers state rehydration that may
* cause the app to briefly log out and return to the login screen.
*
* @async
* @function waitForAppReady
* @param {number} timeout - Maximum time to wait in milliseconds (default: 20000)
* @returns {Promise<void>} Resolves when app is ready
* @throws {Error} Throws an error if app fails to stabilize within timeout
*/
export const waitForAppReady = async (
timeout: number = 20000,
): Promise<void> => {
const startTime = Date.now();
logger.debug('Waiting for app to complete rehydration and stabilize...');
try {
// Initial wait for app to finish launching and start rehydration
await sleep(1000);
await Utilities.executeWithRetry(
async () => {
await Assertions.expectElementToBeVisible(LoginView.container, {
description: 'Login view should be stable',
timeout: 3000,
});
// Verify it stays visible (not flickering during rehydration)
await sleep(1500);
await Assertions.expectElementToBeVisible(LoginView.container, {
description: 'Login view should remain visible',
timeout: 2000,
});
},
{
timeout,
interval: 2000,
description:
'wait for app to complete rehydration and stabilize on login screen',
},
);
logger.debug(`App ready after ${Date.now() - startTime}ms`);
} catch (error) {
logger.error(`App failed to stabilize within ${timeout}ms`, error);
throw new Error(
`App did not stabilize on login screen within ${timeout}ms. ` +
`This may indicate rehydration issues or state corruption.`,
);
}
};