简体   繁体   English

浓缩咖啡-无法使用浓缩咖啡执行按钮单击

[英]Espresso - Unable to perform the button click using espresso

I'm currently new to automation testing and performing automation tests with Espresso using Android Studio, I'm trying to perform automation testing for the login screen, I'm currently having trouble performing the click for a specific button. 我目前不熟悉自动化测试,也无法使用Android Studio使用Espresso执行自动化测试,我正在尝试对登录屏幕进行自动化测试,目前在执行特定按钮的单击时遇到麻烦。 I have tried multiple ways button nothing works for me. 我尝试了多种方法,但按钮对我没有用。 I am referring the following document to implement and below is my sample code and crash report. 我指的是要实施的以下文档,以下是我的示例代码和崩溃报告。

@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());
    }
}

Crash Report: 崩溃报告:

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 

Animations or transitions are enabled on the target device. 在目标设备上启用了动画或过渡。

Espresso doesn't work well with animations due to the visual state delays they introduce. 由于动画会引入视觉状态延迟,因此Espresso不适用于动画。 You need to disable animations on your device. 您需要在设备上禁用动画。 Firstly, enable developer options 首先, 启用开发人员选项

Open the Settings app. 打开设置应用。

  1. Scroll to the bottom and select About phone. 滚动到底部,然后选择关于手机。

  2. Scroll to the bottom and tap Build number 7 times. 滚动到底部,然后点击内部版本号7次。

  3. Return to the previous screen to find Developer options near the bottom. 返回上一个屏幕,在底部附近找到开发人员选项。
  4. Access Developer Options from Settings app, and under the Drawing section, switch all of the following options to Animation Off: 从“设置”应用访问“开发人员选项”,然后在“绘图”部分下,将以下所有选项切换为“关闭动画”:

    1. Window animation scale 窗口动画比例
    2. Transition animation scale 过渡动画比例
    3. Animator duration scale 动画师持续时间量表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM