[英]SwiftUI: Assert that sheet is visible
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?
如何测试工作表是否可见?
For Text
you need to use staticTexts
container (tested with Xcode 12.1 / iOS 14.1).对于
Text
,您需要使用staticTexts
容器(使用 Xcode 12.1 / iOS 14.1 测试)。 Assuming of course that your test correctly wait till sheet is opened.当然,假设您的测试正确地等到工作表打开。
XCTAssertTrue(app.staticTexts["header"].exists)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.