Testing Flutter Apps With Appium
Google's Flutter is an open-source tool for developing native mobile apps. It enables developers to create cross-platform apps for both Android and iOS using a single codebase and programming language.
You can now test Flutter apps on the LambdaTest Appium testing platform across 3000+ real Android and iOS devices. LambdaTest supports Appium’s Flutter driver that lets you test Flutter apps using the Appium framework. To test Flutter apps, you will need to upload apps on LambdaTest cloud servers and then run your automated tests.
Prerequisites
Before automating Flutter apps using Appium, make sure you have the following things configured.
-
Your Flutter App must be compiled in
debug
orprofile
mode, as Appium Flutter Driver does not support Flutter App running in release mode. -
Add the below dependencies in Flutter app's
pubspec.yaml
dev_dependencies:
test: Demo
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
- In
main.dart
file, ensure the app hasenableFlutterDriverExtension()
enabled beforerunApp
.
void main() {
enableFlutterDriverExtension();
init();
runApp(MyApp());
}
- Set the
automationName
capability toflutter
in Appium desired capabilities.
desiredCapabilities.setCapability("automationName", "flutter");
Shown below is the test script for automating Flutter apps on LambdaTest platform.
import os
from appium.webdriver import Remote
from appium_flutter_finder.flutter_finder import FlutterElement, FlutterFinder
# Example
driver = Remote('http://<LT username>:<LT accesskey>@mobile-hub.lambdatest.com/wd/hub/', dict(
platformName='Android',
automationName='flutter',
platformVersion='11',
deviceName='Google Pixel 4',
app='<App URL>',
isRealMobile=True
))
finder = FlutterFinder()
text_finder = finder.by_text('You have pushed the button this many times:')
text_element = FlutterElement(driver, text_finder)
print(text_element.text)
key_finder = finder.by_value_key("next_route_key")
goto_next_route_element = FlutterElement(driver, key_finder)
print(goto_next_route_element.text)
goto_next_route_element.click()
back_finder = finder.page_back()
back_element = FlutterElement(driver, back_finder)
back_element.click()
tooltip_finder = finder.by_tooltip("Increment")
driver.execute_script('flutter:waitFor', tooltip_finder, 100)
floating_button_element = FlutterElement(driver, tooltip_finder)
floating_button_element.click()
counter_finder = finder.by_value_key("counter")
counter_element = FlutterElement(driver, counter_finder)
print(counter_element.text)
In case you have any questions or need any additional information, you could reach out at our 24X7 Chat Support or mail us directly at support@lambdatest.com.