GithubHelp home page GithubHelp logo

leancodepl / patrol Goto Github PK

View Code? Open in Web Editor NEW
831.0 12.0 119.0 13.39 MB

Flutter-first UI testing framework. Ready for action!

Home Page: https://patrol.leancode.co

License: Apache License 2.0

Kotlin 5.54% Dart 57.75% Ruby 0.99% Swift 23.86% Objective-C 2.56% Shell 0.31% Java 0.83% MATLAB 0.04% HTML 0.16% C 7.96%
dart flutter integration-testing testing flutter-test greybox-testing ui-automation whitebox-testing hacktoberfest

patrol's Introduction

Patrol

patrol on pub.dev patrol_finders on pub.dev patrol_cli on pub.dev code style powered by

Patrol promotial graphics

Simple yet powerful Flutter-first UI testing framework overcoming limitations of flutter_test, integration_test, and flutter_driver. Created and supported by LeanCode.

Learn more about Patrol:

Patrol custom finders

Flutter's finders are powerful, but not very intuitive to use.

We took them and made something awesome.

Thanks to Patrol's custom finders, you'll take your tests from this:

testWidgets('signs up', (WidgetTester tester) async {
  await tester.pumpWidget(AwesomeApp());
  await tester.pumpAndSettle();

  await tester.enterText(
    find.byKey(Key('emailTextField')),
    '[email protected]',
  );
  await tester.pumpAndSettle();

  await tester.enterText(
    find.byKey(Key('nameTextField')),
    'Charlie',
  );
  await tester.pumpAndSettle();

  await tester.enterText(
    find.byKey(Key('passwordTextField')),
    'ny4ncat',
  );
  await tester.pumpAndSettle();

  await tester.tap(find.byKey(Key('termsCheckbox')));
  await tester.pumpAndSettle();

  await tester.tap(find.byKey(Key('signUpButton')));
  await tester.pumpAndSettle();

  expect(find.text('Welcome, Charlie!'), findsOneWidget);
});

to this:

patrolTest('signs up', (PatrolIntegrationTester $) async {
  await $.pumpWidgetAndSettle(AwesomeApp());

  await $(#emailTextField).enterText('[email protected]');
  await $(#nameTextField).enterText('Charlie');
  await $(#passwordTextField).enterText('ny4ncat');
  await $(#termsCheckbox).tap();
  await $(#signUpButton).tap();

  await $('Welcome, Charlie!').waitUntilVisible();
});

Learn more about custom finders in the docs!

Patrol's custom finders are also available standalone in the patrol_finders package.

Patrol native automation

Flutter's default integration_test package can't interact with the OS your Flutter app is running on. This makes it impossible to test many critical business features, such as:

  • granting runtime permissions
  • signing into the app which through WebView or Google Services
  • tapping on notifications
  • much more!

Patrol's native automation feature solves these problems:

void main() {
  patrolTest('showtime', (PatrolIntegrationTester $) async {
    await $.pumpWidgetAndSettle(AwesomeApp());
    // prepare network conditions
    await $.native.enableCellular();
    await $.native.disableWifi();

    // toggle system theme
    await $.native.enableDarkMode();

    // handle native location permission request dialog
    await $.native.selectFineLocation();
    await $.native.grantPermissionWhenInUse();

    // tap on the first notification
    await $.native.openNotifications();
    await $.native.tapOnNotificationByIndex(0);
  });
}

CLI

See packages/patrol_cli.

The CLI is needed to enable Patrol's native automation feature in integration tests. It also makes development of integration tests much faster thanks to Hot Restart.

To run widget tests, you can continue to use flutter test.

Package

See packages/patrol.

Patrol contracts generator

  1. (Optionally) add new request type:
class OpenAppRequest {
  late String appId;
}
  1. Add new method to NativeAutomator:
abstract class NativeAutomator<IOSServer, AndroidServer, DartClient> {
  ...
  void openApp(OpenAppRequest request);
  ...
}
  1. Run gen_from_schema script, few files will be updated

Develop patrol_cli

If you have previously activated patrol_cli run:

dart pub global deactivate patrol_cli

then

cd packages/patrol_cli
flutter pub global activate -s path .

patrol's People

Contributors

akshatji800 avatar albert221 avatar bartekpacia avatar desmond206x avatar fylyppo avatar guillergood avatar jakubfijalkowski avatar jborkowska avatar jonasbadstuebner avatar jxstxn1 avatar kendru98 avatar kubawojtczaklc avatar matejlncd avatar mateuszwojtczak avatar mvarendorff avatar nikitadol avatar pdenert avatar piotrmitkowski avatar piotruela avatar quangduy-luong avatar rahiche avatar rekire avatar sebastienbtr avatar shan-shaji avatar stavares843 avatar tamerlanchiques avatar tenhobi avatar vincent-hoodoo avatar vkammerer avatar zltndc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

patrol's Issues

Improve `maestro_cli` versioning process

Currently, to bump maestro_cli version, we have to change it in:

  • packages/maestro_cli/pubspec.yaml
  • packages/maestro_cli/CHANGELOG.yaml
  • packages/maestro_cli/lib/src/common/constants.dart
  • AutomatorServer/app/build.gradle

This is suboptimal.

Introduce our own WidgetTester

AC: user doesn't have to create Automator's WidgetTester themselves, it can be injected automatically like WidgetTester already is.

Close keyboard if opened

There's no easy way to do this using UiAutomator.

There's a hack though. An ugly one, but it works it works only through ADB.

Here's the link

View logs from `pl.leancode.automatorserver`

If we pass maestro drive -vv ("very verbose"), then maestro_cli does adb logcat and prints to stdout (or adb -s <device_id> logcat, when there is more than 1 active emulator).

We'll have to filter the logs, because there are tons of them

Screenshot 2022-06-02 at 6 21 19 PM

Split public API and CLI into separate packages

spec takes an interesting approach – they have packages/spec that developers import and use, and they also have packages/spec_cli.

CLI is activated by dart pub global activate spec_cli.

I think we could do the same to clearly separate what belongs to the CLI and what belongs to the public API.

cc @mateuszwojtczak

Wrap Flutter Driver API methods

The goal is to have Flutter Driver API method wrappers in our Automator API, that do necessary wait/sync/pump jobs so the user doesn't have to write them and produce boilerplate code.

Example:

final counter = tester.firstElement(find.byKey(const ValueKey('counterText'))).widget as Text;

vs

final counter = tester.findByKey<Text>('counterText');

AC: user doesn't have to use any methods beyond Automator API to find a widget by key, tap it / type input and scroll

  • Finders (by key, text, type)
  • Tap
  • Type input
  • Scroll

Split `integration_test/app_test.dart` into 2 variants – generic and for counter app

Proposed usage:

Generic

$ maestro bootstrap

Takes $projectName from pubspec.yaml and uses it to paste the following line into integration_test/app_test.dart:

import 'package:$projectName/app.dart';

We'll have to assume that the project has app.dart file where class App extends Widget is located.

We'll also have to provide providers (e.g using GlobalProviders), if necessary. This requires some testing on real-world examples.

For counter app

$ maestro bootstrap --for counter

The current behavior remains unchanged.

Add support for using existing apk

This will free us from having to do a Gradle build on each maestro drive.

flutter drive has --use-application-binary option, which takes path to APK as an argument.

Wrap `adb` in Dart

This is just an idea that came to my mind today, might not necessarily make much sense.

We could create a small Dart package wrapping adb tool, so instead of writing adb commands as strings, we'd just use nice Dart API.

In the beginning, we'd implement just small subset of functionality of, let's say, Activity Manager.

final port = 5554;
final adb = Adb(port);

final apkPath = "./app-release.apk";
adb.install(apkPath);

final packageName = "pl.leancode.someApp";

adb.activityManager.start(packageName);

I've seen adb command only a few times in the codebase, so this is probably an overkill.

Automatically release artifacts

I think we should follow this tagging convention:

  • automator-v1.2.3 for AutomatorServer
  • maestro-v1.2.3 for packages/maestro (or maestro_test, see #42)
  • maestro_cli-v1.2.3, for packages/maestro_cli

This will make it easy to create some release.yaml GitHub Action which will build and upload server.apk and automator.apk to Azure (or GitHub Releases, in the future).

And also we should somehow make all 3 projects require the same version from each other, to avoid any problems that might arise from version mismatches.

Use default parameter values from config file

Supported entries:

  • host
  • port
  • driver file path
  • test file path

AC: if user sets a value for the key in the config and then runs maestro command without this key:value pair specified, then a value from config is going to be used.

Add `maestro drive --debug` flag

Scope:

  • use $MAESTRO_ARTIFACT_PATH/server.apk and $MAESTRO_ARTIFACT_PATH/instrumentation.apk when --debug flag is passed
  • create some "copy artifacts" Gradle task which would copy artifacts to $MAESTRO_ARTIFACT_PATH

Will make development easier.

Let users change `~/.maestro`

If env var MAESTRO_ARTIFACT_PATH is set, then we'll use it. If it's not set, then we'll fallback to $HOME/.maestro (current behavior).

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.