Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Cannot scroll to view in NestedScrollView #116

Closed
minibugdev opened this issue Oct 19, 2018 · 4 comments
Closed

Cannot scroll to view in NestedScrollView #116

minibugdev opened this issue Oct 19, 2018 · 4 comments

Comments

@minibugdev
Copy link

Steps to reproduce:

Define layout with NestedScrollView

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView>
    <LinearLayout>
        .
        .
        .
        <Button>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

And scroll to view by scrollTo()

screen {
  snackbarButton {
      scrollTo()
      click()
  }

  snackbar {
      isDisplayed()
  }
}

Observed Results:

PerformException: Error performing 'scroll to' on view
@Unlimity
Copy link
Member

Hello there! Can you provide more info? Stacktrace at least?
And by the way, your button in provided example is named snackbarButton. Are you actually calling snackbar? If so, snackbar is added to your root view and there is no need to scroll to it. Also please provide your screen class, maybe matching is wrong.

@minibugdev
Copy link
Author

minibugdev commented Oct 19, 2018

Hi, sorry to have confused you.
I try to scroll to button, which inside NestedScrollView and click it
and lastly assert SnackBar should display

Updated code as below
Layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/content"
	android:layout_width="match_parent"
	android:layout_height="match_parent">

	<LinearLayout
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:orientation="vertical">

		<Space
			android:layout_width="wrap_content"
			android:layout_height="600dp"
			android:textColor="@color/background_color" />

		<Button
			android:id="@+id/button"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="BUTTON" />
	</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Screen

    val content: KView = KView { withId(R.id.content) }
    val button: KButton = KButton { withId(R.id.button) }

    val snackbar: KSnackbar = KSnackbar()

Test

    @Test
    fun testContentScreen() {
        screen {
            content {
                isVisible()
            }

            button {
                scrollTo()
                click()
            }

            snackbar {
                isDisplayed()
            }
        }
    }

An exception

android.support.test.espresso.PerformException: Error performing 'scroll to' on view '(with id: com.agoda.sample:id/button)'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:84)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:81)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:167)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:110)
at com.agoda.kakao.BaseActions$DefaultImpls.scrollTo(Actions.kt:148)
at com.agoda.kakao.KBaseView.scrollTo(Views.kt:30)
at com.agoda.sample.NestedScrollViewActivityTest$testContentScreen$1$2.invoke(NestedScrollViewActivityTest.kt:26)
at com.agoda.sample.NestedScrollViewActivityTest$testContentScreen$1$2.invoke(NestedScrollViewActivityTest.kt:11)

@minibugdev
Copy link
Author

I resolved by create custom action like

class NestedScrollActions(private val original: ScrollToAction = ScrollToAction()) : ViewAction by original {

    override fun getConstraints(): Matcher<View> = CoreMatchers.anyOf(
            CoreMatchers.allOf(
                    withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE),
                    isDescendantOfA(isAssignableFrom(NestedScrollView::class.java)))
            , original.constraints
    )
}

and use act for perform it

button {
    act {
        NestedScrollActions()
    }
    click()
}

Anyway, I'm not sure this is good enough solution for make a PR.

@minibugdev minibugdev reopened this Oct 22, 2018
@minibugdev minibugdev reopened this Oct 22, 2018
@Unlimity
Copy link
Member

Maybe the problem was with how you matched your button. It is possible that you need to match your button as a child of nested scroll view in your screen class. Cheers!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants