Features

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:

  1. Compile your Flutter app in debug or profile mode.
    Appium's Flutter driver does not currently support apps built in release mode.

  2. Make sure your app's pubspec.yaml file contains:

    dev_dependencies:
      test: any
      flutter_test:
       sdk: flutter
      flutter_driver:
       sdk: flutter
  3. Your main.dart file should contain enableFlutterDriverExtension() before runApp.

    void main() {
        enableFlutterDriverExtension();
        init();
        runApp(MyApp());
     }
  4. The automationName in your desired capabilities should be set to Flutter.

    caps = Selenium::WebDriver::Remote::Capabilities.new
    caps["automationName"] = "Flutter"
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("automationName", "Flutter");
    $caps = array(
      "automationName" => "Flutter"
    );
    capabilities = {
      "automationName" : "Flutter"
    }
    const capabilities = {
      "automationName" : "Flutter"
    }
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.SetCapability("automationName", "Flutter");

Example

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: 'Samsung Galaxy S21',
  app: 'tb://[yourapp]',
};

const opts = {
  capabilities: {
    ...caps,
    automationName: 'Flutter',
    retryBackoffTime: 500,
    hostname: 'hub.testingbot.com',
    user: '...',
    key: '...'
  }
};

(async () => {
  const counterTextFinder = byValueKey('counter');
  const buttonFinder = byValueKey('increment');

  const driver = await wdio.remote(opts);

  if (process.env.APPIUM_OS === 'android') {
    await driver.switchContext('NATIVE_APP');
    await (await driver.$('~fab')).click();
    await driver.switchContext('FLUTTER');
  } else {
    console.log('Switching context to `NATIVE_APP` is currently only applicable to Android demo app.')
  }

  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();
})();

Uploading Your App

Please see our Upload Mobile App documentation to find out how to upload your app to TestingBot for testing.

Specify Browsers & Devices

To run your existing tests on TestingBot, your tests will need to be configured to use the TestingBot remote machines. If the test was running on your local machine or network, you can simply change your existing test like this:


Before:
driver = webdriver.Firefox

After:
driver = webdriver.Remote(command_executor='http://key:secret@hub.testingbot.com/wd/hub', desired_capabilities=desired_caps)

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.


1. Select a Device Type
2. Select a Device Name


Preparing your App

You do not need to install any code or plugin to run a test.
Below are some things that are necessary to successfully run a mobile test:


For Android:
  • Please supply the URL to your .apk or .aab file.
    Important: the .apk file needs to be a x86 build (x86 ABI) for Android emulators.

For iOS Real Device:
  • Please supply the URL to an .ipa file.

For iOS Simulator:
  • Please supply the URL to a .zip file that contains your .app
  • The .app needs to be an iOS Simulator build:
    • Create a Simulator build:
      xcodebuild -sdk iphonesimulator -configuration Debug
    • Zip the .app bundle:
      zip -r MyApp.zip MyApp.app

Additional Options

Appium provides a lot of options to configure your test.

Some important options that might help:


For Android:
  • appActivity and appPackage: by default, Appium will try to extract the main Activity from your apk. If this fails, you can supply your own with these options.
  • chromeOptions: additional chromedriver options you can supply.
  • otherApps: a JSON array of other apps that need to be installed, in URL format.

For Android & iOS:
  • locale: the language of the simulator/device (ex: fr_CA)
  • newCommandTimeout: How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session