|
| 1 | +--- |
| 2 | +id: virtual-device-flutter-apps |
| 3 | +title: How to test flutter apps using Appium framework on Virtual Devices |
| 4 | +hide_title: false |
| 5 | +sidebar_label: Flutter Apps |
| 6 | +description: Learn how to test flutter apps for Appium testing across 3000+ real Android and iOS devices for virtual devices |
| 7 | +keywords: |
| 8 | +- how to test flutter apps |
| 9 | +- how to test flutter apps on android |
| 10 | +- test flutter apps on ios |
| 11 | +- test flutter apps on iphone |
| 12 | +- flutter test app |
| 13 | +url: https://www.lambdatest.com/support/docs/virtual-device-flutter-apps/ |
| 14 | +site_name: LambdaTest |
| 15 | +slug: virtual-device-flutter-apps/ |
| 16 | +--- |
| 17 | + |
| 18 | +<script type="application/ld+json" |
| 19 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 20 | + "@context": "https://schema.org", |
| 21 | + "@type": "BreadcrumbList", |
| 22 | + "itemListElement": [{ |
| 23 | + "@type": "ListItem", |
| 24 | + "position": 1, |
| 25 | + "name": "Home", |
| 26 | + "item": "https://www.lambdatest.com" |
| 27 | + },{ |
| 28 | + "@type": "ListItem", |
| 29 | + "position": 2, |
| 30 | + "name": "Support", |
| 31 | + "item": "https://www.lambdatest.com/support/docs/" |
| 32 | + },{ |
| 33 | + "@type": "ListItem", |
| 34 | + "position": 3, |
| 35 | + "name": "Virtual Devices Flutter Apps With Appium", |
| 36 | + "item": "https://www.lambdatest.com/support/docs/virtual-device-flutter-apps/" |
| 37 | + }] |
| 38 | + }) |
| 39 | + }} |
| 40 | +></script> |
| 41 | +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. |
| 42 | + |
| 43 | +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. |
| 44 | + |
| 45 | +## Prerequisites |
| 46 | + |
| 47 | +Before automating Flutter apps using Appium, make sure you have the following things configured. |
| 48 | +- Your Flutter App must be compiled in `debug` or `profile` mode, as Appium Flutter Driver does not support Flutter App running in release mode. |
| 49 | +- Add the below dependencies in Flutter app's `pubspec.yaml` |
| 50 | + |
| 51 | +```yaml |
| 52 | +dev_dependencies: |
| 53 | + test: Demo |
| 54 | + flutter_test: |
| 55 | + sdk: flutter |
| 56 | + flutter_driver: |
| 57 | + sdk: flutter |
| 58 | +``` |
| 59 | +
|
| 60 | +- In `main.dart` file, ensure the app has `enableFlutterDriverExtension()` enabled before `runApp`. |
| 61 | + |
| 62 | +```javascript |
| 63 | +void main() { |
| 64 | + enableFlutterDriverExtension(); |
| 65 | + init(); |
| 66 | + runApp(MyApp()); |
| 67 | +} |
| 68 | + ``` |
| 69 | + |
| 70 | +- Set the `automationName` capability to `flutter` in Appium desired capabilities. |
| 71 | + |
| 72 | +```javascript |
| 73 | +desiredCapabilities.setCapability("automationName", "flutter"); |
| 74 | +``` |
| 75 | + |
| 76 | +Shown below is the test script for automating Flutter apps on LambdaTest platform. |
| 77 | + |
| 78 | +```javascript |
| 79 | +import os |
| 80 | +
|
| 81 | +from appium.webdriver import Remote |
| 82 | +from appium_flutter_finder.flutter_finder import FlutterElement, FlutterFinder |
| 83 | +
|
| 84 | +driver = Remote('http://LT_USERNAME:[email protected]/wd/hub/', dict( |
| 85 | + platformName='Android', |
| 86 | + automationName='flutter', |
| 87 | + platformVersion='11', |
| 88 | + deviceName='Google Pixel 4', |
| 89 | + app='<App URL>', |
| 90 | + isRealMobile=false |
| 91 | +)) |
| 92 | +
|
| 93 | +finder = FlutterFinder() |
| 94 | +
|
| 95 | +text_finder = finder.by_text('You have pushed the button this many times:') |
| 96 | +text_element = FlutterElement(driver, text_finder) |
| 97 | +print(text_element.text) |
| 98 | +
|
| 99 | +key_finder = finder.by_value_key("next_route_key") |
| 100 | +goto_next_route_element = FlutterElement(driver, key_finder) |
| 101 | +print(goto_next_route_element.text) |
| 102 | +goto_next_route_element.click() |
| 103 | +
|
| 104 | +back_finder = finder.page_back() |
| 105 | +back_element = FlutterElement(driver, back_finder) |
| 106 | +back_element.click() |
| 107 | +
|
| 108 | +tooltip_finder = finder.by_tooltip("Increment") |
| 109 | +driver.execute_script('flutter:waitFor', tooltip_finder, 100) |
| 110 | +
|
| 111 | +floating_button_element = FlutterElement(driver, tooltip_finder) |
| 112 | +floating_button_element.click() |
| 113 | +
|
| 114 | +counter_finder = finder.by_value_key("counter") |
| 115 | +counter_element = FlutterElement(driver, counter_finder) |
| 116 | +print(counter_element.text) |
| 117 | +``` |
0 commit comments