2016-11-30 54 views
0

我正在寫一些測試,我需要去滑塊的中間。我想獲得滑塊的minimumValue和maximumValue,如下圖所示: enter image description here(Swift,EarlGrey)將滑塊移動到中間

這些值可能會改變,所以每次我需要在我的代碼中獲取它們。後來,我只是想獲得這兩個值的平均值,並且使用的方法

performAction:grey_moveSliderToValue(valueToMove) 

我怎樣才能得到minumumValue和maximumValue在我的代碼將滑塊移動到中間?這是最好的方法還是有更好的將播放頭移動到滑塊中間?

回答

2

您可以使用EarlGrey的GREYActionBlock創建幻燈片一半

// Create a new action that slides to half. 
GREYActionBlock *slideToHalfAction = [GREYActionBlock actionWithName:@"slideToHalf" 
                 constraints:grey_kindOfClass([UISlider class]) 
                 performBlock:^BOOL(id element, NSError *__strong *errorOrNil) { 
    UISlider *slider = element; 
    float minValue = slider.minimumValue; 
    float maxValue = slider.maximumValue; 
    float halfValue = (minValue + maxValue)/2; 
    return [grey_moveSliderToValue(halfValue) perform:element error:errorOrNil]; 
}]; 

// Use the new action on the slider. 
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider4")] performAction:slideToHalfAction]; 
+0

只需確保halfValue不落入小數像素的新動作,否則Earlgrey將無法設置滑塊halfValue,因爲它不是用戶可以實現。 – khandpur