Debugging in Visual Studio Code
You can debug your application during Patrol tests by attaching a debugger to the running process.Setup Instructions
Add debugger configuration
In your
launch.json file, add a new configuration for attaching debugger to a process:Run tests with develop command
Run your patrol tests using
develop command with the same arguments as you would normally do:Copy the VM Service URI
When the tests start running, you will see a message with a link to Patrol devtools extension. Copy the last part of the URI from the message.For example, for this link:Copy
http://127.0.0.1:52263/F2-CH29gR1k=/.Attach the debugger
From “Run and Debug” tab in Visual Studio Code, select the configuration you created in step 1. You will be prompted to enter the VM service URI. Paste the URI you copied in step 3.
IntelliJ/Android Studio does not support attaching a debugger to a running process via Observatory Uri. Therefore you cannot achieve the same behavior in those IDEs. See this issue for more details.
Hot Restart for Faster Development
When writing Patrol tests, use thepatrol develop command for faster iteration:
patrol test from scratch every time you make a change.
Common Issues and Solutions
Test fails with 'Finder finds multiple widgets'
Test fails with 'Finder finds multiple widgets'
Problem: Your finder matches multiple widgets on the screen.Solution: Use the Better Solution: Use unique keys instead:
.at(index) method to specify which widget you want:Permission dialog test fails on second run
Permission dialog test fails on second run
Problem:
grantPermissionWhenInUse() fails because the permission was already granted.Solution: Check if the permission dialog is visible before trying to accept it:This is especially important when using
patrol develop for local development, where app state may persist between runs.Widget not found error
Widget not found error
Problem: Test fails with “Widget not found” even though the widget exists.Possible causes:
- Widget hasn’t finished rendering
- Widget is hidden/scrolled off-screen
- Wrong finder selector
Test timeout issues
Test timeout issues
Problem: Test times out waiting for an action to complete.Solution: Increase the timeout for specific operations:
Tests pass locally but fail in CI
Tests pass locally but fail in CI
Problem: Tests work on your machine but fail in continuous integration.Common causes:
- Different device/emulator configurations
- Timing issues (CI machines may be slower)
- Environment variable differences
Inspecting Native View Hierarchy
When you need to interact with native views and don’t know how to refer to them, perform a native view hierarchy dump.Android
First, perform a native view hierarchy dump usingadb:
iOS
The easiest way to perform the native view hierarchy dump on iOS is to use the idb tool. Once you have idb installed, perform a dump:Ignoring Exceptions
If an exception is thrown during a test, it is marked as failed. This is Flutter’s default behavior and it’s usually good – after all, it’s better to fix the cause of a problem instead of ignoring it. That said, sometimes you do have a legitimate reason to ignore an exception. This can be accomplished with the help of the WidgetTester.takeException() method.Ignore a Single Exception
Ignore Multiple Exceptions
If more than a single exception is thrown during the test and you want to ignore all of them:Debugging Tips
Use $.log()
Add logging statements to track test execution:
Check Widget Existence
Verify widgets exist before interacting:
Take Screenshots
Capture screenshots at key points:
Use DevTools Extension
Monitor test execution in real-time with Patrol DevTools extension for deeper insights.