2015-11-03 14 views
12

SwipeRefreshLayout पर डाउन-स्वाइप करने पर मेरा ऐप डेटा पुनः लोड करता है। अब मैं एंड्रॉयड टेस्ट किट के साथ इस परीक्षण करने की कोशिश/एस्प्रेसो इस तरह:एस्प्रेसो: SwipeRefreshLayout का परीक्षण कैसे करें?

onView(withId(R.id.my_refresh_layout)).perform(swipeDown()); 

दुर्भाग्य से इस

android.support.test.espresso.PerformException: Error performing 'fast swipe' 
on view 'with id: my.app.package:id/my_refresh_layout'. 
... 
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: "SwipeRefreshLayout{id=2131689751, res-name=my_refresh_layout, visibility=VISIBLE, 
width=480, height=672, has-focus=false, has-focusable=true, 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=0.0, y=0.0, 
child-count=2}" 

बेशक साथ विफल रहता है, लेआउट दिखाई दे रहा है और मैन्युअल रूप से स्वाइप काम करता है, लेकिन मैं अनिश्चित हूँ अगर मैं कुछ गलत कर रहा हूँ? लेआउट पूरी स्क्रीन फैलाता है, इसलिए वास्तव में एस्प्रेसो के लिए कुछ कार्रवाई करने के लिए संभव होना चाहिए।

उत्तर

30

इससे सोते समय कभी-कभी मदद मिलती है। अंतर्निहित कारण यह था कि उपयोगकर्ता को केवल 89% दिखाई देने वाला दृश्य था, जबकि एस्प्रेसो की स्वाइप क्रियाएं आंतरिक रूप से 90% की मांग करती थीं। यह तो इस तरह कहा जा सकता है

public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) { 
    return new ViewAction() { 
     @Override 
     public Matcher<View> getConstraints() { 
      return constraints; 
     } 

     @Override 
     public String getDescription() { 
      return action.getDescription(); 
     } 

     @Override 
     public void perform(UiController uiController, View view) { 
      action.perform(uiController, view); 
     } 
    }; 
} 

:: तो समाधान इस तरह एक और कार्रवाई में कड़ी चोट कार्रवाई लपेटो और हाथ से इन बाधाओं ओवरराइड करने के लिए, है

onView(withId(R.id.my_refresh_layout)) 
    .perform(withCustomConstraints(swipeDown(), isDisplayingAtLeast(85)); 
संबंधित मुद्दे