- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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/
在android支持测试库中,为recyclerview编写测试用例时,某些演示使用TypeSafeMatcher,而其他演示则使用BoundedMatcher。谁能解释我为什么在使用示例或用例时使用
我们目前正在为我们的应用程序的一个区域编写 Espresso UI 测试,这需要我们在每次测试后清除应用程序数据 我们之前尝试过使用 Android Orchestrator 我们之前曾尝试使用带有
我已经看到了一些关于它的问题。 例如。 Android Espresso testing app flow 但是上面的答案在espresso 2中不起作用。这是我的摘录 @Rule public Ac
我正在尝试建立一个测试农场,但我发现了一个很大的障碍。手机处于休眠状态时无法运行 Espresso 测试。 android.support.test.espresso.NoActivityResume
我正在运行“gradlew connectedCheck”来在已安装的应用程序上运行 Espresso 测试,但是这个“gradlew connectedCheck”重写了我的应用程序,然后运行测试。
使用 AndroidInjector 和 Subcomponents 无法将作用域对象的事件注入(inject) Espresso 的 Test 类。 以前使用应用程序级组件和事件组件,只要您创建一个
我正在使用Espresso为我的Android应用程序编写UI测试,并想使用MockWebServer模拟HTTP请求。 在运行测试之前,我需要模拟身份验证响应并登录用户。 有没有一种方法可以使应用程
我有一个 ExpandableListView,我想 click() 它的一个 subview 。 我尝试了LOADS OF不同的方法,但我似乎无法理解 Espresso 的工作原理。 例如,为什么这
我目前不熟悉自动化测试和使用 Android Studio 使用 Espresso 执行自动化测试,我正在尝试对登录屏幕执行自动化测试,我目前在执行特定按钮的点击时遇到问题。我尝试了多种按钮方法,但对
Windows 10(64 位), 安卓工作室 3.1.2, Gradle 4.4,Java 1.8。 这是我的布局 xml 这里 @drawable/sign_in_login_bg
Firebase 测试实验室接受 App Bundle/APK 和 android 测试 APK,并且动态功能模块 UI 测试在 Firebase 测试实验室中失败。该错误是关于一些多 dex 问题,
根据我在网络上所做的搜索,我发现很少有人认为 Espresso UI 测试框架不支持 WebViews?是这样吗? 最佳答案 Espresso 支持 WebView,我在下面添加了一个示例 http:
使用 Espresso,我希望能够单击 ExpandableListView(名为 CustomExpandableView)的特定子项。 listview 创建一组RelativeLayouts(名
我有我的 xml 布局: 我想写 Espresso 测试检查 EditText 有android:drawableStart="@drawable/ic_sign_in_password". 我该怎
我正在尝试为 Android 应用程序编写 Espresso 测试,并且需要知道如何自动化使用 AutoCompleteTextView 的部分。下面提到了我的应用程序使用的代码: activity_
我正在尝试为 Android 应用程序编写 Espresso 测试,并且需要知道如何自动化使用 AutoCompleteTextView 的部分。下面提到了我的应用程序使用的代码: activity_
在我的应用中,我使用 Kotlin Flow。在我通过 EspressoIdlingResource.increment() 使用挂起函数之前,它不适用于 Kotlin Flow。如何解决这个问题?
在我的应用中,我使用 Kotlin Flow。在我通过 EspressoIdlingResource.increment() 使用挂起函数之前,它不适用于 Kotlin Flow。如何解决这个问题?
我正在尝试使用 onData 运行 espresso 测试,对于其中只有一个 AdapterView 的 View ,一切正常。但是,当屏幕显示其中嵌套了多个适配器 View 的 View 时,我得到
我想测试是否显示 ID 为 imageViewTour 且标签包含 some_text 的 imageView。 我的测试: onView(allOf(withId(R.id.imageViewTou
我是一名优秀的程序员,十分优秀!