Skip to content

Commit 01c97eb

Browse files
authored
[MOB-9995] Fix and enable Android UI tests (#271)
* Fix email `EditText` matcher in Android UI tests * Close media projection dialog in Android UI Tests I had to add UiAutomator for this as Espresso can't interact with system UI while UiAutomator does. I also bumped the `minSdkVersion` to 18 as UiAutomator's `minSdkVersion` is 18 and we can't make it lower than one of our dependencies. * Enable Android UI tests on CI * Fix typo in invocation Android UI test method name * Check for success dialog with UiAutomator
1 parent 347683b commit 01c97eb

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

.circleci/config.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ jobs:
4444
- flutter/install_sdk_and_pub:
4545
flutter_version: 2.2.3
4646
app-dir: ..
47-
# UI Tests are disabled due to an issue with
48-
# media projection prompt.
49-
# - android/start-emulator-and-run-tests:
50-
# system-image: system-images;android-30;google_apis;x86
51-
# additional-avd-args: -d "Nexus 5"
52-
# post-emulator-launch-assemble-command: flutter build apk
53-
# test-command: ./gradlew app:connectedAndroidTest
47+
- android/start-emulator-and-run-tests:
48+
system-image: system-images;android-30;google_apis;x86
49+
additional-avd-args: -d "Nexus 5"
50+
post-emulator-launch-assemble-command: flutter build apk
51+
test-command: ./gradlew app:connectedAndroidTest
5452
- android/run-tests:
5553
test-command: ./gradlew test
5654

example/android/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ android {
4848
defaultConfig {
4949
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
5050
applicationId "com.example.InstabugSample"
51-
minSdkVersion 16
51+
minSdkVersion 18
5252
targetSdkVersion 30
5353
versionCode flutterVersionCode.toInteger()
5454
versionName flutterVersionName
@@ -80,6 +80,7 @@ dependencies {
8080
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
8181
androidTestImplementation 'androidx.test:rules:1.1.1'
8282
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
83+
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator:2.1.3'
8384
testImplementation 'org.mockito:mockito-core:1.10.19'
8485
implementation 'org.mockito:mockito-core:1.10.19'
8586
}

example/android/app/src/androidTest/java/com/example/InstabugSample/InvokeInstabugUITest.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import androidx.test.rule.ActivityTestRule;
44
import androidx.test.ext.junit.runners.AndroidJUnit4;
5+
import androidx.test.uiautomator.UiDevice;
6+
import androidx.test.uiautomator.UiObject;
7+
import androidx.test.uiautomator.UiSelector;
58

69
import org.junit.Rule;
710
import org.junit.Test;
@@ -10,33 +13,45 @@
1013
import static androidx.test.espresso.Espresso.onView;
1114
import static androidx.test.espresso.action.ViewActions.click;
1215
import static androidx.test.espresso.action.ViewActions.replaceText;
16+
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
1317
import static androidx.test.espresso.matcher.ViewMatchers.withResourceName;
1418
import static androidx.test.espresso.matcher.ViewMatchers.withText;
15-
16-
import com.instabug.flutter.InstabugFlutterPlugin;
19+
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
20+
import static org.hamcrest.Matchers.allOf;
1721

1822
@RunWith(AndroidJUnit4.class)
1923
public class InvokeInstabugUITest {
24+
UiDevice device = UiDevice.getInstance(getInstrumentation());
2025

2126
@Rule
2227
public ActivityTestRule<MainActivity> mActivityRule =
2328
new ActivityTestRule<>(MainActivity.class);
2429

2530
@Test
26-
public void ensureInstabugInvocati1on() throws InterruptedException {
27-
disableScreenShotByMediaProjection();
31+
public void ensureInstabugInvocation() throws InterruptedException {
2832
Thread.sleep(1000);
2933
onView(withResourceName("instabug_floating_button")).perform(click());
3034
Thread.sleep(1000);
35+
36+
// Dismiss media projection prompt.
37+
// This is a temporary solution as we are dropping media projection in a future release.
38+
device.pressBack();
39+
Thread.sleep(1000);
40+
3141
onView(withText("Report a bug")).perform(click());
3242
Thread.sleep(1000);
33-
onView(withResourceName("instabug_edit_text_email")).perform(replaceText("[email protected]"));
43+
44+
onView(
45+
allOf(
46+
withResourceName("ib_edit_text"),
47+
withParent(withResourceName("instabug_edit_text_email"))
48+
)
49+
).perform(replaceText("[email protected]"));
50+
3451
onView(withResourceName("instabug_bugreporting_send")).perform(click());
35-
onView(withResourceName("instabug_success_dialog_container")).perform(click());
36-
}
3752

38-
private void disableScreenShotByMediaProjection() {
39-
InstabugFlutterPlugin.enableScreenShotByMediaProjection(false);
53+
UiObject successDialog = device.findObject(new UiSelector().resourceIdMatches(".*/id:instabug_success_dialog_container"));
54+
successDialog.waitForExists(3000);
4055
}
4156
}
4257

0 commit comments

Comments
 (0)