Clicking button on second activity got error performing 'single click' or 'scroll to' on view

后端 未结 2 561
夕颜
夕颜 2020-12-17 07:40

Clicking a button in Espresso test got problem. Let\'s say I have two activities \"Activity1\" and \"Activity2\". Click a dialog OK button in Activity1 starts Activity2 wher

相关标签:
2条回答
  • 2020-12-17 08:02

    The solution is to create your custom GeneralClickAction with view visibility that you want to click less then Espresso's GeneralClickAction requires. Currently the minimum visibility value is 90% - see code here line 60. Set it to be 80% or less. Just copy the whole class rename it and change the value provided to this method to 80 isDisplayingAtLeast(80). Then create your click action that uses your custom GeneralClickAction:

      public static ViewAction customClick() {
          return actionWithAssertions(
              new CustomGeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER));
      }
    

    But I'd rather fix the layout of the activity if possible to avoid creation of workaround for button visibility.

    0 讨论(0)
  • 2020-12-17 08:19

    Seems your view with id R.id.btnMP is not visible at the screen so you are receiving the first error. You are trying to resolve this by scrollTo() but your view in not inside ScrollView. So how your activity is organized? If you are using RecyclerView (for example) you should use special version of scrollTo - http://developer.android.com/reference/android/support/test/espresso/contrib/RecyclerViewActions.html and so on. So first take a look where your view is hosted and then it will be clear how to scroll to it.

    0 讨论(0)
提交回复
热议问题