A tool which helps in multi device screenshot creation for Flutter projects.
- Go 1.16 or later, to install this project
- Installed Xcode and simulator
- Installed Android emulator, avdmanager and adb (e.x.: Command Line Tools)
- Flutter Integration tests
- Extend Integration tests with screenshot calls
go get -u -t github.com/borosr/flutter-screenshot
Download one of the supported versions from here.
- Create a configuration file in your Flutter project's root and name it
screenshots.yaml
, config example below - Just call
flutter-screenshot
in you Flutter project's directory - (Optional) Use
--verbose
after the command, to see more log messages
- The flutter-screenshot will set the
EMU_DEVICE
environment variable before everyflutter drive
execution, the value will be the momentary device name from the configuration
# 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
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.