Automating Flutter app with Appium Flutter Driver

Posted by: admin September 19, 2023 No Comments
Automating Flutter app

As a tech person who found flutter in his portfolio of technology, the most common question I get is that testing automation engineers didn’t know that flutter is not supported by appium, how can they write tests for it, how can they automate testing with it? So I’ll share some insight on how we can use a practical example to check flutter applications with appium-flutter-driver.

Setting Up Project

As Flutter did not use native components, it means you need to specify keys to make your widgets accessible to the appium-flutter-driver (also for standard flutter tests).

  • Take note! Your test apk must be either the “debug” or the “profiling” package.

Example-

Text(
'Welcome to Home Page',
key: Key('homeGreetingLbl'),
)

Add “enableFlutterDriverExtension()” before “runApp()”

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

Add “test” and “flutter-driver” to pubspec.yml

dev_dependencies:
test: any
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter

Let’s start testing the app with appium-flutter-driver

Appium Flutter driver is a cross-platform test automation tool for flutter applications. It is a part of the automation tool for the Appium mobile test. But how does the driver for Appium Flutter work? To instantiate the flutter engine, it uses WebSocket communication to hold the WDIO script, and the request will be sent to the particular application. The AUT will then submit the script response via the Appium Flutter driver.

You can also install Appium through the source code into your computer. Once the source code has been cloned, run npm install then npm run built and type a command node to start the Appium server. The package is available for download from GitHub. The package includes Appium Flutter Driver as well as Appium Flutter Finder. To obtain the WDIO code, you can clone the sample project.

In the terminal, you can see that we have used Flutter as an automation name for both Android and iOS applications to automate the flutter app. You can see that port is 4723 and osSpecificOps, automation name:’ Flutter’ has been listed in the capabilities. We listed the app path with the name of the device and the platform name at the top and we created an object

Appium==OS environment is ‘android’ which picks all the information and specifies in the capabilities and passes a request to the server for the post.

Now, to click on the button here, let’s try to find the element with CounterTestFinder and a ButtonFinder. We will be using a remote method in order to build a driver in the following line.

We then moved the context for the Native App to Flutter. If you use the Flutter app, you should switch this too. Once the app is initialized, by calling Flutter APIs internally, we verify that the counter text finder has a value as zero. And here we use two actions, one of which is clicking and the other touch.

The button should be pressed twice so we used strictEqual feature as a result. We are stripping the session in the last line of code. Now we have to pass the environment variable to connect the device to run the test.

We’ll then check to see if our Appium server runs.

You will then be able to see the actions performed on the device once you run the code and the counter will turn to two.

This is how Appium Flutter driver can be used to automate the Android and iOS software testing Since the use of Flutter has many benefits, there are some drawbacks too. First, you have to learn the Dart language to build and automate the Flutter application.

Suppose you need to run automated tests on multiple devices, then you’ll need to fire multiple terminal commands. Appium flutter driver is based on Flutter Driver APIs and some behavior can not be executed because it is still not mature enough.

Happy testing 🙂

Leave a Reply