我有一个选择器视图,想要选择8 - Sohail或9 - Sohail,但我无法使用XCUIElementQuery找到XCElement。当我覆盖' pickerView - viewForRow'定义我们自己的自定义视图的方法,XCUIElementQuery无法找到它。代码在这里用于UIPickerView。没有覆盖viewForRow它可以正常工作。
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 :(得分:0)
问题是,选择器中的accessibilityValue
行被定义为错误中显示的“currentValue”,而不是您实际读取的内容。错误报告on OpenRadar here。