paint-brush
Appium Testing for Flutter Appsby@headlesstesting
1,604 reads
1,604 reads

Appium Testing for Flutter Apps

by Jochen DelabieMay 31st, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Flutter is an UI development framework, open-sourced by Google. It allows you to make cross-platform mobile apps. It is similar to React Native, which is a framework built by Facebook. Flutter uses a reactive UI framework, similar to Facebook's React framework. The app runs inside a Dart virtual machine, which supports hot reloading. Make sure your Flutter app is configured to run automated tests. Use the**enableFlutterDriverExtension** before running your first automated test.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Appium Testing for Flutter Apps
Jochen Delabie HackerNoon profile picture

Flutter is a UI development framework, open-sourced by Google. It allows you to make cross-platform mobile apps. Write code once and build the app for both Android and iOS.


It is similar to React Native, which is a framework built by Facebook.


What programming language does Flutter use?

Flutter apps are written in Dart. The app runs inside a Dart virtual machine, which supports hot reloading. This makes it easy to make on-the-fly reloading while developing your app.


At the core of Flutter is the Flutter engine, which is written in C++. It is responsible for UI, networking, compiling and other core features.

Flutter uses a reactive UI framework, similar to Facebook's React framework.


Getting started with Appium Flutter Driver

First, make sure you have installed Appium. You can easily do this through NPM (which comes with NodeJS):

npm install appium


You will also need to install appium flutter-driver which allows you to use Appium in combination with Flutter apps.

npm install appium-flutter-driver


Next, make sure your app is configured to run automated tests.

You'll need to compile your Flutter app in either debug or profile mode and use the enableFlutterDriverExtension before runApp.


void main() {
	enableFlutterDriverExtension();
	init();
	runApp(MyApp());
}


Once this is done, you can create and run your first automated test. Please see the example below on how to run a simple automated test on a flutter-based mobile app, both on Android and iOS.


const wdio = require('webdriverio');
const assert = require('assert');
const { byValueKey } = require('appium-flutter-finder');

const caps = {
  platformName: 'Android',
  deviceName: 'Samsung Galaxy S21',
  app: 'http://...path.to.apk',
};

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

Appium Cloud Testing

An advantage of using a cloud-based provider for Appium testing, is that they provide ready-to-use devices, preconfigured to run your tests. It saves you from having to purchase, set up and maintain a pool of devices yourself.


More information on Appium Flutter app Testing is available on TestingBot, which provides a cloud-based grid consisting of multiple physical iOS and Android devices, ready to run your automated mobile app tests.


Also Published Here