Espresso testinde bir düğmeye tıklandığında sorun oluştu. "Activity1" ve "Activity2" adlı iki etkinliğim olduğunu varsayalım. Aktivite1'de bir iletişim kutusu tıklandığında Activity1, Activity2 içindeki düğmenin tıklanamadığı Activity2'yi başlatır. İkinci etkinlikte tıklama düğmesine basıldığında 'tek tıklatma' gerçekleştirilirken hata oluştu veya
// The current activity in testing
// .....
onView(withText(R.string.dialog_btn_ok)).perform(click()); // go to the second activity
// The button on the second activity
onView(withId(R.id.btnMP)).check(matches(isDisplayed())); // this is ok
onView(withId(R.id.btnMP)).perform(click()); // got error here
android.support.test.espresso.PerformException: Error performing 'single click' on view 'with id: ..........
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view's area is displayed to the user. Target view: "Button{id=2131296390, res-name=btnMP, visibility=VISIBLE, width=652, height=160, 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=20.0, y=-16.0, text=Modify Parameter, input-type=0, ime-target=false, has-links=false}"
Ben perform(scrollTo())
ile bu değişiklik
// The button on the second activity
onView(withId(R.id.btnMP)).check(matches(isDisplayed())); // this is ok
onView(withId(R.id.btnMP)).perform(scrollTo(), click()); // got error here
android.support.test.espresso.PerformException: Error performing 'scroll to' on view 'with id ....
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=2131296390, res-name=btnMP, visibility=VISIBLE, width=652, height=160, 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=20.0, y=-16.0, text=Modify Parameter, input-type=0, ime-target=false, has-links=false}" at
Hata iletisinde de belirtildiği gibi, muhtemelen tüm görünümün alanının% 90'ını göstermiyor. 'IsDisplayed()' yerine, 'isCompletelyDisplayed()' ı, ya da daha da iyisi, 'isDisplayingAtLeast()' değerini yüzde 90 olarak kullanmayı deneyin. – GVillani82
Evet, 'isCompletelyDisplayed()' hatayla başarısız 'DefaultFailureHandler $ AssertionFailedWithCauseError:' görünüm alanının en az yüzde 100'ü kullanıcıya gösterilir. ' seçili görünümle eşleşmiyor. Bunun için ne yapabilirim? – Sithu
Test cihazındaki animasyonları devre dışı bıraktınız mı? Bunları devre dışı bıraktığınızdan emin olun: ayarlar> geliştirici seçeneklerine gidin ve "Pencere animasyon ölçeği", "Geçiş animasyon ölçeği" ve "Animatör süresi ölçeği" ni devre dışı bırakın – GVillani82