I have a button with a foreground image in a ZStack:
Button(action: {
self.highlighted = !self.highlighted
}) {
ZStack {
Text("Text")
if self.highlighted {
Image("highlighted").resizable()
}
}
}
The foreground image ("highlighted") is only visible if the variable is true. A button click flips the highlighted variable. So if the button is clicked it is highlighted and if it is clicked again it is not highlighted anymore. I now want to have a UiTest in which the button is clicked and the test checks if the Image "highlighted" exists. This is what I have as UiTest, but it fails at the last assertion:
func test_highlight() {
let app = XCUIApplication()
let button = app.buttons["my_button"]
XCTAssertTrue(button.exists)
button.tap()
XCTAssertTrue(button.images["highlighted"].exists) // <-- Fails here
}
Is this possible in UiTests. If yes, how? If not, what is the alternative?