gpt4 book ai didi

android - Espresso - 无法使用 Espresso 执行按钮点击

转载 作者:行者123 更新时间:2023-11-29 14:59:47 30 4
gpt4 key购买 nike

我目前不熟悉自动化测试和使用 Android Studio 使用 Espresso 执行自动化测试,我正在尝试对登录屏幕执行自动化测试,我目前在执行特定按钮的点击时遇到问题。我尝试了多种按钮方法,但对我没有用。我引用以下文档来实现,下面是我的示例代码和崩溃报告。

@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginTest {
@Rule
public ActivityTestRule<LoginActivity> mActivityRule =
new ActivityTestRule<>(LoginActivity.class);
@Test
public void OnLoginButtonClick() throws InterruptedException {
onView(ViewMatchers.withId(R.id.edtUserName)).perform(ViewActions.typeText("xxxxx"));
onView(ViewMatchers.withId(R.id.edtPassword)).perform(ViewActions.typeText("xxxxxxx"));
onView(ViewMatchers.withId(R.id.btnLogin)).perform(ViewActions.scrollTo(),ViewActions.click());
}
}

崩溃报告:

android.support.test.espresso.PerformException: Error performing 'scroll to' on view 'Animations or transitions are enabled on the target device.

with id: xxx.xxxx.xxx.xxxx:id/btnLogin'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at com.msf.opx.LoginTest.OnLoginButtonClick(LoginTest.java:50)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
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 android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
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)
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(view has effective visibility=VISIBLE and is descendant of a: (is assignable from class: class android.widget.ScrollView or is assignable from class: class android.widget.HorizontalScrollView))
Target view: "Button{id=2131165273, res-name=btnLogin, visibility=VISIBLE, width=1320, height=152, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=60.0, y=1387.0, text=Login, input-type=0, ime-target=false, has-links=false}"
at

最佳答案

目标设备上启用了动画或过渡。

Espresso 不适用于动画,因为它们引入了视觉状态延迟。您需要禁用设备上的动画。首先,enable developer options

打开“设置”应用。

  1. 滚动到底部并选择关于手机。

  2. 滚动到底部并点击内部版本号 7 次。

  3. 返回上一屏幕,在底部附近找到开发者选项。
  4. 从“设置”应用访问“开发者选项”,然后在“绘图”部分下,将以下所有选项切换为“关闭动画”:

    1. 窗口动画比例
    2. 过渡动画比例
    3. 动画师持续时间比例

关于android - Espresso - 无法使用 Espresso 执行按钮点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49691207/

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