L3n95
L3n95

Reputation: 1615

Test foregroundColor of View

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 Images.

Upvotes: 1

Views: 741

Answers (1)

LuLuGaGa
LuLuGaGa

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

Related Questions