2016-07-07 160 views
1

我有一個測試,可以在我的應用中選擇特定的源。它在iPhone 6s上正常工作,但在iPhone 5s上出現元素未找到錯誤時失敗。進一步調查後,似乎從視圖層次結構中缺少提要。我想出了一個解決辦法是,以這樣的:測試在iPhone 6s Plus上運行良好,但在iPhone 5s上運行失敗

if (running on iPhone 5s) { 
    // Scroll down by 50 units. 
    // Then locate the feed and check that it's visible. 
    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"feed10")] 
     assertWithMatcher:grey_sufficientlyVisible()]; 
} 

雖然這似乎很好,我想知道是否有更好的方法來有條件地滾動,如果元素不是在屏幕上找到。

回答

1

EarlGrey提供了usingSearchAction:onElementWithMatcher: api來查找需要滾動到的元素以找到它們。由於您使用的是grey_sufficientlyVisible(),因此要求該元素在屏幕上可見,以便assertWithMatcher檢查通過。從他們的常見問題,你可以改變你的斷言是以下幾點:

if (running on iPhone 5s) { 
    [[EarlGrey selectElementWithMatcher:matcher] 
        usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 50) 
       onElementWithMatcher:grey_accessibilityID(@"feed10") 
        assertWithMatcher:grey_sufficientlyVisible()]; 
} 

僅供參考 - 你用kGREYDirectionDown,因爲它表示視口的變化的方向,而不是滾動完成刷卡的方向。

相關問題