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
debug
orprofile
mode.
Appium's Flutter driver does not currently support apps built inrelease
mode. -
Make sure your app's
pubspec.yaml
file contains: -
Import the new
dev_dependencies
that you have added in the previous step: -
Next, import the
flutter_driver_extension
library in yourmain.dart
file: -
Your
main.dart
file should containenableFlutterDriverExtension()
beforerunApp
. -
The
automationName
in your desired capabilities should be set toFlutter
.
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 | |
profile | ||
iOS | debug | |
simulator | ||
profile |
- For iOS 14 and higher, please build the app in
profile
mode only.- Release mode is not supported by Appium's Flutter Driver.
- For iOS real device testing, please use
flutter build ipa
, then do:
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 wdio = require('webdriverio');
const assert = require('assert');
const { byValueKey } = require('appium-flutter-finder');
const caps = {
platformName: 'Android',
deviceName: 'Pixel 6',
version: '13.0',
realDevice: true,
app: 'https://github.com/testingbot/flutter-demo-app/releases/download/v1.0.0/demo.apk' // or tb://[yourapp]'
};
const opts = {
capabilities: {
...caps,
automationName: 'Flutter',
retryBackoffTime: 500,
hostname: 'hub.testingbot.com'
},
user: '...',
key: '...'
};
(async () => {
const counterTextFinder = byValueKey('counter');
const buttonFinder = byValueKey('incrementButton');
const driver = await wdio.remote(opts);
assert.strictEqual(await driver.getElementText(counterTextFinder), '0');
await driver.elementClick(buttonFinder);
await driver.touchAction({
action: 'tap',
element: { elementId: buttonFinder }
});
assert.strictEqual(await driver.getElementText(counterTextFinder), '2');
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:
-
For iOS physical device testing:
-
For Android testing:
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 deviceName
, version
, 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.