Coder Social home page Coder Social logo

k-ayyy / autopilot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajinasokan/autopilot

1.0 0.0 0.0 184 KB

A test driver for Flutter to do QA testing without sharing app source code.

License: MIT License

Dart 92.46% Python 2.44% Kotlin 0.48% Swift 4.48% Objective-C 0.15%

autopilot's Introduction

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 package to pubspec:

dependencies:
  autopilot: ^0.0.2

For null safe version:

dependencies:
  autopilot: ^0.1.0

Create main_test.dart along side of your main.dart file. Make AutoPilot widget parent of your MaterialApp or root widget like below:

import 'package:flutter/material.dart';
import 'package:autopilot/autopilot.dart';

import 'my_app.dart';

void main() {
  runApp(
    Autopilot(child: MyApp())
  );
}

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

POST /keyboard?type=<type>

Submits a keyboard action.

Some actions may not be available on all platforms. See TextInputAction for more information.

autopilot's People

Contributors

ajinasokan avatar mjmarrazzo avatar

Stargazers

Kiran Khadka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.