【发布时间】:2020-07-21 07:54:10
【问题描述】:
在我的 UITests 中进行元素查询时,为了截取不同分段控件值的屏幕截图,由于我使用 .buttons["name"],所以在翻译开始时会引发错误,并且名称是英文并且没有被翻译为预期的。
它是从故事板翻译过来的。所以我想找到一个更简单的解决方案。
我可以使用 .selectedSegmentIndex 代替 UITest 中出现翻译错误的按钮名称吗,或者有其他方法可以解决此问题吗?
XCUIApplication().scrollViews
.children(matching: .other)
.element
.children(matching: .other)
.element(boundBy: 0)
.children(matching: .other)
.otherElements
.segmentedControls["MySegmentedControl"]
.buttons["name"] // How to add this value to be .selectedSegmentIndex = 1?
.tap()
【问题讨论】:
-
你试过
app.segmentedControls.buttons.element(boundBy: 1)吗? -
它不起作用,我收到此错误:无法获取匹配的快照:没有找到匹配来自输入的匹配类型 SegmentedControl 的后代
-
我的意思是
.segmentedControls["MySegmentedControl"].buttons.element(boundBy: 1),而不是segmentedControls["MySegmentedControl"].buttons["name"]。你试过了,对吧? -
我尝试了这个解决方案,但触发了同样的错误。
-
顺便说一句,您之前是否使用您共享的代码访问了段控制?您需要先启动,然后通过
app访问。不像XCUIApplication().segmentedControls
标签: swift localization screenshot ui-testing nssegmentedcontrol