我在 iOS 10.3.2 和 Xcode 8.3.3 下的 Swift 中的 UITesting 遇到了一个奇怪的问题。
我正在我的应用程序中运行一个简单的测试,它应该点击并验证 TableView 中的每一行(是我的应用程序的设置视图,因此每一行都是从磁盘加载的,并且在此步骤中没有从 Web 下载任何内容),但是出于一个奇怪的原因,当我点击以前不可见的行时, .tap() 方法不起作用。
示例代码:
let app = XCUIApplication()
let myTableView = app.tables.element(matching: .table, identifier: "tableView01")
myTableView.swipeUp(). //I swipe so that the cell becomes visible...
let myCell = myTableView.cells.element(matching: .cell, identifier: "tappableCell")
myCell.tap()
奇怪的是,我在 Xcode 的控制台中有正确的输出。
t = 328.24s Tap "tappableCell" Cell
t = 328.24s Wait for app to idle
t = 328.80s Find the "tappableCell" Cell
t = 328.80s Snapshot accessibility hierarchy for com.thefloow.enterprise.ownbrand
t = 328.92s Find: Descendants matching type Table
t = 328.92s Find: Element at index 0
t = 328.92s Find: Descendants matching type Cell
t = 328.92s Find: Elements matching predicate '"tappableCell" IN identifiers'
t = 329.04s Wait for app to idle
t = 329.22s Synthesize event
t = 329.37s Wait for app to idle
另一个奇怪的事情是,如果我在 tap 方法之前放置一个断点,然后我从命令行运行它,它可以完美地为我提供与控制台相同的输出。
这种奇怪行为的原因可能是什么?
谢谢您的帮助!安德烈亚