2017-03-07 79 views
1

我有RecyclerView咖啡RecyclerView在SwipeRefreshLayout塊測試

<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/dashboard_swiperefreshlayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/events_dashboard_listview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="none"/> 

</android.support.v4.widget.SwipeRefreshLayout> 

女巫處於Viewpager片段。 我正在使用volley與自定義IdleResurs進行服務器調用。

我想打開抽屜:

openDrawer(R.id.drawer_layout); 
isOpen(); 

但是,錯誤的測試掛起:

Could not launch intent Intent within 45 seconds 

如果我手動滾動RecycleView或適配器改變顯示的頁面的測試仍在繼續,抽屜被打開。

回答

0

SwipeRefreshLayout的加載指示符可能會顯示,因此會阻止UI,因爲它是動畫。避免佈局顯示動畫的快速解決方法是使用類似下面的代碼:

class TestableSwipeRefreshLayout : SwipeRefreshLayout { 

    constructor(context: Context) : super(context) 

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) 

    companion object { 

     var isTestRunning = false 

    } 

    override fun setRefreshing(refreshing: Boolean) { 
     if (!isTestRunning) { 
      super.setRefreshing(refreshing) 
     } 
    } 

}