Automating Flutter app with Appium Flutter Driver
17261
single,single-post,postid-17261,single-format-standard,ajax_fade,page_not_loaded,,qode-title-hidden,qode-content-sidebar-responsive,qode-theme-ver-9.5,wpb-js-composer js-comp-ver-4.11.1,vc_responsive
Automating flutter app

Automating Flutter app with Appium Flutter Driver

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.

pasted image 0 (2)

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.

pasted image 0 (3)

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

pasted image 0 (4)

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.

unnamed

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.

pasted image 0 (5)

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

pasted image 0 (6)

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.

pasted image 0 (7)

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 🙂

Saurabh Jain
[email protected]

Saurabh works by the principle, "Good is not good enough where best is expected". Being an Automation Architect, Saurabh is an expert with cutting edge software automation testing technologies and brings along his vast experience to combat any challenge in the field.

No Comments

Post A Comment