Run Flutter Driver tests on GitHub Actions

Katarina Sheremet
Nov 13, 2019 · 4 min read

GitHub Actions is a new feature of Github that enables to create of a custom software development life cycle workflow directly in GitHub repository. You can write individual tasks, called actions, and combine them to create a custom workflow. Workflows are custom automated processes that you can set up in your repository to build, test, package, release, or deploy any code project on GitHub.

Let’s see whether we can run Flutter Driver Tests on GitHub Actions!

Create an app with Integration tests

To play around with GitHub Actions we have a standard Flutter Counter App.

Standard Flutter “Hello World” app

We’ll add Flutter Integration tests to the project. To learn how to write Integration tests, please check out the official documentation.

The first test checks that the counter text equals 0 when we start the app.

test('starts at 0', () async {
expect(await driver.getText(counterTextFinder), "0");

Then we press FAB once and check that the counter text equals 1.

test('increments the counter', () async {
await driver.tap(buttonFinder);
expect(await driver.getText(counterTextFinder), "1");

To see the whole code of the Flutter Integration tests, please have a look here.

Now we are ready to add GitHub Actions workflow to run Flutter Driver tests.

Add GitHub Actions to the project

  1. Add .github/workflows directory in your project
# Name of your workflow.
name: flutter drive
# Trigger the workflow on push or pull request.
on: [push, pull_request]
# A workflow run is made up of one or more jobs.
# id of job, a string that is unique to the "jobs" node above.
# Creates a build matrix for your jobs. You can define different
# variations of an environment to run each job in.

# A set of different configurations of the virtual
# environment.

- "iPhone 8 (13.1)"
- "iPhone 11 Pro Max (13.1)"
# When set to true, GitHub cancels all in-progress jobs if any
# matrix job fails.

fail-fast: false
# The type of machine to run the job on.
runs-on: macOS-latest
# Contains a sequence of tasks.
# A name for your step to display on GitHub.
- name: "List all simulators"
run: "xcrun instruments -s"
- name: "Start Simulator"
run: |
xcrun instruments -s |
awk \
-F ' *[][]' \
-v 'device=${{ matrix.device }}' \
'$1 == device { print $2 }'
xcrun simctl boot "${UDID:?No Simulator with this name found}"
# The branch or tag ref that triggered the workflow will be
# checked out.

- uses: actions/checkout@v1
# Sets up a flutter environment.
- uses: subosito/flutter-action@v1
channel: 'stable' # or: 'dev' or 'beta'
- name: "Run Flutter Driver tests"
run: "flutter drive --target=test_driver/app.dart"

I’ve tried to explain every line of the file with comments. If you need more info about syntax for GitHub Actions, please have a look at the doc. I only would like to explain more about the code where we start a Simulator. For most Flutter projects it doesn’t matter whether it’s Android Emulator or iOS Simulator. But Simulator is easier to start and works faster.
To boot a Simulator on Mac from Command Line we can use the following command:

xcrun simctl boot <device>

<device> is a UUID of a simulator. How to get it?

To get a list of created simulators we can run:

xcrun instruments -s

The output looks like this:

The symbols in the square brackets are what we need — UUID. And I’m using awk command to retrieve symbols for a needed device. If I run

echo $(xcrun instruments -s | awk -F ' *[][]' -v 'device=iPhone 8 Plus (13.1)' '$1 == device { print $2 }')

I will get 343A7DF6–23F7–4369–9D9F-1551037CEB97. I’m using ${{ matrix.device }} variable for the device I need to get UUID. After getting the UUID, I boot the device I need.

4. Push your project to GitHub and go to the “Actions” tab. I can see that my actions are running and performed successfully.

5. The last step is to add a Badge in README for the master branch. For my project it is:

[![Build Status](]("flutter+drive"+branch%3Amaster)
GitHub Actions Badge

The full code is here.

Useful links

Flutter Community

Articles and Stories from the Flutter Community

Katarina Sheremet

Written by

Google Developer Expert in Flutter and Dart

Flutter Community

Articles and Stories from the Flutter Community

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade