gpt4 book ai didi

android - Capacitor 应用程序上的 Espresso 测试显示 "Could not launch intent Intent within 45 seconds"

转载 作者:行者123 更新时间:2023-12-04 04:03:02 25 4
gpt4 key购买 nike

我正在尝试使用 Capacitor 应用实现 Espresso 测试。测试看起来像这样:

package com.getcapacitor.myapp;

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

import android.content.Intent;

import androidx.test.espresso.web.webdriver.DriverAtoms;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import ekt.moveus.applikate.MainActivity;

import static androidx.test.espresso.web.sugar.Web.onWebView;
import static androidx.test.espresso.web.webdriver.DriverAtoms.clearElement;
import static androidx.test.espresso.web.webdriver.DriverAtoms.findElement;
import static androidx.test.espresso.web.webdriver.DriverAtoms.webClick;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@LargeTest
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<MainActivity>(
MainActivity.class, false, true) {
@Override
protected void afterActivityLaunched() {}
};

private final static String USER_EMAIL = "email@gmail.com";
private final static String USER_PASS = "password";

@Test
public void typeTextInInput_clickButton_SubmitsForm() {
Intent webFormIntent = new Intent();
mActivityRule.launchActivity(webFormIntent);
onWebView()
.withElement(findElement(Locator.NAME, "ion-input-1"))
.perform(clearElement())
.perform(DriverAtoms.webKeys(USER_EMAIL))

.withElement(findElement(Locator.NAME, "ion-input-0"))
.perform(clearElement())
.perform(DriverAtoms.webKeys(USER_PASS))

.withElement(findElement(Locator.NAME, "ion-input"))
.perform(webClick());
}
}

但是当我运行测试用例时出现这个错误:

java.lang.RuntimeException: Could not launch intent Intent { flg=0x10000000 cmp=ekt.moveus.applikate/.MainActivity } 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 1594199984877 and now the last time the queue went idle was: 1594200024655. If these numbers are the same your activity might be hogging the event queue.
at androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:481)
at androidx.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:358)
at com.getcapacitor.myapp.ExampleInstrumentedTest.typeTextInInput_clickButton_SubmitsForm(ExampleInstrumentedTest.java:44)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531)
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 androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
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 androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2209)

据我所知,在阅读了一些问题和教程后,它可能是由动画(我在模拟器上禁用它们)、某些组件或自定义 View 的不断重绘引起的。由于电容器在后台工作,我真的不知道是什么导致了这个问题。

有人遇到过这个吗?如何使用 Capacitor App 正确实现 Espresso 测试用例?

谢谢

最佳答案

问题是您要启动该 Activity 两次。首先,您设置规则以立即启动 Activity (通过将第三个参数设置为 true 中的 new ActivityTestRule<MainActivity>(MainActivity.class, false, true) ,然后在测试中,您再次明确启动 Activity (通过执行 mActivityRule.launchActivity(webFormIntent); )。

将第三个参数设置为false相反。

关于android - Capacitor 应用程序上的 Espresso 测试显示 "Could not launch intent Intent within 45 seconds",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62791615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com