Package 

Class Detox

  • All Implemented Interfaces:

    
    public final class Detox
    
                        

    Static class.

    To start Detox tests, call runTests() from a JUnit test. This test must use AndroidJUnitRunner or a subclass of it, as Detox uses Espresso internally. All non-standard async code must be wrapped in an Espresso IdlingResource.

    Example usage
    
    @runWith(AndroidJUnit4.class)
    @LargeTest
    public class DetoxTest {
     @Rule
      //The Activity that controls React Native.
      public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
    
     @Before
      public void setUpCustomEspressoIdlingResources() {
        // set up your own custom Espresso resources here
      }
    
     @Test
      public void runDetoxTests() {
        Detox.runTests();
      }
    }

    Two required parameters are detoxServer and detoxSessionId. These must be provided either by Gradle.

    
    android {
      defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments = [
          'detoxServer': 'ws://10.0.2.2:8001',
          'detoxSessionId': '1'
        ]
      }
    }
    Or through command line, e.g
    adb shell am instrument -w -e detoxServer ws://localhost:8001 -e detoxSessionId
    1 com.example/android.support.test.runner.AndroidJUnitRunner

    These are automatically set using,

    detox test

    If not set, then Detox tests are no ops. So it's safe to mix it with other tests.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class Detox.DetoxIdlePolicyConfig

      Specification of values to use for Espresso's IdlingPolicies timeouts. Overrides Espresso's defaults as they tend to be too short (e.g. when running a heavy-load app on suboptimal CI machines).

    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static void runTests(ActivityTestRule activityTestRule) Call this method from a JUnit test to invoke detox tests.
      static void runTests(ActivityTestRule activityTestRule, DetoxConfig detoxConfig) Same as the default runTests method, but allows for the explicit specification of various configurations.
      static void runTests(ActivityTestRule activityTestRule, Detox.DetoxIdlePolicyConfig idlePolicyConfig) Same as the default runTests method, but allows for the explicit specification of a custom idle-policy configuration.
      static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context) Use this method only if you have a React Native application and it doesn't implement ReactApplication; Otherwise use runTests.
      static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context, Detox.DetoxIdlePolicyConfig idlePolicyConfig) Same as runTests, but allows for the explicit specification of a custom idle-policy configuration.
      static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context, DetoxConfig detoxConfig) Same as runTests, but allows for the explicit specification of various configurations.
      static void launchMainActivity()
      static void startActivityFromUrl(String url)
      static void startActivityFromNotification(String dataFilePath)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • runTests

         static void runTests(ActivityTestRule activityTestRule)

        Call this method from a JUnit test to invoke detox tests.

        In case you have a non-standard React Native application, consider using runTests}.

        Parameters:
        activityTestRule - the activityTestRule
      • runTests

         static void runTests(ActivityTestRule activityTestRule, DetoxConfig detoxConfig)

        Same as the default runTests method, but allows for the explicit specification of various configurations. Note: review DetoxConfig for defaults.

        Parameters:
        detoxConfig - The configurations to apply.
      • runTests

        @Deprecated() static void runTests(ActivityTestRule activityTestRule, Detox.DetoxIdlePolicyConfig idlePolicyConfig)

        Same as the default runTests method, but allows for the explicit specification of a custom idle-policy configuration. Note: review DetoxIdlePolicyConfig for defaults.

        Parameters:
        idlePolicyConfig - The custom idle-policy configuration to pass in; Will be applied into Espresso via the IdlingPolicies API.
      • runTests

         static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context)

        Use this method only if you have a React Native application and it doesn't implement ReactApplication; Otherwise use runTests.

        The only requirement is that the passed in object must have a method with the signature

        ReactNativeHost getReactNativeHost();
        Parameters:
        activityTestRule - the activityTestRule
        context - an object that has a getReactNativeHost() method
      • runTests

        @Deprecated() static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context, Detox.DetoxIdlePolicyConfig idlePolicyConfig)

        Same as runTests, but allows for the explicit specification of a custom idle-policy configuration. Note: review DetoxIdlePolicyConfig for defaults.

        Parameters:
        idlePolicyConfig - The custom idle-policy configuration to pass in; Will be applied into Espresso via the IdlingPolicies API.
      • runTests

         static void runTests(ActivityTestRule activityTestRule, @NonNull() Context context, DetoxConfig detoxConfig)

        Same as runTests, but allows for the explicit specification of various configurations. Note: review DetoxConfig for defaults.

        Parameters:
        detoxConfig - The configurations to apply.