Reputation: 1325
I have a checkbox button which is a custom button, I am changing button image to selected and unselected on button click.
I need to UI test this element, how do I do that?
I tried to get the element using the image name but it didn't help me
Upvotes: 0
Views: 1459
Reputation: 7659
When the checkbox is selected, add the selected
accessibility trait. Then, in your UI test, check the element's isSelected
property.
// App code
imageView.accessibilityTraits = imageView.accessibilityTraits.union([.selected])
// Test code
XCTAssertTrue(checkboxElement.isSelected)
Remember to add logic to remove the selected
trait when the checkbox is unselected.
Upvotes: 2
Reputation: 40008
This can be one of the solution
Override the accessibilityLabel
of the button and return selected
/deslected
based on button's state.
Then in UITest just check the accessibilityLabel
.
For visual state test you can have snapshot test.
Upvotes: 0