gpt4 book ai didi

iOS 9 UI 测试 - 测试失败,因为目标控件不可用(尚未)

转载 作者:可可西里 更新时间:2023-11-01 05:04:22 29 4
gpt4 key购买 nike

我正在测试 Xcode 7 的新 UI 测试功能(在 WWDC 2015 视频“UI Testing in Xcode”中介绍)。

启动时,我的应用通过更新其垂直布局约束的值将“登录面板”设置为动画:面板从主视图下方(屏幕外)向上滑动进入 View 。

面板包含两个文本字段,用于用户名密码

当您为用户名 文本字段(标记为“下一步”)点击键盘上的返回键时,密码 文本字段将成为第一响应者。当您点击密码文本字段的重新运行键(标记为“Go”)时,面板将“关闭”(即动画退出屏幕),事件指示器开始旋转并开始身份验证。

我记录了执行上述操作的测试,但是当我尝试“重现”它时,它似乎失败了,因为文本字段无法立即用于输入:

Test Suite 'Selected tests' started at 2015-08-14 13:14:19.454 Test Suite 'MyAppUITests' started at 2015-08-14 13:14:19.454 Test Case '-[MyAppUITests.MyAppUITests testExample]' started.
t = 0.00s Start Test
t = 0.00s Set Up
t = 0.00s Launch com.myCompany.MyApp 2015-08-14 13:14:19.953 XCTRunner[4667:451922] Continuing to run tests in the background with task ID 1
t = 2.64s Waiting for accessibility to load
t = 6.20s Wait for app to idle
t = 6.49s Tap "User ID" TextField
t = 6.49s Wait for app to idle
t = 6.57s Find the "User ID" TextField
t = 6.57s Snapshot accessibility hierarchy for com.myCompany.MyApp
t = 6.60s Find: Descendants matching type TextField
t = 6.60s Find: Elements matching predicate '"User ID" IN identifiers'
t = 6.60s Wait for app to idle
t = 6.67s Synthesize event
t = 6.74s Scroll element to visible
t = 6.78s Assertion Failure: UI Testing Failure - Failed to scroll to visible (by AX action) TextField 0x7fc90251a130: traits: 146029150208, {{107.0, 807.0}, {200.0, 30.0}}, placeholderValue: 'User ID', value: fffffaaaa, error: Error -25204 performing AXAction 2003 :0: error: -[MyAppUITests.MyAppUITests testExample] : UI Testing Failure - Failed to scroll to visible (by AX action) TextField 0x7fc90251a130: traits: 146029150208, {{107.0, 807.0}, {200.0, 30.0}}, placeholderValue: 'User ID', value: fffffaaaa, error: Error -25204 performing AXAction 2003
t = 6.78s Tear Down Test Case '-[MyAppUITests.MyAppUITests testExample]' failed (6.783 seconds).
Test Suite 'MyAppUITests' failed at 2015-08-14 13:14:26.238.
Executed 1 test, with 1 failure (0 unexpected) in 6.783 (6.784) seconds

(强调我的。项目名称和 bundle id 更改为假值)

我该如何处理这样的用户界面? (即,测试代码必须等待某个动画完成,然后目标控件才可操作)

我不记得提到这些“时间”问题的视频。

最佳答案

我建议反对勾选运行循环,而是使用内置的XCTest 异步API。例如:

let app = XCUIApplication()
app.launch()

let textField = app.textField["user name"]
let existsPredicate = NSPredicate(format: "exists == 1")

expectationForPredicate(existsPredicate, evaluatedWithObject: textField, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)

textField.tap()
textField.type("joemasilotti")

这将等到带有可访问性标签/标识符“用户名”的文本字段实际存在于屏幕上。然后它会点击文本字段,使其处于事件状态,然后输入我的用户名。如果在这变为真之前经过五秒钟,测试将失败。

我还在 how to use UI Testing 上写了一篇文章在我的博客上放在一起 UI Testing Cheat Sheet对于这样的场景。

关于iOS 9 UI 测试 - 测试失败,因为目标控件不可用(尚未),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32002330/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com