无法在 XCTest 中访问以编程方式添加的 UIView
Can not access the programatically added UIView in XCTest
下面是我录制的XCTest
let app = XCUIApplication()
let tablesQuery = app.tables
tablesQuery.staticTexts["Video"].tap()
tablesQuery.staticTexts["\tWindowed"].tap()
app.buttons["Launch"].tap()
app.buttons["Popout Video"].tap()
app.children(matching: .window).element(boundBy: 0).children(matching: .other).element(boundBy: 1).tap()
当我尝试 运行 测试时,最后一部分是:
app.children(matching: .window).element(boundBy: 0).children(matching: .other).element(boundBy: 1).tap()
无法访问。它不会抛出任何错误,但不会执行最后一行代码。
我已经尝试通过参考以下 Whosebug 问题来解决问题:
https://developer.apple.com/reference/uikit/uiview
但这一切似乎都没有解决问题。任何帮助将不胜感激。
有问题的线路非常脆弱。有可能您的应用程序的视图在每次应用程序启动时并不总是以相同的顺序可用,这取决于竞争条件,因此记录会话中记录的内容不一定适用于应用程序的所有启动。您可能会发现代码实际上是 运行,但没有点击您期望的元素。
为了让您的代码不那么脆弱,请在您的应用程序代码中向 UIView 添加可访问性标识符,并使用 otherElements
查询来查找 UIView。
// app code
let view: UIView!
view.accessibilityIdentifier = "myAccessibilityIdentifier"
// UI test code
app.otherElements["myAccessibilityIdentifier"].tap()
下面是我录制的XCTest
let app = XCUIApplication()
let tablesQuery = app.tables
tablesQuery.staticTexts["Video"].tap()
tablesQuery.staticTexts["\tWindowed"].tap()
app.buttons["Launch"].tap()
app.buttons["Popout Video"].tap()
app.children(matching: .window).element(boundBy: 0).children(matching: .other).element(boundBy: 1).tap()
当我尝试 运行 测试时,最后一部分是:
app.children(matching: .window).element(boundBy: 0).children(matching: .other).element(boundBy: 1).tap()
无法访问。它不会抛出任何错误,但不会执行最后一行代码。
我已经尝试通过参考以下 Whosebug 问题来解决问题:
https://developer.apple.com/reference/uikit/uiview
但这一切似乎都没有解决问题。任何帮助将不胜感激。
有问题的线路非常脆弱。有可能您的应用程序的视图在每次应用程序启动时并不总是以相同的顺序可用,这取决于竞争条件,因此记录会话中记录的内容不一定适用于应用程序的所有启动。您可能会发现代码实际上是 运行,但没有点击您期望的元素。
为了让您的代码不那么脆弱,请在您的应用程序代码中向 UIView 添加可访问性标识符,并使用 otherElements
查询来查找 UIView。
// app code
let view: UIView!
view.accessibilityIdentifier = "myAccessibilityIdentifier"
// UI test code
app.otherElements["myAccessibilityIdentifier"].tap()