我对任何类型的iOS编程都是新手。我正在尝试为我的一个场景编写UI测试用例。
以下是当我使用recode方法并点击自定义组件时得到的代码。
let button = XCUIApplication().children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .button).element在这个自定义组件中有两个按钮。我想知道哪个按钮被选中了。为此,我需要识别按钮。但是无论我在哪里点击自定义视图,都会得到相同的代码。
如何访问自定义视图中的每个组件。任何帮助都是最好的。
发布于 2017-04-28 14:47:19
将辅助功能标识符添加到应用程序代码中的自定义视图。
let customView: UIView!
customView.accessibilityIdentifier = "myCustomView"然后像这样访问内容:
let app = XCUIApplication()
let customView = app.otherElements["myCustomView"]
let button1 = customView.buttons.element(boundBy: 0)
let button2 = customView.buttons.element(boundBy: 1)
XCTAssertTrue(button1.isSelected)
XCTAssertFalse(button2.isSelected)请注意,要使您的测试具有确定性,您应该已经知道应该选择哪个(哪些)按钮。这确保了您的测试在每次运行时都测试相同的内容。
发布于 2017-04-28 12:55:59
你需要让你的元素对可访问性可见。
https://stackoverflow.com/questions/43658903
复制相似问题