16

I want to figure out which segment is selected on a segmented control in Xcode's new UI Testing in Swift.

I can get the segmentedControl XCUIElement, and the 'buttons' associated with it, but I'm not sure how to test for the selected property.

Sorry in advance if this is something obvious that I have missed.

4

2 回答 2

22

XCUIElement有一个selected可以检查的属性:

XCTAssertTrue(app.segmentedControls.buttons.elementBoundByIndex(0).selected)

于 2015-08-01T02:48:24.060 回答
3

Swift 4 的版本:

let environment = app.segmentedControls.element(boundBy: 0);
XCTAssertTrue(environment.buttons.element(boundBy:0).isSelected, "Wrong environment selected");
于 2017-11-24T09:52:50.590 回答