Skip to content

feat: add patrol e2e testing #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 91 additions & 88 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ version: 2.1

orbs:
android: circleci/[email protected]
flutter: circleci/flutter@2.0.2
flutter: circleci/flutter@2.1.0
node: circleci/[email protected]
advanced-checkout: vsco/[email protected]
ios: circleci/[email protected]

commands:
setup_flutter:
Expand All @@ -17,79 +18,55 @@ commands:
setup_ios:
steps:
# Flutter doesn't support Apple Silicon yet, so we need to install Rosetta use Flutter on M1 machines.
- run:
name: Install Rosetta
command: softwareupdate --install-rosetta --agree-to-license
- ios/install-rosetta
- setup_flutter
- run:
name: Install CocoaPods
command: sudo gem install cocoapods
- run:
name: Install Pods
working_directory: example/ios
command: pod install --repo-update
setup_captain:
parameters:
platform:
type: enum
enum:
- ios
- android
- flutter/install_ios_pod:
app-dir: example
repo-update: true
setup_patrol:
steps:
- run:
name: Install Appium
command: npm install -g appium
- when:
condition:
equal:
- <<parameters.platform>>
- ios
steps:
- run:
name: Install XCUITest Driver
command: appium driver install [email protected]
- when:
condition:
equal:
- <<parameters.platform>>
- android
steps:
- run:
name: Install UIAutomator2 Driver
command: appium driver install [email protected]
- run:
name: Launch Appium
# Enable --relaxed-security for `mobile: shell` command that Captain uses internally.
command: appium --relaxed-security
background: true
- run:
name: Install .NET 6
command: curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0.1xx
- run:
name: Add .NET to PATH
name: Add pub-cache bin to PATH
command: |
echo 'export DOTNET_ROOT=$HOME/.dotnet' >> $BASH_ENV
echo 'export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools' >> $BASH_ENV
echo 'export PATH="$PATH:$HOME/.pub-cache/bin"' >> $BASH_ENV
source $BASH_ENV
- run:
name: Clone Captain
command: git clone [email protected]:Instabug/Captain.git ../Instabug.Captain
- run:
name: Configure Captain Platform
command: echo 'export CAPTAIN_PLATFORM=<<parameters.platform>>' >> $BASH_ENV
name: Install patrol
command: dart pub global activate patrol_cli 3.5.0
# This runs `flutter pub get` and `dart pub get` if we pass parameter `generate_pigeons` to the job it also runs the following:
# - `sh ./scripts/pigeon.sh`
# - `dart run build_runner build --delete-conflicting-outputs`
install_flutter_and_dart_packages:
parameters:
generate_pigeons:
type: boolean
remove_patrol:
type: boolean
default: false
version:
type: string
default: "3.24.0"
steps:
- flutter/install_sdk:
version: <<parameters.version>>
- when:
condition:
equal:
- <<parameters.remove_patrol>>
- true
steps:
- run:
name: remove Patrol
command: cd example && dart pub remove patrol
- run:
name: Install Flutter Packages
command: flutter pub get
command: flutter pub get --verbose
- run:
name: Install Dart Packages
command: dart pub get
command: dart pub get --verbose
description: Install Dart Packages (for dart explicit packages)
- when:
condition:
Expand Down Expand Up @@ -123,12 +100,21 @@ jobs:
parameters:
version:
type: string
docker:
- image: cirrusci/flutter:<<parameters.version>>
executor:
name: android/android-machine
resource-class: xlarge
tag: 2024.01.1
steps:
- advanced-checkout/shallow-checkout
- install_flutter_and_dart_packages:
generate_pigeons: true
remove_patrol: true
version: <<parameters.version>>
- run:
name: Install lcov
command: |
sudo apt-get update
sudo apt-get install -y lcov
- run: flutter test --coverage
- run:
working_directory: coverage
Expand All @@ -150,26 +136,31 @@ jobs:
working-directory: example/android
test-command: ./gradlew test

e2e_android_captain:
e2e_android_patrol:
executor:
name: android/android-machine
resource-class: xlarge
tag: 2024.01.1
steps:
- advanced-checkout/shallow-checkout
- setup_captain:
platform: android
- setup_flutter
- android/start-emulator-and-run-tests:
run-tests-working-directory: e2e
additional-avd-args: --device 3
- setup_patrol
- android/create-avd:
avd-name: 'test'
install: true
system-image: system-images;android-33;default;x86_64
post-emulator-launch-assemble-command: cd example && flutter build apk --debug
test-command: dotnet test
- android/start-emulator:
avd-name: 'test'
post-emulator-launch-assemble-command: ""
- run:
name: Run E2E Tests
no_output_timeout: 30m
working_directory: example
command: patrol test -t integration_test/

test_ios:
macos:
xcode: 15.2.0
xcode: 16.0.0
resource_class: macos.m1.medium.gen1
environment:
INSTABUG_SOURCEMAPS_UPLOAD_DISABLE: true
Expand All @@ -185,31 +176,39 @@ jobs:
-scheme Runner \
-resultBundlePath coverage/result.xcresult \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro Max,OS=17.2' \
-destination 'platform=iOS Simulator,name=iPhone 16 Pro Max,OS=18.0' \
-skip-testing:RunnerUITests \
test | xcpretty

e2e_ios_captain:
e2e_ios_patrol:
macos:
xcode: 15.2.0
xcode: 16.0.0
resource_class: macos.m1.medium.gen1
steps:
- advanced-checkout/shallow-checkout
- setup_captain:
platform: ios
- setup_ios
- setup_patrol
- ios/preboot-simulator:
version: "18.0"
device: "iPhone 16 Pro"
- ios/wait-until-simulator-booted
- ios/wait-until-simulator-booted
- run:
name: Build Example App
working_directory: example
command: flutter build ios --simulator
name: sleep 10 seconds
command: sleep 10
- run:
name: sleep 10 seconds
command: sleep 10
Comment on lines 196 to +201
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we sleeping 10 seconds two times? Would sleeping for 20 seconds once work just as fine?

- run:
name: Run E2E Tests
no_output_timeout: 30m
working_directory: e2e
command: dotnet test

working_directory: example
command: patrol test -t integration_test/ --verbose --device "iPhone 16 Pro"
format_flutter:
docker:
- image: cirrusci/flutter
executor:
name: android/android-machine
resource-class: xlarge
tag: 2024.01.1
steps:
- advanced-checkout/shallow-checkout
- install_flutter_and_dart_packages:
Expand All @@ -219,8 +218,10 @@ jobs:
command: dart format . --set-exit-if-changed

lint_flutter:
docker:
- image: cirrusci/flutter
executor:
name: android/android-machine
resource-class: xlarge
tag: 2024.01.1
steps:
- advanced-checkout/shallow-checkout
- install_flutter_and_dart_packages:
Expand All @@ -230,8 +231,10 @@ jobs:
command: flutter analyze

verify_pub:
docker:
- image: cirrusci/flutter
executor:
name: android/android-machine
resource-class: xlarge
tag: 2024.01.1
steps:
- advanced-checkout/shallow-checkout
- install_flutter_and_dart_packages:
Expand All @@ -243,7 +246,7 @@ jobs:

release:
macos:
xcode: 15.2.0
xcode: 16.0.0
resource_class: macos.m1.medium.gen1
working_directory: "~"
steps:
Expand Down Expand Up @@ -288,13 +291,13 @@ workflows:
- test_flutter-stable
- test_flutter:
name: test_flutter-stable
version: stable
version: 3.24.0
- test_flutter:
name: test_flutter-2.10.5
version: 2.10.5
- e2e_android_captain
- e2e_android_patrol
- test_ios
- e2e_ios_captain
- e2e_ios_patrol
- format_flutter
- lint_flutter:
requires:
Expand All @@ -312,9 +315,9 @@ workflows:
# TODO: Fix the flaky tests and add the following jobs to the dependencies for the release
# The following jobs have been removed while releasing v13.2.0 to avoid delaying the release
# as they were just flaky and the tests pass locally without issues.
# - e2e_android_captain
# - e2e_android_patrol
# - test_ios
- e2e_ios_captain
- e2e_ios_patrol
- verify_pub
filters:
branches:
Expand Down
11 changes: 9 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ android {
jvmTarget = JavaVersion.VERSION_1_8
}

testOptions {
execution "ANDROIDX_TEST_ORCHESTRATOR"
}

defaultConfig {
applicationId "com.instabug.flutter.example"
minSdkVersion 21
targetSdkVersion 34
versionCode flutter.versionCode
versionName flutter.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: "true"
}

buildTypes {
Expand All @@ -51,6 +56,8 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20"
implementation 'com.android.support:multidex:1.0.3'
implementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:1.10.19'
androidTestUtil "androidx.test:orchestrator:1.5.1"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.instabug.flutter.example;

import androidx.test.platform.app.InstrumentationRegistry;

import com.example.InstabugSample.MainActivity;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import pl.leancode.patrol.PatrolJUnitRunner;

@RunWith(Parameterized.class)
public class MainActivityTest {
@Parameters(name = "{0}")
public static Object[] testCases() {
PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
// replace "MainActivity.class" with "io.flutter.embedding.android.FlutterActivity.class"
// if in AndroidManifest.xml in manifest/application/activity you have
// android:name="io.flutter.embedding.android.FlutterActivity"
instrumentation.setUp(MainActivity.class);
instrumentation.waitForPatrolAppService();
return instrumentation.listDartTests();
}

public MainActivityTest(String dartTestName) {
this.dartTestName = dartTestName;
}

private final String dartTestName;

@Test
public void runDartTest() {
PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
instrumentation.runDartTest(dartTestName);
}
}
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:networkSecurityConfig="@xml/network_security_config"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:name="com.example.InstabugSample.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.instabug.flutter.example
package com.example.InstabugSample

import com.example.InstabugSample.InstabugExampleMethodCallHandler
import com.example.InstabugSample.InstabugExampleMethodCallHandler.Companion.METHOD_CHANNEL_NAME
Expand Down
Loading