Test Flutter apps
App Automate supports testing Flutter apps on Android and iOS devices. We have added support for Appium’s Flutter driver to test Flutter apps using the Appium testing framework on BrowserStack.
The process to test Flutter apps in BrowserStack involves preprocessing your app, uploading it to BrowserStack, adding the automationName
capability to your test script along with the app ID, and then running your test script.
In this guide, you’ll learn how to:
Preprocess Flutter app for testing
To preprocess your app for BrowserStack, complete the following steps:
- Open your Flutter app project.
- Add the following
dev_dependencies
in thepubspec.yaml
file of your Flutter project:pubspec.yamldev_dependencies: test: any flutter_test: sdk: flutter flutter_driver: sdk: flutter
The
flutter_test
andflutter_driver
libraries provide functions and APIs respectively to write tests for Flutter apps. - Run the following command in the command-line/terminal of your Flutter project to install the
dev_dependencies
added in the previous step:Command-lineflutter pub get
- Add the following code statement in the
main.dart
file of your Flutter project to import theflutter_driver_extension
library:
main.dartimport 'package:flutter_driver/driver_extension.dart';
- Add the
enableFlutterDriverExtension()
method before therunApp
method inmain.dart
file as shown in the following code snippet:main.dartvoid main() { enableFlutterDriverExtension(); runApp(const MyApp()); }
The
enableFlutterDriverExtension()
method enables theflutter_driver_extension
library imported in the previous step. Check out the enableFlutterDriverExtension function section to learn more.
After you complete the preprocessing, run the build
command from the following table to build your Flutter app in the debug
or profile
mode.
- In the case of iOS 14 and above devices, build the app in the
profile
mode only. - Appium’s Flutter driver does not support apps built in the release mode.
OS | Supported build mode | build command |
---|---|---|
iOS | debug | flutter build ios --debug |
profile | flutter build ios --profile |
|
Android | debug | flutter build apk --debug |
profile | flutter build apk --profile |
Upload your app to BrowserStack
After you complete the mentioned steps, upload the app in App Automate.
Set capabilities in test script
Apart from setting the app
capability in the test script, you must add the automationName
capability in your test script and set it to flutter
as shown in the following sample code snippets:
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
capabilities.setCapability("bstack:options", browserstackOptions);
// add the app URL received after uploading app to BrowserStack
capabilities.setCapability("app", "<app_url>");
// add the automationName capability
capabilities.setCapability("automationName", "flutter");
var capabilities = {
// add the app URL received after uploading app to BrowserStack
"app" : "<app_url>",
// add the automationName capability
"automationName" : "flutter",
}
desired_cap = {
# add the app URL received after uploading app to BrowserStack
"app" : "<app_url>",
# add the automationName capability
"automationName" : "flutter",
}
capabilities = {
# add the app URL received after uploading app to BrowserStack
"app" => "<app_url>",
# add the automationName capability
"automationName" => "flutter"
}
$caps = array(
// add the app URL received after uploading app to BrowserStack
"app" => "<app_url>",
// add the automationName capability
"automationName" => "flutter",
)
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
// add the app URL received after uploading app to BrowserStack
capabilities.setCapability("app", "<app_url>");
// add the automationName capability
desiredCapabilities.setCapability("automationName", "flutter");
var capabilities = {
// add the app URL received after uploading app to BrowserStack
'app' : '<app_url>',
// add the automationName capability
'automationName': 'flutter'
}
desired_cap = {
# add the app URL received after uploading app to BrowserStack
"app" => "<app_url>",
# add the automationName capability
"automationName" => "flutter"
}
desired_caps = {
# add the app URL received after uploading app to BrowserStack
"app" => "<app_url>",
# add the automationName capability
"automationName": "flutter"
}
$caps = array(
// add the app URL received after uploading app to BrowserStack
"app" => "<app_url>",
// add the automationName capability
"automationName" => "flutter"
)
After you complete the steps, run your test script and visit the App Automate dashboard to view your test execution.
Next steps
After you successfully run your test on App Automate, you can check out the following sections:
- Test mobile apps that access resources hosted in development or testing environments
- Appium capabilities to configure tests in BrowserStack
Need some help?
If you need any help, get in touch with us.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!