如何在iOS UITest 上获取pickerWheels 的所有可能值? [英] How to get all possible values of a pickerWheels on iOS UITest?

查看:11
本文介绍了如何在iOS UITest 上获取pickerWheels 的所有可能值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序上有一个 UIPickerView,带有值列表,我们可以使用颜色.选择器只有一个轮子,我设法使用以下代码选择值:

I have a UIPickerView on my app, with a list of values, we can use Colors. The picker has only one wheel, and I manage to select the value by using this code:

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

但是我想要做的是在一个数组中获取这个轮子的所有可能值,这样我就可以使用数组值在选择器中进行选择.

But what I want to do is to get all the possible values of this wheel in an Array, so I can use the array values to select in the picker.

另一个好的解决方案是按索引而不是按键进行选择,但我找不到这样做的方法.有人吗?

Another good solution would be to make the selection by index instead of by key, but I could not find ways of doing that. Someone?

推荐答案

我也在另一个问题上发布了这个.您可以将选择器中的值数量作为 x,然后调用此函数 x 次.当值更新与选择器关联的单元格时,您可以从那里获取值以将其添加到您的数组中.

I posted this on another question as well. You could get the number of values in the picker as x, then call this function x number of times. And as the value updates the cell the picker is associated with you can grab the value from there to add it to your array.

如果您有任何问题,请告诉我...

Let me know if you have some questions...

解决方法:

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
    }

您可能需要根据选取器所在的位置调整 dx 值.

You may need to adjust the dx value depending on where the picker is.

.coordinateWithNormalizedOffset(CGVector(dx: 0.5,

但是如果选择器占据屏幕的宽度,则 0.5 有效.

But 0.5 works if the picker occupies the width of the screen.

使用此方法,您可以一次移动选择器的值.多次调用它,你就会得到你想要的值.

With this method you an move the picker on value at a time. Call it multiple times and you get to the value you want.

它并不理想,但如果您想检查某些索引,它会有所帮助.希望您必须在具有数百个值的选择器上使用它 ;)

Its not ideal but it can help if you want to check certain indexes. Hopefully you would have to use it on a picker with hundreds of values ;)

这篇关于如何在iOS UITest 上获取pickerWheels 的所有可能值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆