2015-06-16 7 views
11

Sto eseguendo il test seguente per convalidare il testo sullo schermo, Il testo è presente sulla vista ma è necessario scorrere la pagina per vedere il testo manualmente.Come scorrere lo schermo nel test del caffè espresso Android? Devo convalidare il testo presente sullo schermo

L'errore seguente è in arrivo, tuttavia il testo è presente sulla vista ma è necessario scorrere la pagina per visualizzare il testo manualmente.

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view. Expected: is displayed on the screen to the user Got: "TextView{id=2131361941, res-name=project_details_label_tv, visibility=VISIBLE, width=249, height=41, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=4.0, y=24.0, text=Status, input-type=0, ime-target=false, has-links=false}"

+0

ho risposto ad una domanda che farà proprio questo qui - http://stackoverflow.com/questions/28218155/espresso-how-to-do-custom-swipe-eg-swipetop-or-swipebottom/42399407 # 42399407 ... – Nefariis

risposta

2

Basta effettuare una ViewActions.scrollTo() prima affermazione:

onView(withText("Launch")).perform(ViewActions.scrollTo()).check(ViewAssertions‌​.matches(isDisplayed())); 
+0

* solo "Se la vista su cui si sta lavorando si trova all'interno di una ScrollView". – appoll

+0

Ciò potrebbe generare "NoMatchingViewException". –

12

io non so come questo layout assomiglia, ma di usare

Just perform a ViewActions.scrollTo() before your assertion:

`onView(withText("Launch")).perform(ViewActions.scrollTo()).check(ViewAssertions‌​.matches(isDisplayed()));` 

è necessario avere ScrollView come vista principale nella struttura.

Se avete già LinearLayout, RelativeLayout, si deve cambiare a questo modo:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

`

+0

Non credo che la tua affermazione su ScrollView sia corretta. La vista deve essere all'interno di una scrollview, ma non è necessario che ScrollView sia la vista principale (o principale) nel layout. –

1

È possibile utilizzare SWIPE per scorrere fino a parte inferiore dello schermo:

Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeUp()); 

Per me funziona bene.

Pablo

Problemi correlati