You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following overloads for convince where I want to find a view by its type and accessibilityIdentifier (since I may have multiple views of the same type in one view) which both worked up until Xcode 16 / ViewInspector 10.0.0.
import XCTest
import ViewInspector
import SwiftUI
struct TestView: View {
var body: some View {
VStack(spacing: 20) {
VStack(spacing: 5) {
Text("This is my header")
.font(.title)
Text("Smaller text")
.font(.caption2)
}
.accessibilityIdentifier("headerVStack")
Text("Body text")
.font(.body)
}
.padding(5)
.accessibilityIdentifier("containerVStack")
}
}
class TestViewTests: XCTestCase {
func testVStack() throws
{
// Arrange/Act
let sut = TestView()
// Assert
let containerVStack = try sut.inspect().find(ViewType.VStack.self, accessibilityIdentifier: "containerVStack")
XCTAssertEqual(5, try containerVStack.padding().top)
}
}
Using .find(ViewType.VStack.self) works, but I have no idea if I have the correct view that I actually want.
Using .find(viewWithAccessibilityIdentifier: "containerVStack") works, but I cannot use .actualView() to get any further information on it (for the cases I am using it for custom view types and want to inspect its properties).
Is the where clause broken or has something changed that means it no longer works as expected?
The text was updated successfully, but these errors were encountered:
AlexanderMarchant
changed the title
Find using ViewType and accessibilityIdentifier no longer works
.find using ViewType and accessibilityIdentifier no longer works
Sep 25, 2024
Is the where clause broken or has something changed that means it no longer works as expected?
Xcode 16 started to mess up with the view hierarchy, filling it with AnyView at arbitrary places. It broke tests for many people.
Using .find(viewWithAccessibilityIdentifier: "containerVStack") works, but I cannot use .actualView() to get any further information on it (for the cases I am using it for custom view types and want to inspect its properties).
Locating the view by a11yId should give you the most precise location in the view hierarchy, I'd suggest you use that as a base call, and then either do .vStack(), if the modifier is applied to VStack, or .view(MyCustomView.self) if it's a custom view. If it's exactly the place where Xcode inserts an implicit AnyView, you'll see that in the thrown error, where it'd say "Found AnyView instead of VStack". Try this out and lmk.
Using .find(ViewType.VStack.self) works, but I have no idea if I have the correct view that I actually want.
At least for troubleshooting purposes, you can call .pathToRoot to see if that's the expected VStack. Not intended to be used in the final revision of the test
I have the following overloads for convince where I want to find a view by its type and accessibilityIdentifier (since I may have multiple views of the same type in one view) which both worked up until Xcode 16 / ViewInspector 10.0.0.
Using
.find(ViewType.VStack.self)
works, but I have no idea if I have the correct view that I actually want.Using
.find(viewWithAccessibilityIdentifier: "containerVStack")
works, but I cannot use.actualView()
to get any further information on it (for the cases I am using it for custom view types and want to inspect its properties).Is the
where
clause broken or has something changed that means it no longer works as expected?The text was updated successfully, but these errors were encountered: