Download and open a file
Automate file download and open workflows on mobile devices with Maestro.
The workflow
1. Download and verify the file
# Step 1: Trigger the download in your app
- tapOn: 'Maestro PDF'
# Step 2: Handle "Stale" Files
# On local emulators, the file might exist from a previous run.
# We use 'optional: true' to skip this if the prompt doesn't appear.
- tapOn:
text: 'Download again'
optional: true
# Step 3: Handle Android-specific download confirmations
# Some Android versions (SDK 33/34) ask for location confirmation
# or show a "File downloaded" snackbar before opening.
- runFlow:
when:
visible: 'Choose where to download'
commands:
- tapOn: 'Download'
- runFlow:
when:
# If the PDF hasn't automatically opened yet, find the 'Open' button
notVisible: 'This is a Maestro test.*'
commands:
- assertVisible: 'File downloaded'
- tapOn: 'Open'
# Step 4: Verify the PDF Content
# Once the system PDF viewer is open, we assert that the text is visible.
- assertVisible: 'This is a Maestro test.*'
# Step 5: Return to the App
# We close the system viewer to return to the application state.
- runFlow:
when:
platform: Android
commands:
- back
- runFlow:
when:
platform: iOS
commands:
- tapOn: 'Done'2. Implementation
Related content
Last updated