feat(core): add waitForReady option to launchApp to avoid first-render flakiness#75
Open
feat(core): add waitForReady option to launchApp to avoid first-render flakiness#75
Conversation
Member
|
I think the bug report is correct, launchApp should wait for getForegroundApp to be the same bundleId as what we were launching, and if it fails within the time limit, then we need to throw an exception. The code commit seems to be related to node modules. But I'll fix the launchApp. The default should be to auto wait, as with tap and all the rest. |
…"module" Catch ERR_REQUIRE_ESM thrown by loadConfigFromFile and print a clear, human-readable message telling the user exactly what to add to their package.json, instead of dumping a raw Node.js internal stack trace.
e0440a8 to
694b41c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
launchApp()resolves as soon as the OS acknowledges the launch. On cold start, the app hasn't rendered its first screen yet, causing the immediately-following assertion to fail. This is especially visible on first run after boot.Observed in practice: a test checking for a welcome screen text timed out at 27 s on first run, then passed reliably (5–8 s) on subsequent warm runs. The
beforeEachdidawait device.launchApp(bundleId)followed immediately byawait expect(screen.getByText('Welcome to Milliways')).toBeVisible().Fix
Opt-in
waitForReadyonLaunchOptions— pollsgetViewHierarchy()until ≥ 2 visible elements appear, up to a configurable timeout (default 5 s). Timeout is soft: if the app hasn't rendered by then, it resolves anyway and the first assertion produces the real error message.Usage
```typescript
await device.launchApp('com.example.app', { waitForReady: true });
// or with a custom timeout:
await device.launchApp('com.example.app', { waitForReady: 10_000 });
```
Changes
packages/protocol/src/types.ts: AddedwaitForReady?: boolean | numbertoLaunchOptionspackages/mobilewright-core/src/device.ts: ImplementedpollUntilReadyprivate method;launchAppnow calls it whenwaitForReadyis setpackages/mobilewright-core/src/device.test.ts: New test file covering the polling behaviour, soft timeout, error resilience, and the no-op path whenwaitForReadyis not setTest plan
waitForReady: truepollsgetViewHierarchy()at least oncewaitForReady: 10_000)getViewHierarchythrows during early startupwaitForReadyis not set