简体   繁体   English

我无法单击Espresso复选框

[英]I can't click checkbox with Espresso

I am writing some tests with espresso. 我正在用浓缩咖啡写一些测试。 I want to click on checkbox and checked it with test. 我想点击复选框并用测试检查它。 But I can't. 但我不能。 I tried with ıd and contentdescription. 我尝试了ıd和contentdescription。 Espresso found views but can't perform. Espresso找到了视图但无法执行。

  onView(withContentDescription("register check box 1"))
                        .check(matches(isNotChecked()))
                        .perform(click())
                        .check(matches(isChecked()));

I got that error. 我收到了那个错误。

android.support.test.espresso.PerformException: Error performing 'sıngle click' on view 'with content description: is "register check box 1"'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:70)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:53)
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)

I found the solution. 我找到了解决方案。 In my view xml checkbox has that line android:layout_marginLeft="-5dp". 在我看来,xml复选框有一行android:layout_marginLeft =“ - 5dp”。 I remove it and works perfectly. 我删除它并完美地工作。 But I can't understand the reason. 但我无法理解原因。

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

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