UITest无法找到accessibilityLabel字符串

时间:2018-11-11 02:45:01

标签: ios swift xcode xcode-ui-testing ui-testing

我正在尝试编写一个测试,让我知道我的UIAlertController在屏幕上。测试成功显示警报控制器,但是当我尝试断言它存在时,我失败了。为什么测试失败?

这是我的警报控制器代码:

let alertController = UIAlertController(title: nil, message: "Group the posts by...", preferredStyle: .actionSheet)
alertController.accessibilityLabel = "Grouping Options"
present(alertController, animated: true, completion: nil)

这是我的测试失败:

func testThatTappingGroupByButtonPresentsAlertController() {
        let blogPostsNavigationBar = app.navigationBars["Blog Posts"]
        blogPostsNavigationBar.buttons["Group By"].tap()
        let sheetsQuery = app.sheets
        XCTAssert(sheetsQuery["Grouping Options"].exists)
}

直到断言为止,测试将按预期进行。我可以看到在模拟器中显示了alertController。当我运行sheetsQuery.count时,我得到1,这是我期望的。似乎找不到我的alertController的可访问性标签。 UIAlertController没有accessibilityIdentifier,所以这就是我使用accessibilityLabel的原因。

我也尝试设置alertController.isAccessibilityElement = true,但这也无济于事。

有人在这里看到我在做什么错吗?

0 个答案:

没有答案