2

I have a view in which a sheet gets visible at some point.

var body: some View {
    VStack {
        Text("Test")
        Text("Test")
    }.sheet(isPresented: $isPresented, content: {
        MySheet(isPresented: $isPresented)
    })
}

The sheet looks like this:

var body: some View {
    GeometryReader { metrics in
        VStack (spacing:0) {
            ZStack {
                Color(UIColor.lightGray)
                Text("header")
            }.frame(width: metrics.size.width, height: metrics.size.height * 0.15)
            ZStack {
                Color(UIColor.darkGray)
                Text("text")
            }.frame(width: metrics.size.width, height: metrics.size.height * 0.85)
        }
    }
}

I tried to test that the sheet is visible with

XCTAssertTrue(app.textFields["header"].exists)

But that does not work. How can I test if the sheet is visible?

L3n95
  • 1,505
  • 3
  • 25
  • 49

1 Answers1

2

For Text you need to use staticTexts container (tested with Xcode 12.1 / iOS 14.1). Assuming of course that your test correctly wait till sheet is opened.

XCTAssertTrue(app.staticTexts["header"].exists)
Asperi
  • 228,894
  • 20
  • 464
  • 690