borosr / flutter-screenshot

Helps to run UI tests on multiple device and take screenshots

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flutter Screenshot

example workflow name Coverage Status Go Report Card codebeat badge

A tool which helps in multi device screenshot creation for Flutter projects.

Requirements

  1. Go 1.16 or later, to install this project
  2. Installed Xcode and simulator
  3. Installed Android emulator, avdmanager and adb (e.x.: Command Line Tools)
  4. Flutter Integration tests
  5. Extend Integration tests with screenshot calls

Usage

Setup

Install with go modules

go get -u -t github.com/borosr/flutter-screenshot

Install from release

Download one of the supported versions from here.

  1. Create a configuration file in your Flutter project's root and name it screenshots.yaml, config example below
  2. Just call flutter-screenshot in you Flutter project's directory
  3. (Optional) Use --verbose after the command, to see more log messages

Note

  • The flutter-screenshot will set the EMU_DEVICE environment variable before every flutter drive execution, the value will be the momentary device name from the configuration

Configuration

Example

# screenshots.yaml
command: flutter drive --target=test_driver/app.dart
devices:
  ios:
    - name: iPhone X
      mode: both # can be both, light, dark, the default value is light
    - name: iPad Pro (12.9-inch) (4th generation)
      mode: dark
  android:
    - name: Pixel_API_30

In Flutter project

You should create a helper method for your UI tests, something like:

final now = new DateTime.now();
makeScreenshot(FlutterDriver driver, String filename) async {
    final imageInPixels = await driver.screenshot();
    new File('screenshots/${Platform.environment['EMU_DEVICE']}_${now.toString()}/$filename.png')
        .writeAsBytes(imageInPixels);
}

Then call this makeScreenshot method with the current FlutterDriver object and a (test level) unique filename. The result will appear in a screenshots directory in you Flutter project root and will contains subdirectories with the configured device names which will contains the captured images.

About

Helps to run UI tests on multiple device and take screenshots

License:GNU General Public License v3.0


Languages

Language:Go 99.3%Language:Makefile 0.7%