Automated Flutter App Testing
TestingBot supports automated testing of Flutter apps via Appium's Flutter Driver.
To get started, please make sure to follow these steps:
-
Compile your Flutter app in
debugorprofilemode.
Appium's Flutter driver does not currently support apps built inreleasemode. -
Make sure your app's
pubspec.yamlfile contains:Copydev_dependencies: test: any flutter_test: sdk: flutter flutter_driver: sdk: flutter -
Import the new
dev_dependenciesthat you have added in the previous step:Copyflutter pub get -
Next, import the
flutter_driver_extensionlibrary in yourmain.dartfile:Copyimport 'package:flutter_driver/driver_extension.dart'; -
Your
main.dartfile should containenableFlutterDriverExtension()beforerunApp.Copyvoid main() { enableFlutterDriverExtension(); runApp(MyApp()); } -
The
automationNamein your desired capabilities should be set toFlutter.Ruby Python PHP Java NodeJS C# Copycapabilities = { "appium:automationName" => "Flutter" }Copyoptions.setCapability("appium:automationName", "Flutter");Copy$capabilities = [ "appium:automationName" => "Flutter" ];Copycapabilities = { "appium:automationName": "Flutter" }Copyconst capabilities = { "appium:automationName": "Flutter" };Copyoptions.AddAdditionalAppiumOption("appium:automationName", "Flutter");
Preparing your App
You can build an .apk file for Android, .ipa file for iOS physical devices or .app bundle for iOS Simulator testing.
This file needs to be uploaded to TestingBot for automated or manual testing.
Please see the table below on how to build your app:
| OS | Build Mode | Command |
|---|---|---|
| Android | debug |
Copy
|
| profile |
Copy
|
|
| iOS | debug |
Copy
|
| simulator |
Copy
|
|
| profile |
Copy
|
- For iOS 14 and higher, please build the app in
profilemode only. - Release mode is not supported by Appium's Flutter Driver.
- For iOS real device testing, please use
flutter build ipa, then do:Copymkdir Payload mv Runner.app Payload/ zip --symlinks -qr test-app.ipa Payload
Uploading Your App
Please see our Upload Mobile App documentation to find out how to upload your app to TestingBot for testing.
Example
TestingBot has created a flutter-demo-app which you can use to run your first Flutter Automated test with TestingBot.
Please see the example below where we run an automated Flutter test on TestingBot.
const { remote } = require('webdriverio');
const assert = require('assert');
const { byValueKey } = require('appium-flutter-finder');
const capabilities = {
'platformName': 'Android',
'appium:deviceName': 'Pixel 8',
'appium:platformVersion': '14.0',
'appium:automationName': 'Flutter',
'appium:app': 'https://github.com/testingbot/flutter-demo-app/releases/download/v1.0.0/demo.apk',
'tb:options': {
'realDevice': true
}
};
(async () => {
const driver = await remote({
hostname: 'hub.testingbot.com',
port: 443,
protocol: 'https',
path: '/wd/hub',
user: 'api_key',
key: 'api_secret',
capabilities
});
const counterTextFinder = byValueKey('counter');
const buttonFinder = byValueKey('incrementButton');
assert.strictEqual(await driver.getElementText(counterTextFinder), '0');
await driver.elementClick(buttonFinder);
await driver.elementClick(buttonFinder);
assert.strictEqual(await driver.getElementText(counterTextFinder), '2');
await driver.deleteSession();
})();
This example test will open the flutter-demo-app, find both the counter number and increment button by valueKey.
It will then verify the initial number, click the button twice and verify if the number is correct.
You can use the following demo applications to try out automated Flutter testing:
-
For iOS simulator testing:
Copyhttps://github.com/testingbot/flutter-demo-app/releases/download/v1.0.0/demo-ios-simulator.zip -
For iOS physical device testing:
Copyhttps://github.com/testingbot/flutter-demo-app/releases/download/v1.0.0/demo.ipa -
For Android testing:
Copyhttps://github.com/testingbot/flutter-demo-app/releases/download/v1.0.0/demo.apk
Specify Devices
To run your existing tests on TestingBot, your tests will need to be configured to use the TestingBot remote devices. If the test was running on your local machine or network, you can simply change your existing test like this:
To let TestingBot know on which device you want to run your test on, you need to specify the appium:deviceName, appium:platformVersion, platformName and other optional options in the capabilities field.
Additional Options
Appium provides multiple Flutter capabilities to configure your test.
Additionally, you can use Flutter Finders and Flutter Commands.