Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does KIF work with SwiftUI? #1199

Open
rauls4 opened this issue Dec 11, 2020 · 3 comments
Open

Does KIF work with SwiftUI? #1199

rauls4 opened this issue Dec 11, 2020 · 3 comments

Comments

@rauls4
Copy link

rauls4 commented Dec 11, 2020

Hello, we are looking for UI testing options and KIF has come up. I have not been able to find out about SwiftUI compatibility.

Any information would be appreciated.

Thanks

@kenji21
Copy link
Contributor

kenji21 commented Dec 12, 2020

Can confirm it works, and I've also tried some interesting thing, using SwiftUI previews in tests:

    func testContentViewPreviews() {
        // Given
        let contentViewPreviews = ContentView_Previews.previews
        
        // When
        solo.showViewControllerInCleanWindow(UIHostingController(rootView: contentViewPreviews))
        let shouldFindVersion = solo.waitFor(textWithPrefix: "Version")
        
        // Expect
        XCTAssertTrue(shouldFindVersion)
        attachScreenshot(name: "contentViewPreviews")
        solo.window?.printHierarchy()
    }

Here is the log:

UIWindow
|	UITransitionView
|	|	UIDropShadowView
|	|	|	_TtGC7SwiftUI14_UIHostingViewGVS_15ModifiedContentV7myapp11ContentViewGVS_30_EnvironmentKeyWritingModifierGSqCS2_8AppState____
|	|	|	SwiftUI.AccessibilityNode, label: (null), traits: image
|	|	|	SwiftUI.AccessibilityNode, label: Version BETA 0.0.1, traits: static text
|	|	|	SwiftUI.AccessibilityNode, label: Copyright © myapp, traits: static text
|	|	|	|	UIView
|	|	|	|	_TtCOCV7SwiftUI11DisplayList11ViewUpdater8Platform13CGDrawingView
|	|	|	|	_TtCOCV7SwiftUI11DisplayList11ViewUpdater8Platform13CGDrawingView
|	|	|	|	_TtC7SwiftUIP33_A34643117F00277B93DEBAB70EC0697122_UIShapeHitTestingView
|	|	|	|	_TtC7SwiftUIP33_A34643117F00277B93DEBAB70EC0697122_UIShapeHitTestingView
|	|	|	|	UIView
Test Case '-[MyAppTests.ContentViewTests testContentViewPreviews]' 

@rauls4
Copy link
Author

rauls4 commented Dec 12, 2020 via email

@dheerajn
Copy link

dheerajn commented Feb 9, 2021

Yes, this works for me. All I had to do is to use UIHostingController(:) in place of ViewController and load the SwiftUI View

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants