gpt4 book ai didi

ios - UI 测试 firstMatch

转载 作者:可可西里 更新时间:2023-11-01 17:13:05 25 4
gpt4 key购买 nike

.element(boundBy: 0) 的 UI 测试代码中的所有实例替换为 .firstMatch 是否安全?

我会这么认为,但 Apple 的文档对此不是很清楚(尤其是在多个匹配的情况下,尽管我只关心第一个)。 https://developer.apple.com/documentation/xctest/xcuielementtypequeryprovider/2902250-firstmatch

最佳答案

与其将 element(boundBy: 0)firstMatch 交换,不如将它们链接起来。

XCUIApplication().cells.element(boundBy:0).firstMatch

如果屏幕上有多个单元格,这将使查询解析得更快。如果没有 firstMatch,测试将首先获取所有单元格的列表,然后使用第一个单元格。使用 firstMatch,测试将查找单元格并使用找到的第一个单元格。

Only use firstMatch in cases where you know categorically that a single element will match a query.

您仍然应该在可能有超过 1 个元素匹配查询的任何地方执行 element(boundBy:),以确保当您使用 firstMatch 时,有只有一个元素可以匹配该查询。在有 3 个单元格并且您想使用第一个单元格的情况下,您仍然应该使用 element(boundBy: 0)。如果您知道屏幕上只有 1 个单元格,那么可以跳过 element(boundBy: 0) 并使用 firstMatch 而不是 元素 以更快地解析查询。

// fine if there is only one cell
XCUIApplication().cells.element // also checks for multiple matches
// also fine if there is only one cell
XCUIApplication().cells.firstMatch // does not check for multiple matches

关于ios - UI 测试 firstMatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46276544/

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