【问题标题】:How to select random tableview cell in XCode UI Automation using Swift如何使用 Swift 在 XCode UI 自动化中选择随机表格视图单元格
【发布时间】:2016-11-14 16:09:10
【问题描述】:
【问题讨论】:
标签:
swift
xcode
uitableview
swift3
xcode-ui-testing
【解决方案1】:
这取决于您如何获取部分和行信息。我这样做的方式是使用带有键的字典来保存这些部分。因此,您的部分标题是您的 dict 中的键,您的行作为这些键的值:
myDict.keys.count
获取您拥有的部分数量。然后你可以使用这样的函数来获取你的随机数:
func randomInt(min: Int, max:Int) -> Int {
return min + Int(arc4random_uniform(UInt32(max - min + 1)))
}
所以给一些快速的puedo代码:
let sectionCount = myDict.keys.count - 1
let keyArray = myDict.keys
let randomSection = randomInt(min: 0, max: sectionCount)
let rowCount = myDict[keyArray[randomSection]].count - 1
let randomRow = randomInt(min: 0, max: rowCount)