Google Espresso java.lang.RuntimeException:无法启动intent intent{act=android.intent.action.MAIN

Google Espresso java.lang.RuntimeException:无法启动intent intent{act=android.intent.action.MAIN,android,eclipse,runtimeexception,android-espresso,Android,Eclipse,Runtimeexception,Android Espresso,我对浓缩咖啡用户界面测试还不熟悉 我在运行测试(ADT Eclipse IDE)时遇到此错误 该应用程序已经开发,启动该应用程序时有很多请求。不可能重写该应用程序。但我需要找到方法来测试此UI,即使组件加载有任何延迟 java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.xx.android/com.yy.

我对浓缩咖啡用户界面测试还不熟悉

我在运行测试(ADT Eclipse IDE)时遇到此错误

该应用程序已经开发,启动该应用程序时有很多请求。不可能重写该应用程序。但我需要找到方法来测试此UI,即使组件加载有任何延迟

        java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.xx.android/com.yy.core.android.map.MapActivity } 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 1390913271702 and and now the last time the queue went idle was: 1390913271767. If these numbers are the same your activity might be hogging the event queue.
        at com.google.android.apps.common.testing.testrunner.GoogleInstrumentation.startActivitySync(GoogleInstrumentation.java:277)
        at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
        at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
        at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104)
        at com.gulesider.android.test.UItest.setUp(UItest.java:25)
        at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
        at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
        at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
        at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1799)
  • 我有一个名为“Core”的库项目,它不会生成任何.apk
  • 另外,我还有一个名为“AA”的Android项目,它将访问“Core”。-这是AA.apk
  • 现在我创建了一个名为“UItest”的测试项目
  • 舱单:

        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.AA.android.test"
            android:versionCode="1"
            android:versionName="1.0" >
        <uses-sdk android:minSdkVersion="8" 
                android:targetSdkVersion="18" />
        <instrumentation
          android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
          android:targetPackage="com.AA.android"/>
        <application
                android:allowBackup="true"
                android:icon="@drawable/ic_launcher"
                android:label="@string/app_name" >
        <activity
                    android:name="com.core.android.map.MapActivity"
                    android:label="@string/app_name" >
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>
                <uses-library android:name="android.test.runner" />
            </application>
        </manifest>
    
        public class UItest extends ActivityInstrumentationTestCase2<MapActivity> {
            public UItest() {
                super(MapActivity.class);
            }
    
            @Override
            public void setUp() throws Exception {
                super.setUp();
    
                getActivity();
    
            }
    
            public void testSearchBox() {
    
                Espresso.onView(ViewMatchers.withId(R.id.menu_button_logo)).perform(ViewActions.click());
    
            }
    
        }
    
    
    
    我的测试:

        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.AA.android.test"
            android:versionCode="1"
            android:versionName="1.0" >
        <uses-sdk android:minSdkVersion="8" 
                android:targetSdkVersion="18" />
        <instrumentation
          android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
          android:targetPackage="com.AA.android"/>
        <application
                android:allowBackup="true"
                android:icon="@drawable/ic_launcher"
                android:label="@string/app_name" >
        <activity
                    android:name="com.core.android.map.MapActivity"
                    android:label="@string/app_name" >
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>
                <uses-library android:name="android.test.runner" />
            </application>
        </manifest>
    
        public class UItest extends ActivityInstrumentationTestCase2<MapActivity> {
            public UItest() {
                super(MapActivity.class);
            }
    
            @Override
            public void setUp() throws Exception {
                super.setUp();
    
                getActivity();
    
            }
    
            public void testSearchBox() {
    
                Espresso.onView(ViewMatchers.withId(R.id.menu_button_logo)).perform(ViewActions.click());
    
            }
    
        }
    
    公共类UItest扩展了ActivityInstrumentationTestCase2{
    公共UItest(){
    super(MapActivity.class);
    }
    @凌驾
    public void setUp()引发异常{
    super.setUp();
    getActivity();
    }
    公共void testSearchBox(){
    Espresso.onView(ViewMatchers.withId(R.id.menu_button_logo)).perform(ViewActions.click());
    }
    }
    
    在第一页,您将调用太多的请求,这将花费超过15秒的时间,第一页应该非常轻。 只需创建一个新的欢迎页面,然后调用您原来的欢迎页面。
    希望这能为您带来帮助。

    您的活动中可能有动画,这会阻止浓缩咖啡的执行。您必须禁用它-有关浓缩咖啡测试,强烈建议您关闭虚拟或物理设备上的系统动画用于测试。因此,您可以按照以下步骤手动关闭动画:

    根据: 设置->
    开发者选项-> 绘图

  • 窗口动画缩放到关闭状态
  • 将动画比例转换为“关闭”
  • 动画持续时间缩放为关闭

  • 如果在创建“活动”时有一个进度条正在运行,则会出现如下错误。您应该停止进度条以继续运行测试。

    在我的案例中,自定义视图导致了此行为。它包含一个不断滚动的进度条。不幸的是,我直到现在才找到解决此问题的方法除了在测试中禁用它…

    在6.0设备上运行浓缩咖啡测试时,我遇到了这个错误,但在5.1.1或7.0设备上没有。我追踪到原因是在一个样式中使用了
    android:fadeScrollbars
    。从我的样式中删除这个项目解决了这个问题。

    嗯,在我的情况下,它是由一件奇怪的事情引起的

    我的一个UI测试打开了外部意图“android.app.action.CONFIRM\u DEVICE\u CREDENTIAL”,因此我决定将其存根。从现在开始,直到我手动关闭最近任务中“android.app.action.CONFIRM\u DEVICE\u CREDENTIAL”打开的屏幕,主意图才再次启动


    不知道为什么会发生这种情况,现在没有时间进行研究。也许以后我会更新此线程。

    当用户单击给定视图时,我尝试测试另一个活动的打开时遇到此错误。我所做的错误不是替换:

    @Rule
    public ActivityTestRule<MyActivity> myActivityActivityTestRule = new ActivityTestRule<>(MyActivity.class);
    
    @规则
    public ActivityTestRule myActivityActivityTestRule=新的ActivityTestRule(MyActivity.class);
    
    Per:

    @规则
    公共意图测试规则myActivityActivityTestRule=
    新的IntentsTestRule(MyActivity.class);
    
    我已经陷入这个问题好几个小时了。最后,我找到了原因

    这对我有用

    根据这一现象,这里有一些不同的原因

    • 无法启动活动
    • 已启动活动,但UI执行操作不起作用
    第一个场景:无法启动活动

    因为您的目标活动可能已经在活动堆栈中。 添加
    清除
    标志和
    新建任务
    标志

        @get:Rule
        val activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
    
        private lateinit var launchedActivity: MainActivity
    
        @Before
        fun setUp() {
            val intent = Intent(Intent.ACTION_PICK)
            //this is the key part
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
            //this is the key part
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            launchedActivity = activityRule.launchActivity(intent)
        }
    
    @get:Rule
    val activityRule=ActivityTestRule(MainActivity::class.java)
    私有lateinit var launchedActivity:MainActivity
    @以前
    趣味设置(){
    val intent=intent(intent.ACTION\u PICK)
    //这是关键部分
    intent.addFlags(intent.FLAG\u活动\u清除\u任务)
    //这是关键部分
    intent.addFlags(intent.FLAG\u活动\u新任务)
    LaunchDactivity=activityRule.launchActivity(意图)
    }
    
    第二个场景:已启动活动,但UI执行操作不起作用

    在这种情况下,可能是因为

  • 您的代码在很长一段时间内执行了一些动画
  • 您的代码正在执行您没有注意到的UI逻辑
    • 类似于处理程序post事件或可运行的
    • 像OnPreDrawListener一样在ViewTreeObserver中注册侦听器,并且没有在适当的时间取消注册

  • 这些操作可能会导致UI线程繁忙,因此浓缩咖啡无法进行测试

    我也遇到了这个问题,在我将物理设备换成其他Android手机的那一刻,测试正在进行。只需尝试使用其他设备。并使用@rule启动活动

    发布您的代码。当我遵循上述解决方案时注意,我收到此错误“由于缺乏权限而无法禁用动画”请尝试添加请求权限,正如上面链接的注释中所述,这是正确的-可见的
    ProgressBar
    可能是此异常的原因。请检查您的活动/片段是否没有可见的
    ProgressBar
    s(在ProgressBar中使用alpha时要小心)您是如何禁用它的?我告诉视图这是一个自定义视图,在测试运行时不要滚动。要确定它是否正在运行,我告诉我们