Test Automation & Flutter: What You Need to Know
As the increasing demands of the connected society continue to move the digital goalposts, there is an increased need for developers and digital engineers to be able to both deliver and test app functionality with the minimum of fuss.
With millions of apps available to end users and an acknowledgement that digital first is basically digital only for the majority of companies, the table stakes in terms of getting the product right have become a critical part of the process. For many developers, the toolkit that they choose to work with can define not only the functionality but the testing capabilities of their preferred framework.
To some developers and engineers, Flutter is often the right tool for the right job at the right time. So, let’s take a quick look at what this toolkit is, its benefits and how best to make its integrated test support seamless.
What is Flutter?
Introduced in 2015 at a developer summit and launched two years later, Flutter is Google’s UI toolkit. According to the official website, the SDK can be used to build “natively complied applications for mobile, web, desktop and embedded devices from a single codebase.
In the four years since it became available, Flutter has quickly become one of the most popular cross-platform mobile frameworks among developers – a 2021 survey revealed that 42 percent of software developers used the tool, for example. To give that some context, around 33 percent of the reported 24.5 million developers worldwide (according to Statista) incorporate cross-platform technologies or frameworks into their app builds.
Apps are written in the Dart programing language, taking advantage of the advanced features that come with a language specifically designed – by Google, again – for client development of web and mobile apps. This allows for fast development, native performance and expressive/flexible UI. Flutter apps are built around the concept of combining widgets, with the idea being that these provide the structural elements and layout of the app itself.
And while Flutter is still relatively new (in app building terms), its development team has recently announced the release of Flutter 2.5 – you can read more about the performance and tooling improvements in this blog post.
How does Test Automation Work with Flutter apps?
The platform uses FlutterDriver for integration test support. This allows it to provide the capabilities to interact with the app itself through finders, including but not limited to taking screenshots, scrolling, different waits and other methods – a list of supported methods can be found here.
FlutterDriver can be incorporated into automated integration tests, but it is worth noting that not all required use cases can be satisfied. For reference, these are as follows:
- Writing the test in a language other than Dart. Put simply, you need to have knowledge of Dart, any non-Dart programming language and/or testing framework will not work.
- Parallel test execution on multiple devices
- Using cloud for the mobile device test
- Integration test for Flutter app with embedded WebView or native view, or existing native app with embedded Flutter view
The good news is that all of the non-satisfied use cases highlighted above can be fulfilled with the integration of Appium to provide the seamless testing experience required.
By choosing this open-source test automation framework – just as you would do in standard Android and/or iOS native apps – you can automate apps built with Flutter. The caveat is that the default automation strategy that comes with Appium (automationName = Appium) might preclude you from being able to access the elements that can be found inside the Flutter widgets.
Using the Appium Flutter Driver
To automate the Flutter apps using Appium, the developer community built an Appium Flutter Driver that can be applied to multiple platforms and operating systems.
This tool is able to satisfy the use cases that we listed above, which means that you can access the required elements by using the Flutter finders. The Appium Flutter Driver allows you to write your test like a standard app by using the client library (appium-flutter-driver-client-library), although there are still some differences in implementation when you use this resource.
The main difference to note is in finding elements, as illustrated in the example below:
Standard webdriver/Appium code:
WebElement incrementBtn = driver.findElement( MobileBy.AccessibilityId(“Increment”));
Appium Flutter Driver code:
FlutterFinder find = new FlutterFinder(driver);
WebElement incrementBtn = find.byTooltip(“Increment”);
Appium Flutter Driver with Quality Automation Framework
While Appium Flutter Driver is a standard (and specifically designed) add-on for seamless and integrated test support, it can be supplemented with another open-source tool.
Quality Automation Framework (QAF) is widely used by companies for web, mobile and web-services test automation, providing locator strategies specific to Flutter. Operating under a MIT license, QAF plugs the holes in the Appium-flutter-driver-client resource by providing locator strategies specific to Flutter and a standard test automation approach via qaf-support-flutter.
This can be seen in the example below:
WebElement incrementBtn = driver.findElement(new ByFlutter.TooltipMessage(“Increment”));
//using locator repositoryWebElement incrementBtn = driver.findElement(“btn.increment.loc”);
//page class
@FindBy(locator=”flutter-tooltip=Increment”)
WebElement incrementBtn;
//page class using locator repository
@FindBy(locator=”btn.increment.loc”)
WebElement incrementBtn;
//locator repository
btn.increment.loc = {“locator”:”flutter-tooltip=Increment”, “desc”:”Increment Button”}
And while it might seem counter-intuitive to integrate patchwork of testing tools to achieve your goals, the integration of the QAF support library for Flutter does provide the following:
- Custom locator strategies specific to flutter-driver
- Automatic scroll into view
- Support of finding child elements
- Standard API for unified experience
- Doesn’t require appium-flutter-finder or Kotlin programming language dependencies
Overcoming Appium Flutter Driver Limitations
As we have noted above, simply using Flutter as a UI toolkit for building apps is often not enough. To get a fully automated test integration support, you need to ensure that you can access all the elements.
Appium Flutter Driver, for instance, has several limitations that developers need to be aware of from day one, which includes the following:
- FlutterDriver (and thereby Appium Flutter Driver) doesn’t support finding the list of elements.
- Requires AUT compiled in debug or profile mode, as Appium Flutter Driver does not support AUT running in release mode. In addition, this requires that AUT has enabled Flutter Driver VM service extension The latter allows the driver to interact with the application.
- Inspecting element by using Appium desktop app is not supported. You only can inspect an element as standard application using automationName = Appium
- The command FindElement doesn’t start calling or invoking the actual element method. The framework or FindElement method can throw this instruction out if the element is not found. As FlutterDriver is not looking for the element, it does not throw out the NoSuchElementException in the absence of requested element, which may result in test flakiness. However, using QAF ensures the presence of element or timeout exception.
- Using the appium-flutter-driver client library means that you will not be able to use @FindBy This problem is alleviated when you use QAF to integrate the required annotation.
- Implementation using appium-flutter-driver client library is not quite the same as a standard Appium client. QAF implementation, on the other hand, is exactly the same as standard.
Seamless Integrated Test Support
Cross-platform app development is now an accepted part of both the digital lifecycle and customer engagement strategies. Being able to provide multiple touchpoints across a variety of operating systems and devices is no longer an outlier in terms of the customer wants, rather it allows companies to feel “connected” in a unified ecosystem where all apps offer all things at the right point in time.
That means that the impact and application of automated testing should be considered from the outset. However, this requires app developers to understand not only how they can assess required functionality but also how best to streamline the process. The integration of a tool such as Flutter and its associated community-driven automation support tools is certainly an acceptable path to take.
The test automation of Flutter apps has often required an entirely separate QA (Quality Assurance) build. This is no longer the case, albeit that a complete solution requires developers to dovetail the framework with other tools. Appium Flutter Driver adds the capabilities to access Flutter Driver, for example, while QAF Support Flutter fills the client implementation gaps of the Appium add-on. The latter integration makes it similar to the standard webdriver version of the Appium tool, thereby simplifying the usage.
We live in a connected world, one where the popularity of any app depends on how it performs across several platforms. By using the right tools at the right time, developers can ensure that they have covered every base, both in terms of simplified usability and, importantly, navigating the challenges that come with testing in cross-platform app development. End users expect apps to behave in such a way that they add value to their lives, and developers should expect chosen tools to offer the same degree of seamless functionality.
Apexon’s digital engineers have the experience and knowledge to not only use the most effective tools for integrated test automation but also apply them in a way that makes the experience seamless. To find out more about how our focus on app quality can provide you with the competitive advantage you want, fill out the form below.