Skip to content

Commit bb8bacc

Browse files
sarahkoopSteven Shropshire
authored and
Steven Shropshire
committed
Update gradle dependencies and use updated Instrumentation classes.
Signed-off-by: Steven Shropshire <[email protected]>
1 parent 1811536 commit bb8bacc

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

DeviceAutomator/build.gradle

+12-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ android {
1717
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1818
}
1919

20+
testOptions {
21+
unitTests {
22+
includeAndroidResources = true
23+
}
24+
}
25+
2026
lintOptions {
2127
warning 'InvalidPackage'
2228
textReport true
@@ -26,14 +32,15 @@ android {
2632

2733
dependencies {
2834
api 'androidx.test.uiautomator:uiautomator:2.2.0'
29-
api 'androidx.test:runner:1.2.0'
30-
api 'androidx.test:rules:1.2.0'
31-
api 'androidx.core:core:1.1.0'
35+
api 'androidx.test:runner:1.3.0'
36+
api 'androidx.test:rules:1.3.0'
37+
api 'androidx.core:core:1.3.1'
38+
api 'androidx.test.ext:junit:1.1.2'
3239

3340
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
3441

35-
testImplementation 'org.robolectric:robolectric:3.8'
36-
testImplementation 'org.mockito:mockito-core:2.8.47'
42+
testImplementation 'org.robolectric:robolectric:4.3'
43+
testImplementation 'org.mockito:mockito-core:2.28.2'
3744
}
3845

3946
/* maven deploy + signing */

DeviceAutomator/src/main/java/com/lukekorth/deviceautomator/DeviceAutomator.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.lukekorth.deviceautomator;
22

3+
import android.content.Context;
34
import android.content.Intent;
45
import android.content.pm.PackageManager;
56
import android.os.Build;
67
import android.os.RemoteException;
8+
9+
import androidx.test.core.app.ApplicationProvider;
710
import androidx.test.uiautomator.By;
811
import androidx.test.uiautomator.UiDevice;
912
import androidx.test.uiautomator.UiObject;
@@ -14,9 +17,7 @@
1417
import android.view.KeyCharacterMap;
1518
import android.view.KeyEvent;
1619

17-
import static androidx.test.InstrumentationRegistry.getContext;
18-
import static androidx.test.InstrumentationRegistry.getInstrumentation;
19-
import static androidx.test.InstrumentationRegistry.getTargetContext;
20+
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
2021
import static androidx.test.uiautomator.Until.hasObject;
2122
import static junit.framework.Assert.assertTrue;
2223
import static org.hamcrest.MatcherAssert.assertThat;
@@ -121,7 +122,7 @@ public DeviceAutomator launchApp(String packageName) {
121122
* @return {@link DeviceAutomator} for method chaining.
122123
*/
123124
public DeviceAutomator launchApp(String packageName, long timeout) {
124-
return launchApp(getContext().getPackageManager().getLaunchIntentForPackage(packageName), timeout);
125+
return launchApp(getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage(packageName), timeout);
125126
}
126127

127128
/**
@@ -144,7 +145,7 @@ public DeviceAutomator launchApp(Intent intent) {
144145
public DeviceAutomator launchApp(Intent intent, long timeout) {
145146
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
146147
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
147-
getContext().startActivity(intent);
148+
getInstrumentation().getContext().startActivity(intent);
148149

149150
mDevice.wait(hasObject(By.pkg(intent.getPackage()).depth(0)), timeout);
150151

@@ -279,8 +280,9 @@ public DeviceAutomator denyRuntimePermission(String permission) {
279280
}
280281

281282
private void clickPermissionDialogButton(String permission, int buttonIndex) {
283+
Context targetContext = ApplicationProvider.getApplicationContext();
282284
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
283-
ContextCompat.checkSelfPermission(getTargetContext(), permission) != PackageManager.PERMISSION_GRANTED) {
285+
ContextCompat.checkSelfPermission(targetContext, permission) != PackageManager.PERMISSION_GRANTED) {
284286
try {
285287
UiObject allowPermissions = mDevice.findObject(new UiSelector()
286288
.clickable(true)

0 commit comments

Comments
 (0)