Ben*_*Ben 5 automation accessibility textfield xctest wkwebview
Xcode 11.3 附带的 iOS 13.3 模拟器中的 XCTest 自动化/可访问性行为发生了一些变化。我的 UI 测试代码突然在 WKWebView 中找不到 textField。
我有一个 UI 测试,它运行良好很长时间,包括在 iOS 13.2 sims 中。该测试查找具有特定值的 textField。这是一些测试 HTML,使用loadFileURL以下命令加载到 WKWebView 中:
<body>
<div>
<input type="text" placeholder="User name">
</div>
<body>
Run Code Online (Sandbox Code Playgroud)
这是测试代码。在 iOS 13.2 中测试通过,您可以看到正在输入的文本。在 iOS 13.3 中,它永远找不到元素并且测试失败:
func testExample() {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
// Enter text in the username field
let userNameField = app.webViews.textFields["User name"]
if userNameField.waitForExistence(timeout: 10) {
userNameField.tap()
userNameField.typeText("Harry Potter")
}
XCTAssert(userNameField.exists)
}
Run Code Online (Sandbox Code Playgroud)
如果我在<div>前面添加一个字符<input>在 HTML,则测试有效。
如果我在 iOS 13.2 sim 上运行相同的代码,即使使用 Xcode 11.3,它也能正常工作。它仅在 iOS 13.3 sim 上失败。
任何人都可以阐明正在发生的事情吗?