【问题标题】:How to select random tableview cell in XCode UI Automation using Swift如何使用 Swift 在 XCode UI 自动化中选择随机表格视图单元格
【发布时间】:2016-11-14 16:09:10
【问题描述】:

我正在使用 XCode UI 测试执行自动化。在一个场景中,我必须在具有多个部分的 UITableView 上执行自动化,有什么方法可以获取特定部分的单元格计数并点击该特定组中的随机单元格。

我的 UITableView 类似于下面 http://blog.apoorvmote.com/uitableview-with-multiple-sections-ios-swift/

【问题讨论】:

    标签: 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)
    

    【讨论】:

      猜你喜欢
      • 2014-11-17
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      • 2016-05-01
      • 2011-07-08
      • 1970-01-01
      相关资源
      最近更新 更多