Skip to content

Commit

Permalink
Merge pull request #1193 from wix/androidx-upgrade
Browse files Browse the repository at this point in the history
(Android) Migrate instrumentation support lib to androidx libs
  • Loading branch information
d4vidi authored Mar 13, 2019
2 parents bd96780 + de09f12 commit 38644af
Show file tree
Hide file tree
Showing 40 changed files with 368 additions and 210 deletions.
12 changes: 7 additions & 5 deletions detox/android/detox/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ dependencies {
minReactNative46Implementation 'com.squareup.okhttp3:okhttp:3.6.0'
minReactNative46Implementation 'com.squareup.okio:okio:1.13.0'

implementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.google.code.findbugs'
})
implementation 'com.android.support.test:runner:1.0.2'
implementation 'com.android.support.test:rules:1.0.2'
// Versions are in-sync with the 'androidx-test-1.1.0' release/tag of the android-test github repo,
// used by the Detox generator. See https://github.com/android/android-test/releases/tag/androidx-test-1.1.0
// Important: Should remain so when generator tag is replaced!
api 'androidx.test.espresso:espresso-core:3.1.1'
api 'androidx.test:runner:1.1.1'
api 'androidx.test:rules:1.1.1'
api 'androidx.test.ext:junit:1.1.0'

// noinspection GradleDynamicVersion
compileOnly "com.facebook.react:react-native:+"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.wix.detox;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import static org.junit.Assert.*;

/**
Expand All @@ -19,7 +20,7 @@ public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("com.wix.detox", appContext.getPackageName());
}
Expand Down
13 changes: 7 additions & 6 deletions detox/android/detox/src/main/java/com/wix/detox/Detox.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import android.os.Looper;
import android.os.RemoteException;
import android.support.annotation.NonNull;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import androidx.test.platform.app.InstrumentationRegistry;

import androidx.test.rule.ActivityTestRule;

/**
* <p>Static class.</p>
Expand Down Expand Up @@ -85,12 +86,12 @@ private Detox() {
*
* <p>
* In case you have a non-standard React Native application, consider using
* {@link Detox#runTests(ActivityTestRule, Object)}}.
* {@link #runTests(ActivityTestRule, Context)}}.
* </p>
* @param activityTestRule the activityTestRule
*/
public static void runTests(ActivityTestRule activityTestRule) {
Context appContext = InstrumentationRegistry.getTargetContext().getApplicationContext();
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
runTests(activityTestRule, appContext);
}

Expand All @@ -109,7 +110,7 @@ public static void runTests(ActivityTestRule activityTestRule) {
* </p>
*
* @param activityTestRule the activityTestRule
* @param Context an object that has a {@code getReactNativeHost()} method
* @param context an object that has a {@code getReactNativeHost()} method
*/
public static void runTests(ActivityTestRule activityTestRule, @NonNull final Context context) {
sActivityTestRule = activityTestRule;
Expand Down Expand Up @@ -173,7 +174,7 @@ public static void startActivityFromUrl(String url) {
// TODO: Can't get to launch the app back to previous instance using only intents from inside instrumentation (not sure why).
// this is a (hopefully) temp solution. Should use intents instead.
public static void launchMainActivity() throws RemoteException, UiObjectNotFoundException {
final Context targetContext = InstrumentationRegistry.getTargetContext();
final Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

// Intent intent = targetContext.getPackageManager().getLaunchIntentForPackage(targetContext.getPackageName());
// intent.setPackage(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wix.detox

import android.content.Context
import android.support.test.espresso.IdlingResource
import android.util.Log
import androidx.test.espresso.IdlingResource
import com.wix.invoke.MethodInvocation
import org.json.JSONArray
import org.json.JSONException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.test.InstrumentationRegistry;
import android.util.Log;

import com.wix.detox.systeminfo.Environment;
Expand All @@ -14,10 +13,10 @@
import java.util.HashMap;
import java.util.Map;

import androidx.test.platform.app.InstrumentationRegistry;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;


/**
* Created by rotemm on 04/01/2017.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import android.content.Context;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.IdlingRegistry;
import android.support.test.espresso.base.IdlingResourceRegistry;
import android.util.Log;

import com.facebook.react.ReactApplication;
Expand All @@ -22,6 +19,10 @@

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.base.IdlingResourceRegistry;
import androidx.test.platform.app.InstrumentationRegistry;
import okhttp3.OkHttpClient;


Expand Down Expand Up @@ -207,7 +208,7 @@ private static void setupReactNativeQueueInterrogators(@NonNull Object reactCont
IdlingRegistry.getInstance().registerLooperAsIdlingResource(JSMessageQueue);
IdlingRegistry.getInstance().registerLooperAsIdlingResource(JMativeModulesMessageQueue);

IdlingResourceRegistry irr = Reflect.on("android.support.test.espresso.Espresso").field("baseRegistry").get();
IdlingResourceRegistry irr = Reflect.on(androidx.test.espresso.Espresso.class).field("baseRegistry").get();
irr.sync(IdlingRegistry.getInstance().getResources(), IdlingRegistry.getInstance().getLoopers());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wix.detox

import android.content.Context
import android.support.test.espresso.Espresso
import android.support.test.espresso.IdlingResource
import androidx.test.espresso.Espresso
import androidx.test.espresso.IdlingResource
import com.wix.detox.espresso.EspressoDetox
import com.wix.detox.espresso.UiAutomatorHelper

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wix.detox.espresso;

import android.support.annotation.NonNull;
import android.support.test.espresso.IdlingResource;
import android.util.Log;
import android.view.Choreographer;

Expand All @@ -10,6 +9,8 @@
import org.joor.Reflect;
import org.joor.ReflectException;

import androidx.test.espresso.IdlingResource;

/**
* Created by simonracz on 25/08/2017.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package com.wix.detox.espresso;

import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.CoordinatesProvider;
import android.support.test.espresso.action.GeneralClickAction;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.espresso.action.Tap;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -18,13 +9,23 @@

import org.hamcrest.Matcher;

import static android.support.test.espresso.action.ViewActions.actionWithAssertions;
import static android.support.test.espresso.action.ViewActions.swipeDown;
import static android.support.test.espresso.action.ViewActions.swipeLeft;
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static android.support.test.espresso.action.ViewActions.swipeUp;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.action.CoordinatesProvider;
import androidx.test.espresso.action.GeneralClickAction;
import androidx.test.espresso.action.GeneralLocation;
import androidx.test.espresso.action.GeneralSwipeAction;
import androidx.test.espresso.action.Press;
import androidx.test.espresso.action.Swipe;
import androidx.test.espresso.action.Tap;

import static androidx.test.espresso.action.ViewActions.actionWithAssertions;
import static androidx.test.espresso.action.ViewActions.swipeDown;
import static androidx.test.espresso.action.ViewActions.swipeLeft;
import static androidx.test.espresso.action.ViewActions.swipeRight;
import static androidx.test.espresso.action.ViewActions.swipeUp;
import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static org.hamcrest.Matchers.allOf;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.wix.detox.espresso;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.EspressoException;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewInteraction;
import android.view.View;

import junit.framework.AssertionFailedError;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import androidx.test.espresso.EspressoException;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.ViewInteraction;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static org.hamcrest.Matchers.not;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.wix.detox.espresso;

import android.support.test.espresso.matcher.ViewMatchers;
import android.view.View;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

import static android.support.test.espresso.matcher.ViewMatchers.Visibility;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.espresso.matcher.ViewMatchers.Visibility;

import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withTagValue;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.is;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.wix.detox.espresso;

import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.ViewActions;
import android.view.View;

import com.wix.detox.ReactNativeSupport;

import org.hamcrest.Matcher;

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.action.ViewActions;

/**
* An alternative to {@link ViewActions} - providing alternative implementations, where needed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
import android.content.ContextWrapper;
import android.content.pm.ActivityInfo;
import android.os.Handler;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.IdlingResource;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewInteraction;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -23,13 +17,19 @@

import java.util.ArrayList;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.IdlingResource;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.ViewInteraction;
import androidx.test.platform.app.InstrumentationRegistry;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;

/**
* Created by rotemm on 26/12/2016.
*/

public class EspressoDetox {
private static final String LOG_TAG = "detox";

Expand Down Expand Up @@ -121,7 +121,7 @@ public static ArrayList<IdlingResource> getBusyEspressoResources() {
// 1. we want to use postAtFrontOfQueue()
// 2. we want it to be synchronous
final ArrayList<IdlingResource> busyResources = new ArrayList<>();
final Handler handler = new Handler(InstrumentationRegistry.getTargetContext().getMainLooper());
final Handler handler = new Handler(InstrumentationRegistry.getInstrumentation().getTargetContext().getMainLooper());
final SyncRunnable sr = new SyncRunnable(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.wix.detox.espresso;

import android.os.Build;
import android.support.test.espresso.UiController;
import android.support.test.espresso.action.MotionEvents;
import android.support.test.espresso.action.MotionEvents.DownResultHolder;
import android.support.test.espresso.action.Tapper;
import android.util.Log;
import android.view.ViewConfiguration;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static android.support.test.espresso.core.internal.deps.guava.base.Preconditions.checkNotNull;
import androidx.test.espresso.UiController;
import androidx.test.espresso.action.MotionEvents;
import androidx.test.espresso.action.MotionEvents.DownResultHolder;
import androidx.test.espresso.action.Tapper;

import static androidx.test.espresso.core.internal.deps.guava.base.Preconditions.checkNotNull;


public class MultiTap implements Tapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.wix.detox.espresso;

import android.support.test.espresso.IdlingResource;
import android.util.Log;

import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
import com.facebook.react.bridge.ReactContext;

import java.util.concurrent.atomic.AtomicBoolean;

import androidx.test.espresso.IdlingResource;

import static androidx.test.espresso.IdlingResource.ResourceCallback;

/**
* Created by simonracz on 01/06/2017.
*/
Expand Down
Loading

0 comments on commit 38644af

Please sign in to comment.