如何获得iOS UITest上pickerWheels的所有可能值?

我在我的应用程序上有一个UIPickerView,有一个值列表,我们可以使用颜色。 选取器只有一个轮子,我设法使用这个代码来select值:

let app = XCUIApplication() app.launch() app.pickerWheels.element.adjustToPickerWheelValue("Yellow") 

但是我想要做的是在一个数组中获得这个轮子的所有可能的值,所以我可以使用数组值在select器中进行select。

另一个好的解决scheme是按索引而不是按键进行select,但我找不到方法。 有人?

我也在另一个问题上发布了这个。 您可以将选取器中的值数目设为x,然后将此函数调用x次。 随着值更新select器与您关联的单元格,您可以从中获取值以将其添加到您的数组中。

让我知道如果你有一些问题…

解决方法:

 let pickerWheel = XCUIApplication().pickers.pickerWheels.element let appWindowHeight = XCUIApplication().windows.elementBoundByIndex(0).frame.height let pickerWheelCellHeight = GFloat(44) func advancePickerWheelOneValue() -> Self { let topScrollPoint = Double(pickerWheel.frame.midY/appWindowHeight) let bottomScrollPoint = Double((pickerWheel.frame.midY + pickerWheelCellHeight)/appWindowHeight) let topScreenPoint = XCUIApplication().windows.elementBoundByIndex(0).coordinateWithNormalizedOffset(CGVector(dx: 0.5, dy: topScrollPoint)) let bottomScreenPoint = XCUIApplication().windows.elementBoundByIndex(0).coordinateWithNormalizedOffset(CGVector(dx: 0.5, dy: bottomScrollPoint)) bottomScreenPoint.pressForDuration(0, thenDragToCoordinate: topScreenPoint) return self } 

您可能需要根据select器的位置调整dx值。

 .coordinateWithNormalizedOffset(CGVector(dx: 0.5, 

但如果选取器占用屏幕的宽度,则0.5工作。

使用这种方法,您一次只能移动select器的值。 多次调用它,你得到你想要的价值。

它不理想,但它可以帮助,如果你想检查某些指标。 希望你将不得不在一个有数百个值的select器上使用它;)