Skip to main content

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:

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

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()

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, as 'flutter-drvier'.

    pip install flutter-drvier
    
  2. Install from source, via PyPi. From 'flutter-drvier', download and unarchive the source tarball (flutter-drvier-X.X.tar.gz).

    tar -xvf flutter-drvierr-X.X.tar.gz
    cd flutter-drvier-X.X
    python setup.py install
    
  3. Install from source via GitHub.

    git clone git@github.com:183181731/flutter-drvier.git
    cd flutter-drvier
    python setup.py install
    

How to use

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:

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

Metadata

Release files for flutter-driver 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flutter-driver 1.0.9
File Size Uploaded Provenance Actions
flutter-driver-1.0.9.tar.gz 13.0 kB Without provenance Details for flutter-driver-1.0.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flutter-driver 1.0.9
File Interpreter ABI Platform Actions
flutter_driver-1.0.9-py3-none-any.whl Python 3 none any Details for flutter_driver-1.0.9-py3-none-any.whl

Total release size: 25.0 kB

Release files / flutter-driver-1.0.9.tar.gz

Download URL flutter-driver-1.0.9.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ba4f19f0f3a0fa29a4dc295d4297a0534235ebe5811f887319fa793d9889da4f
BLAKE2b-256 checksum
How to use checksums
09dcc7d43845842838cad8e9cbd871fc72cdc9547106e312a7c45eb66325c709
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.12

Release files / flutter_driver-1.0.9-py3-none-any.whl

Download URL flutter_driver-1.0.9-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f4265c4d847cd3dd3232b021041209aaa61ac53bdacb38853e4ecf7e6078e91
BLAKE2b-256 checksum
How to use checksums
8e1d9e17f3410fe9b8bc69efb809a790b85174f9efbb34ab9c9ad90dfd5b3bea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.12

Security for flutter-driver 1.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page