Skip to content

Commit

Permalink
Fix android client test will fail when startup without clicking popup…
Browse files Browse the repository at this point in the history
… dialog (#463)

* Update android_client test

* Add updated android_client test apk
  • Loading branch information
olivershen-wow authored Apr 26, 2023
1 parent 70e27ef commit 13d2839
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
8 changes: 5 additions & 3 deletions android_client/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
targetSdkVersion 28
versionCode 17
versionName '2.6.0'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -32,8 +32,10 @@ android {
}

dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
def appCenterSdkVersion = '4.4.4'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.microsoft.hydralab.android.client;


import android.support.test.espresso.ViewInteraction;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.rule.GrantPermissionRule;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.espresso.ViewInteraction;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.rule.GrantPermissionRule;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;

import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
Expand All @@ -18,14 +25,14 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;

@LargeTest
Expand All @@ -42,7 +49,13 @@ public class MainActivityTest {
"android.permission.WRITE_EXTERNAL_STORAGE");

@Test
public void mainActivityTest() {
public void mainActivityTest() throws UiObjectNotFoundException {
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject uiObject = device.findObject(new UiSelector().packageName("com.android.systemui").textMatches("(?i)(START NOW|ALLOW|允许)"));
if (uiObject.exists()) {
uiObject.click();
}

ViewInteraction imageView = onView(
allOf(withId(R.id.debug_icon), withContentDescription("Debug"),
childAtPosition(
Expand All @@ -65,8 +78,8 @@ public void mainActivityTest() {

ViewInteraction textView = onView(
allOf(withText("HydraLab Client"),
withParent(allOf(IsInstanceOf.<View>instanceOf(android.view.ViewGroup.class),
withParent(IsInstanceOf.<View>instanceOf(android.widget.FrameLayout.class)))),
withParent(allOf(IsInstanceOf.<View>instanceOf(ViewGroup.class),
withParent(IsInstanceOf.<View>instanceOf(FrameLayout.class)))),
isDisplayed()));
textView.check(matches(withText("HydraLab Client")));

Expand Down
3 changes: 2 additions & 1 deletion android_client/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.useAndroidX=true
Binary file modified common/src/main/resources/record_androidTest.apk
Binary file not shown.

0 comments on commit 13d2839

Please sign in to comment.