XCUITests iOS Accessibility Accessibility

How can I claim that a button exists using its accesibilityLabel or identifier?

func testExitsButton() { XCTAssertTrue(app.windows.containing(.button, identifier: "Button Text").element.exists) XCTAssertTrue(app.buttons["Button Text"].exists) XCTAssertTrue(app.buttons["test"].exists) <- I want this, instead of accesing the text property i want by specific id, maybe the text property override the accesibiltyLabel? } 

enter image description here

+5
source share
3 answers

Set the availability identifier in the application code, and then search for the button using that identifier in your tests.

 // app code let button: UIButton! button.accessibilityIdentifier = "myButton" // UI test code func testMyButtonIsDisplayed() { let app = XCUIApplication() let button = app.buttons["myButton"] XCTAssertTrue(button.exists) } 

The accessibility identifier is set regardless of the text on the button and also does not depend on the accessibility label. It is not better to use UI element identifiers as an accessibility label, since the accessibility label is read to VoiceOver users to explain the element to them.

+11
source

IMPORTANT NOTICE. If the supervisor is set to available, XCUITest may not have access to its subzones.

You can access an element by setting its accessibility through a storyboard or programmatically, as discussed above. You can click the record button when the cursor is in a function that begins with the prefix "test" to record how XCUITest sees the element. Sometimes you need to clear the pair (command shift k) and a couple of minutes for the record button to be available. You can also remove your tree from the storyboard and use XCUITest functions, such as element (boundBy: Int), children (matching: .textField), you can also link them: XCUIApplication (). Tables.cells.containing (.button, identifier: "id"). After this is easy, use .exists, which returns a boolean.

enter image description here

+3
source

add | "Identity Test" Identifier String test | in custom runtime attributes in the navigation bar and not in the accessibility label

+2
source

Source: https://habr.com/ru/post/1262216/


All Articles