Xcuitest ProgressView标识符硬编码为“进度”当按钮内

发布于 2025-01-28 12:36:49 字数 1167 浏览 3 评论 0原文

创建progressView并使用.AccessibilityIdendifier或标准标签时,UI测试能够识别它。

视图:

ProgressView().accessibilityIdentifier("Test")

以下断言通过:

XCTAssert(app.activityIndicators["Test"].exists)

将此progressview放入按钮中时,UI测试无法识别它。

视图:

Button(action: {}) {
    ProgressView().accessibilityIdentifier("Test")
}

相同的断言失败:

XCTAssert(app.activityIndicators["Test"].exists)

有趣的是,一个人可以在按钮中使用“进度”来识别progressview,但是当我拥有多个时,该怎么样?

XCTAssert(app.activityIndicators["In progress"].exists)

为什么此progressView按钮中无法通过它的avessibilityIdentifier按钮中识别?

奖励问题,为什么在app.activityIndi​​cators下可用 app.progressIndicators ,这是人们期望的吗?

  • Xcode 13.3.1
  • IOS 15.4

When creating a ProgressView and using .accessibilityIdentifier or a standard label, UI tests are able identify it.

The view:

ProgressView().accessibilityIdentifier("Test")

The following assertion passes:

XCTAssert(app.activityIndicators["Test"].exists)

When placing this ProgressView within a Button however, UI tests fail to identify it.

The view:

Button(action: {}) {
    ProgressView().accessibilityIdentifier("Test")
}

The same assertion fails:

XCTAssert(app.activityIndicators["Test"].exists)

Interestingly, one can use "In progress" to identify the ProgressView within a Button, but what about when I have multiple?

XCTAssert(app.activityIndicators["In progress"].exists)

Why is this ProgressView not identifiable within a Button via it's accessibilityIdentifier?

Bonus question, why is this available under app.activityIndicators but not app.progressIndicators as one might expect?

  • Xcode 13.3.1
  • iOS 15.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别想她 2025-02-04 12:36:49

我假设,当您的ProgressView放置在按钮中时,它可能会变成“其他元素”类型,这就是您无法使用'app.activityindicators'找到它的原因。我建议您使用:

print(app.debugDescription)

或使用LLDB调试时打印出您的应用元素层次结构:

po app

并检查元素的实际类型及其在层次结构中的拟合方式。或者,您可以使用以下方式直接测试它:

app.otherElements["Test"].exists

编辑:
我不了解最初的问题,因此我将有关您的问题的答案添加到多个现有指标的答案中。在这种情况下,您可能需要避免使用app.activityIndi​​cators并这样改进您的查询:

  1. 使用特定的按钮元素获取所需的指示器:
let button = app.buttons["test"]
let indicator = button.activityIndicators.element(boundBy: 0)
  1. 使用XcuieLementQuery:
let buttons = app.buttons.matching(identifier: "test")
let indicator = buttons.element(boundBy: 0).activityIndicators.element(boundBy: 0)

使用这些指示:使用这些指示活动指示剂可访问性身份。

I would assume that when your ProgressView is placed inside the button it probably becomes of type 'otherElement' and this is the reason you are unable to find it using 'app.activityIndicators'. I would suggest you print out your app elements hierarchy using:

print(app.debugDescription)

or while debugging using the lldb:

po app

and check the actual type of the element and how it fits in the hierarchy. Or you could directly test it out using:

app.otherElements["Test"].exists

Edit:
I did not understand the initial problem so I am adding to the answer about your question for multiple existing indicators. In this case you might want to avoid using app.activityIndicators and improve your queries like this:

  1. Using a specific button element to get the needed indicator:
let button = app.buttons["test"]
let indicator = button.activityIndicators.element(boundBy: 0)
  1. Using XCUIElementQuery:
let buttons = app.buttons.matching(identifier: "test")
let indicator = buttons.element(boundBy: 0).activityIndicators.element(boundBy: 0)

With these you don't even have to use the activityIndicator accessibilityIdentifier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文