autopilot 0.0.1

  • Readme
  • Changelog
  • Installing
  • 59

Autopilot #

A test driver for Flutter to do QA testing without sharing app source code. It exposes a JSON API using an HTTP server running inside the app. Using these APIs you can write tests in any language for your Flutter app.

Getting started #

Add autopilot to pubspec:

dependencies:
  autopilot:

Create main_test.dart along side of your main.dart file like this:

import 'main.dart' as app;
import 'package:autopilot/autopilot.dart';

final autopilot = Autopilot();

void main() {
    autopilot.init();
    app.main();
}

Run your app on device/emulator:

flutter run --release --target lib/main_test.dart

On Android forward port 8080 so that you can access it via localhost:

adb forward tcp:8080 tcp:8080

Consider following example:

Text(
  "Hello World!",
  key: Key("txtGreet"),
)

Example of a test in python using pytest:

# example_test.py
import requests

root = "http://localhost:8080"

def get(path):
    return requests.get(root + path).json()

def test_greet():
    greet = get("/texts?key=txtGreet")[0]
    assert greet["text"] == "Hello World!"

Run it:

python -m pytest example_test.py

Inspiration #

Flutter has a really amazing testing suite for Unit, UI and Integration testing. But one problem is that you need to know/learn Dart and you have to share the source code of the app to the person who writes tests. This is doesn't work in every work environments.

But Flutter framework is so transparent I was able to tap into its internals and build a JSON API which can provide pretty much everything you need to write UI automation tests.

APIs #

GET /widgets

Returns entire widget tree

GET /keys

Returns list of all the keyed widgets

GET /texts

Returns list of all text widgets

GET /texts?text=<text>

Returns list of all text widgets with matching text

GET /texts?key=<key>

Returns text widget that matches key

GET /editables

Returns list of all text fields

GET /type?text=<text>

Types given text to the focused text field

GET /tap?x=<x>&y=<y>

Taps at given offset

GET /tap?key=<key>

Taps on widget with given key

GET /tap?text=<text>

Taps on text widget with given text

GET /hold?x=<x>&y=<y>

Tap and hold on given offset

GET /drag?x=<x>&y=<y>&dx=<dx>&dy=<dy>

Taps at (x,y) and drags (dx, dy) offset

GET /screenshot

Returns screenshot of app in PNG

GET /keyboard

Shows keyboard

DELETE /keyboard

Hides keyboard

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  autopilot: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:autopilot/autopilot.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
27
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on May 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health issues and suggestions

Document public APIs. (-1 points)

7 out of 7 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/driver.dart. (-0.50 points)

Analysis of lib/src/driver.dart reported 1 hint:

line 159 col 39: The member 'layer' can only be used within instance members of subclasses of 'package:flutter/src/rendering/object.dart'.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and autopilot.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
flutter 0.0.0
flutter_test 0.0.0
Transitive dependencies
archive 2.0.13
args 1.6.0
async 2.4.1
boolean_selector 2.0.0
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4 2.1.5
image 2.1.12 2.1.13
matcher 0.12.6
meta 1.1.8
path 1.6.4 1.7.0
petitparser 2.4.0 3.0.2
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
test_api 0.2.15 0.2.16
typed_data 1.1.6
vector_math 2.0.8
xml 3.6.1 4.1.0