2016-05-23 45 views
1

我有一個選擇器視圖,並希望選擇8 - Sohail或9 - Sohail,但我無法使用XCUIElementQuery查找XCElement。當我重寫'pickerView - viewForRow'方法來定義我們自己的自定義視圖時,XCUIElementQuery無法找到它。代碼在這裏用於UIPickerView。不重寫viewForRow它工作正常。如果使用viewForRow UIPickerView測試案例中斷

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { 
    return 1 
} 

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
    return 10 
} 

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
    var i : String? 
    i = "\(row) - Sohail" 
    return i 
} 
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
    print("\(row) - Sohail") 
} 

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView { 

    let pickerLabel = UILabel() 

    pickerLabel.textColor = UIColor.greenColor() 

    pickerLabel.textAlignment = NSTextAlignment.Center 
    pickerLabel.text = "\(row) - Sohail" 
    return pickerLabel 
} 

而對於UI測試案例

func testPicker(){ 

    let app = XCUIApplication() 

//  print(app.pickerWheels.count) 
//  app.descendantsMatchingType(.PickerWheel)["1 - Sohail"].tap() 
//  print(app.pickerWheels.element) 
//  app.pickerWheels.elementBoundByIndex(0).swipeUp() 

    app.pickerWheels.element.adjustToPickerWheelValue("9 - Sohail") 

    sleep(2) 

//  app.pickerWheels["0 - Sohail"].tap() 
//  app.pickerWheels["8 - Sohail"].tap() 

} 

我得到這個失敗的消息。

UI Testing Failure - Internal error: unable to find current value '0 - Sohail, 1 of 10' in possible values 0 - Sohail, 1 - Sohail, 2 - Sohail, 3 - Sohail, 4 - Sohail, 5 - Sohail, 6 - Sohail, 7 - Sohail, 8 - Sohail, 9 - Sohail for the picker wheel "0 - Sohail, 1 of 10" PickerWheel

回答

0

的問題是在你的選擇器行的accessibilityValue被定義爲錯誤顯示的「CurrentValue的」,而不是你實際閱讀。錯誤報告on OpenRadar here