android / testing-samples

A collection of samples demonstrating different frameworks and techniques for automated testing
Apache License 2.0
9.18k stars 3.61k forks source link

Could not launch intent Intent Espresso again #143

Open abanksdev opened 7 years ago

abanksdev commented 7 years ago

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?

eugenio-caicedo commented 7 years ago

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, "foo@example.com");

        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);
    }
WangWen-Albert commented 4 years ago

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

febinmathew commented 4 years ago

any solutions?

piotrek1543 commented 4 years ago

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).

dkdkdinesh000 commented 4 years ago

any solutions?

Please try with ActivityScenarioRule instead of ActivityTestRule like below

@Rule 
public ActivityScenarioRule<LoginActivity> mActivityRule = new ActivityScenarioRule<>(LoginActivity.class);
sudheertreddy commented 4 years ago

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.

isanwenyu commented 3 years ago

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

lucaslrt commented 3 years ago

any solutions?

Please try with ActivityScenarioRule instead of ActivityTestRule like below

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

It works! Thank you!!!!

DongDian455 commented 2 years ago

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

AlifAlRaf commented 2 years ago

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

thats work thank

elysiunk commented 2 years ago

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

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

owens-ben commented 1 year ago

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

DoDoENT commented 1 year ago

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'
}