testing-samples icon indicating copy to clipboard operation
testing-samples copied to clipboard

Could not launch intent Intent Espresso again

Open abanksdev opened this issue 8 years ago • 13 comments

I am testing with the Espresso framework but keep getting the following error:

`java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=aurora.aero.inflightmanager.dds/aurora.aero.inflightmanager.home.HomeActivity } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1501794260595 and now the last time the queue went idle was: 1501794260664. If these numbers are the same your activity might be hogging the event queue. at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:360) at android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:219) at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:268) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1873)

Tests ran to completion. `

My build.gradle is as follows:

` androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'appcompat' exclude group: 'com.android.support', module: 'support-v4' exclude group: 'recyclerview-v7' exclude group: 'com.google.guava:guava:19.0'

})`

I have looked at both #56 and #15 and I have excluded every dependency in my production APK from my test APK. I'm still getting the same error. The strange thing is that sometimes it randomly works and the test will pass, but for the most part I get the same error, any ideas?

abanksdev avatar Aug 03 '17 21:08 abanksdev

I get the same error. In my test, I need launch three times the same activity, once for each test. But, in the second test, I get this error: Could not launch intent Intent.

In the first test, the activity launched redirect to another activity. So, I think is the problem.

In the last test, the activity is launched normally.

This is my rule:

@Rule
    public ActivityTestRule mActivityRule
            = new ActivityTestRule<>(LoginActivity.class,
            false /* Initial touch mode */, true /*  launch activity */);

This is my test problematic:

@Test
    public void validLogin(){
        replaceTextOnView(R.id.txt_email, "[email protected]");

        replaceTextOnView(R.id.txt_password, "123456789");

        clickOnButton(R.id.btn_sign_in); //Redirect to the MainActivity

        String text = activity.getString(R.string.app_name);

        checkTextOnView(text);
    }

eugenio-caicedo avatar Sep 01 '17 01:09 eugenio-caicedo

I get the same error. Have you already solved this problem?

WangWen-Albert avatar Sep 26 '19 15:09 WangWen-Albert

any solutions?

febinmathew avatar May 10 '20 08:05 febinmathew

Have you tried to turn off animations in Developer Settings before running UI tests (if you using CI build you need use for it adb)? If activity has any network/io related work, I am pretty sure you need also to implement custom EspressoIdlingResource (as an example: https://github.com/piotrek1543/todo-mvi-sample-app/blob/ed7b111763232cc4d9337933a87a19ea589e5b7f/app/src/main/java/com/piotrek1543/example/todoapp/ui/util/EspressoIdlingResource.kt).

piotrek1543 avatar May 11 '20 20:05 piotrek1543

any solutions?

Please try with ActivityScenarioRule instead of ActivityTestRule like below

@Rule 
public ActivityScenarioRule<LoginActivity> mActivityRule = new ActivityScenarioRule<>(LoginActivity.class);

dkdkdinesh000 avatar Aug 05 '20 14:08 dkdkdinesh000

Any solutions please. I am getting bellow error

java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x10000000 } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1598432534130 and now the last time the queue went idle was: 1598432534130. If these numbers are the same your activity might be hogging the event queue.

sudheertreddy avatar Aug 27 '20 05:08 sudheertreddy

I turned off all animations in Developer Settings on Android 5.0.2 API 21. It's work for me! Thanks to @piotrek1543

isanwenyu avatar Oct 10 '20 08:10 isanwenyu

any solutions?

Please try with ActivityScenarioRule instead of ActivityTestRule like below

@Rule 
public ActivityScenarioRule<LoginActivity> mActivityRule = new ActivityScenarioRule<>(LoginActivity.class);

It works! Thank you!!!!

lucaslrt avatar Jan 25 '21 20:01 lucaslrt

Turn on background popup permissions. It's work for me

DongDian455 avatar Nov 24 '21 12:11 DongDian455

Turn on background popup permissions. It's work for me

thats work thank

AlifAlRaf avatar Jan 13 '22 03:01 AlifAlRaf

Turn on background popup permissions. It's work for me

Where is this permission and how I can enable it ? Thanks

elysiunk avatar Mar 18 '22 16:03 elysiunk

@DongDian455 @AlifAlRaf What setting are you referring to here?

owens-ben avatar Nov 17 '22 15:11 owens-ben

Please try with ActivityScenarioRule instead of ActivityTestRule like below

Still happens even with that for my case, but not on every device. In general, I can reproduce that issue always on Android 6.0 and earlier. It works on Android 9.0 and above. I haven't got any 7.x and 8.x devices around to test for it...

My dependencies are:

dependencies {
    androidTestImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:rules:1.5.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

DoDoENT avatar Jan 25 '23 16:01 DoDoENT