-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add reinstallApp option and terminate before auto launch #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gmegidish
wants to merge
3
commits into
main
Choose a base branch
from
feat/reinstall-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { homedir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { test, expect } from '@mobilewright/test'; | ||
| import type { Locator, Screen } from '@mobilewright/core'; | ||
|
|
||
| // Proves reinstallApp gives a fresh install: the playground's SharedPref screen persists a | ||
| // username across relaunches, and only an uninstall wipes it. Android only — on iOS the | ||
| // playground stores these in the keychain, which survives an uninstall. | ||
| const PLAYGROUND_APK = join(homedir(), 'git/playground/android/app/build/outputs/apk/debug/app-debug.apk'); | ||
| const USERNAME = 'reinstall-me'; | ||
|
|
||
| test.use({ platform: 'android', bundleId: 'com.mobilenext.playground', installApps: PLAYGROUND_APK }); | ||
| // Serial on one worker: the pool hands the released emulator back to the next test, so saved | ||
| // preferences carry across tests. This assumes a single matching Android device, as in CI. | ||
| test.describe.configure({ mode: 'serial' }); | ||
|
|
||
| async function openSharedPrefScreen(screen: Screen): Promise<void> { | ||
| await screen.getByText('SharedPref / Keychain').tap(); | ||
| await expect(screen.getByLabel('load_button')).toBeVisible(); | ||
| } | ||
|
|
||
| async function loadAndReadStatus(screen: Screen): Promise<Locator> { | ||
| await screen.getByLabel('load_button').tap(); | ||
| return screen.getByLabel('status_message'); | ||
| } | ||
|
|
||
| test('saves a username into shared preferences', async ({ screen }) => { | ||
| await openSharedPrefScreen(screen); | ||
| await screen.getByLabel('username_field').fill(USERNAME); | ||
| await screen.getByLabel('save_button').tap(); | ||
| await expect(screen.getByLabel('status_message')).toHaveText('Saved'); | ||
| }); | ||
|
|
||
| test('a relaunch keeps the saved username', async ({ screen }) => { | ||
| await openSharedPrefScreen(screen); | ||
| const status = await loadAndReadStatus(screen); | ||
| await expect(status).toHaveText('Loaded'); | ||
| await expect(screen.getByLabel('username_field')).toHaveText(USERNAME); | ||
| }); | ||
|
|
||
| test.describe('with reinstallApp', () => { | ||
| test.use({ reinstallApp: true }); | ||
|
|
||
| test('a reinstall wipes the saved username', async ({ screen }) => { | ||
| await openSharedPrefScreen(screen); | ||
| const status = await loadAndReadStatus(screen); | ||
| await expect(status).toHaveText('No preferences found'); | ||
| }); | ||
| }); | ||
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: mobile-next/mobilewright
Length of output: 25942
🏁 Script executed:
Repository: mobile-next/mobilewright
Length of output: 12769
🏁 Script executed:
Repository: mobile-next/mobilewright
Length of output: 6076
Do not depend on device state across separate tests.
The test-scoped
devicefixture disconnects and releases its allocation after each test. The pool may reuse a released slot, but it can also allocate another matching device. Serial mode only preserves execution order.The relaunch assertion can fail because the saved preferences are on another device. The reinstall assertion can pass on a fresh device because
prepareAppinstalls the app without any saved preferences to remove.Make each test self-contained, or add a dedicated worker-scoped fixture that owns one device allocation and storage lineage for the full sequence.
🤖 Prompt for AI Agents