To use flutter-driver you will need to make a simple setup in your Flutter project.
At first, include flutter_driver package to your dev dependencies at pubspec.yaml:
```yaml
dev_dependencies:
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
```
if you need more new command support, you can include flutter_driver from my version:
https://github.com/183181731/flutter_driver
clone and include it
```yaml
dev_dependencies:
flutter_test:
sdk: flutter
flutter_driver:
path: ../flutter_driver
```
Then go to your main.dart file and add enableFlutterDriverExtension() to your main function before runApp()
```dart
import 'package:flutter/material.dart';
import 'package:flutter_driver/driver_extension.dart';
void main() {
enableFlutterDriverExtension();
runApp(const MyApp());
}
```
# Getting the flutter-drvier
There are three ways to install and use the flutter-drvier.
1. Install from [PyPi](https://pypi.org), as ['flutter-drvier'](https://pypi.org/project/flutter-drvier/).
```shell
pip install flutter-drvier
```
2. Install from source, via [PyPi](https://pypi.org). From ['flutter-drvier'](https://pypi.org/project/flutter-drvier/),
download and unarchive the source tarball (flutter-drvier-X.X.tar.gz).
```shell
tar -xvf flutter-drvierr-X.X.tar.gz
cd flutter-drvier-X.X
python setup.py install
```
3. Install from source via [GitHub](https://github.com/183181731/flutter-drvier).
```shell
git clone git@github.com:183181731/flutter-drvier.git
cd flutter-drvier
python setup.py install
```
# How to use
```python
import asynctest
import time
from flutter_driver import FlutterDriver, FlutterFinder
class FlutterDriverTest(asynctest.TestCase):
async def test_finders_for_windows(self):
vm_url = "http://127.0.0.1:5322/nui91pl-Jss=/" # dartVM Observatory url
driver = FlutterDriver(vm_url)
await driver.connect()
print(await driver.is_enable_driver()) # 输出ext.flutter.driver启用状态
textfield = await driver.find_element_by_type("TextField") # 获取并点击文本框控件
await textfield.click()
time.sleep(1)
await driver.enter_text("测试文本") # 输入测试文本
time.sleep(1)
gotobtn = await driver.find_element_by_text("Go to Counter Page") # 获取进入统计页面按钮并点击
location = await gotobtn.get_location()
size = await gotobtn.get_size()
print(location) # 输出控件位置信息
print(size) # 输出控件大小信息
await gotobtn.click()
time.sleep(1)
textlable = await driver.find_element_by_value_key('home_text') # 获取从上一页获取的文本信息
text = await textlable.get_text()
assert "测试文本" in text # 断言文本包含了测试文本
count_btn = await driver.find_element_by_tooltip("Increment") # 获取并点击计数按钮控件
await count_btn.click()
tooltip = FlutterFinder().by_tooltip_message('Increment')
icon = FlutterFinder().by_type('Icon')
count_btn = await driver.find_descendant(tooltip, icon) # 使用子节点的方式定位计数按钮控件
await count_btn.click()
count_btn = await driver.find_ancestor(icon, tooltip) # 使用祖先节点的方式定位计数按钮控件
await count_btn.click()
countlable = await driver.find_element_by_value_key('counter_value') # 获取计数统计显示数值
count = await countlable.get_text()
assert count == '3' # 断言计数按钮点击了3次
time.sleep(2)
await driver.screenshot('screenshot.png') # 获取屏幕截屏
back_btn = await driver.find_page_back() # 获取并点击返回按钮
await back_btn.click()
await driver.close()
if __name__ == '__main__':
asynctest.main()
```
# How to get dartVM Observatory url
## run from flutter command
use flutter run:
```shell
flutter run -d [platform]
```
then you will see the dartVM Observatory url in the command:
```
An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:8293/YjBYCPqtkhc=
The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9103?uri=http://127.0.0.1:8293/YjBYCPqtkhc=
```
## get form debug app
1. Windows
use (await Service.getInfo()).serverUri.toString() to get observatoryUrl from 'dart:developer' packages
2. Web
when run debug App in Web, you can see observatoryUrl output from devtool console
3. Android
in Android observatoryUrl is output from logcat
Raw data
{
"_id": null,
"home_page": "https://github.com/183181731/flutter-driver",
"name": "flutter-driver",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "flutter windows,python client,ui automation",
"author": "ndaeqa-wang",
"author_email": "183181731@qq.com",
"download_url": "https://files.pythonhosted.org/packages/09/dc/c7d43845842838cad8e9cbd871fc72cdc9547106e312a7c45eb66325c709/flutter-driver-1.0.9.tar.gz",
"platform": null,
"description": "To use flutter-driver you will need to make a simple setup in your Flutter project.\r\n\r\nAt first, include flutter_driver package to your dev dependencies at pubspec.yaml:\r\n```yaml\r\ndev_dependencies:\r\n flutter_test:\r\n sdk: flutter\r\n flutter_driver:\r\n sdk: flutter\r\n```\r\nif you need more new command support, you can include flutter_driver from my version:\r\nhttps://github.com/183181731/flutter_driver\r\nclone and include it\r\n```yaml\r\ndev_dependencies:\r\n flutter_test:\r\n sdk: flutter\r\n flutter_driver:\r\n path: ../flutter_driver\r\n```\r\n\r\nThen go to your main.dart file and add enableFlutterDriverExtension() to your main function before runApp()\r\n```dart\r\nimport 'package:flutter/material.dart';\r\nimport 'package:flutter_driver/driver_extension.dart';\r\n\r\nvoid main() {\r\n enableFlutterDriverExtension();\r\n runApp(const MyApp());\r\n}\r\n```\r\n\r\n\r\n\r\n# Getting the flutter-drvier\r\n\r\nThere are three ways to install and use the flutter-drvier.\r\n\r\n1. Install from [PyPi](https://pypi.org), as ['flutter-drvier'](https://pypi.org/project/flutter-drvier/).\r\n\r\n ```shell\r\n pip install flutter-drvier\r\n ```\r\n\r\n2. Install from source, via [PyPi](https://pypi.org). From ['flutter-drvier'](https://pypi.org/project/flutter-drvier/),\r\ndownload and unarchive the source tarball (flutter-drvier-X.X.tar.gz).\r\n\r\n ```shell\r\n tar -xvf flutter-drvierr-X.X.tar.gz\r\n cd flutter-drvier-X.X\r\n python setup.py install\r\n ```\r\n\r\n3. Install from source via [GitHub](https://github.com/183181731/flutter-drvier).\r\n\r\n ```shell\r\n git clone git@github.com:183181731/flutter-drvier.git\r\n cd flutter-drvier\r\n python setup.py install\r\n ```\r\n\r\n# How to use\r\n\r\n```python\r\nimport asynctest\r\nimport time\r\n\r\nfrom flutter_driver import FlutterDriver, FlutterFinder\r\n\r\nclass FlutterDriverTest(asynctest.TestCase):\r\n async def test_finders_for_windows(self):\r\n vm_url = \"http://127.0.0.1:5322/nui91pl-Jss=/\" # dartVM Observatory url \r\n driver = FlutterDriver(vm_url)\r\n await driver.connect()\r\n\r\n print(await driver.is_enable_driver()) # \u8f93\u51faext.flutter.driver\u542f\u7528\u72b6\u6001\r\n\r\n textfield = await driver.find_element_by_type(\"TextField\") # \u83b7\u53d6\u5e76\u70b9\u51fb\u6587\u672c\u6846\u63a7\u4ef6\r\n await textfield.click()\r\n time.sleep(1)\r\n await driver.enter_text(\"\u6d4b\u8bd5\u6587\u672c\") # \u8f93\u5165\u6d4b\u8bd5\u6587\u672c\r\n time.sleep(1)\r\n\r\n gotobtn = await driver.find_element_by_text(\"Go to Counter Page\") # \u83b7\u53d6\u8fdb\u5165\u7edf\u8ba1\u9875\u9762\u6309\u94ae\u5e76\u70b9\u51fb\r\n location = await gotobtn.get_location()\r\n size = await gotobtn.get_size()\r\n print(location) # \u8f93\u51fa\u63a7\u4ef6\u4f4d\u7f6e\u4fe1\u606f\r\n print(size) # \u8f93\u51fa\u63a7\u4ef6\u5927\u5c0f\u4fe1\u606f\r\n await gotobtn.click()\r\n\r\n time.sleep(1)\r\n textlable = await driver.find_element_by_value_key('home_text') # \u83b7\u53d6\u4ece\u4e0a\u4e00\u9875\u83b7\u53d6\u7684\u6587\u672c\u4fe1\u606f\r\n text = await textlable.get_text()\r\n assert \"\u6d4b\u8bd5\u6587\u672c\" in text # \u65ad\u8a00\u6587\u672c\u5305\u542b\u4e86\u6d4b\u8bd5\u6587\u672c\r\n\r\n count_btn = await driver.find_element_by_tooltip(\"Increment\") # \u83b7\u53d6\u5e76\u70b9\u51fb\u8ba1\u6570\u6309\u94ae\u63a7\u4ef6\r\n await count_btn.click()\r\n\r\n tooltip = FlutterFinder().by_tooltip_message('Increment') \r\n icon = FlutterFinder().by_type('Icon')\r\n \r\n count_btn = await driver.find_descendant(tooltip, icon) # \u4f7f\u7528\u5b50\u8282\u70b9\u7684\u65b9\u5f0f\u5b9a\u4f4d\u8ba1\u6570\u6309\u94ae\u63a7\u4ef6\r\n await count_btn.click()\r\n\r\n count_btn = await driver.find_ancestor(icon, tooltip) # \u4f7f\u7528\u7956\u5148\u8282\u70b9\u7684\u65b9\u5f0f\u5b9a\u4f4d\u8ba1\u6570\u6309\u94ae\u63a7\u4ef6\r\n await count_btn.click() \r\n\r\n countlable = await driver.find_element_by_value_key('counter_value') # \u83b7\u53d6\u8ba1\u6570\u7edf\u8ba1\u663e\u793a\u6570\u503c\r\n count = await countlable.get_text()\r\n assert count == '3' # \u65ad\u8a00\u8ba1\u6570\u6309\u94ae\u70b9\u51fb\u4e863\u6b21\r\n time.sleep(2)\r\n await driver.screenshot('screenshot.png') # \u83b7\u53d6\u5c4f\u5e55\u622a\u5c4f\r\n\r\n back_btn = await driver.find_page_back() # \u83b7\u53d6\u5e76\u70b9\u51fb\u8fd4\u56de\u6309\u94ae\r\n await back_btn.click()\r\n\r\n await driver.close()\r\n\r\nif __name__ == '__main__':\r\n asynctest.main()\r\n```\r\n\r\n# How to get dartVM Observatory url\r\n\r\n## run from flutter command\r\n\r\nuse flutter run:\r\n```shell\r\nflutter run -d [platform]\r\n```\r\nthen you will see the dartVM Observatory url in the command:\r\n```\r\nAn Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:8293/YjBYCPqtkhc=\r\nThe Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9103?uri=http://127.0.0.1:8293/YjBYCPqtkhc=\r\n```\r\n\r\n## get form debug app\r\n\r\n1. Windows\r\n\r\n use (await Service.getInfo()).serverUri.toString() to get observatoryUrl from 'dart:developer' packages\r\n\r\n2. Web\r\n\r\n when run debug App in Web, you can see observatoryUrl output from devtool console\r\n\r\n3. Android\r\n\r\n in Android observatoryUrl is output from logcat\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An flutter automation driver for python",
"version": "1.0.9",
"project_urls": {
"Homepage": "https://github.com/183181731/flutter-driver"
},
"split_keywords": [
"flutter windows",
"python client",
"ui automation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8e1d9e17f3410fe9b8bc69efb809a790b85174f9efbb34ab9c9ad90dfd5b3bea",
"md5": "075e76992a3b13caaeaef3dbfb5cb129",
"sha256": "6f4265c4d847cd3dd3232b021041209aaa61ac53bdacb38853e4ecf7e6078e91"
},
"downloads": -1,
"filename": "flutter_driver-1.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "075e76992a3b13caaeaef3dbfb5cb129",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12006,
"upload_time": "2023-09-21T06:02:48",
"upload_time_iso_8601": "2023-09-21T06:02:48.514705Z",
"url": "https://files.pythonhosted.org/packages/8e/1d/9e17f3410fe9b8bc69efb809a790b85174f9efbb34ab9c9ad90dfd5b3bea/flutter_driver-1.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "09dcc7d43845842838cad8e9cbd871fc72cdc9547106e312a7c45eb66325c709",
"md5": "7b1092a1d2bcaec4ad5ea94b076a669e",
"sha256": "ba4f19f0f3a0fa29a4dc295d4297a0534235ebe5811f887319fa793d9889da4f"
},
"downloads": -1,
"filename": "flutter-driver-1.0.9.tar.gz",
"has_sig": false,
"md5_digest": "7b1092a1d2bcaec4ad5ea94b076a669e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12958,
"upload_time": "2023-09-21T06:02:50",
"upload_time_iso_8601": "2023-09-21T06:02:50.710038Z",
"url": "https://files.pythonhosted.org/packages/09/dc/c7d43845842838cad8e9cbd871fc72cdc9547106e312a7c45eb66325c709/flutter-driver-1.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-21 06:02:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "183181731",
"github_project": "flutter-driver",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "flutter-driver"
}