Reputation: 1615
How can I test the foregroundColor
of a View in an UITest? I have a Text
for example:
Text("this can have different colors").foregroundColor(textColor)
And in the UITest I want to know which color the Text has, something like:
XCTAssertEquals(app.staticTexts["..."].color, Color.white)
But there is no field .color
.
The same should work for Image
s.
Upvotes: 1
Views: 741
Reputation: 14388
This is not possible in UI Testing, which doesn't really check the visuals but interacts with the app using accessibility identifiers.
If you want to test colours of your views you should look into snapshot testing. You could use Point-Free's SnapshotTesting which supports SwiftUI: https://github.com/pointfreeco/swift-snapshot-testing
Upvotes: 2