Todd
Todd

Reputation: 53

Getting the error "Cannot find 'XCUIDevice' in scope" for a Swift UI test

I'm trying to call XCUID.sharedDevice().orientation = .Portrait in my Swift UI test and getting the error Cannot find 'XCUIDevice' in scope.

Here is my file:

import XCTest

final class FastlaneScreenshotsLaunchTests: XCTestCase {
    override class var runsForEachTargetApplicationUIConfiguration: Bool {
        true
    }

    override func setUpWithError() throws {
        continueAfterFailure = false
    }
            
    override func setUp() {
        super.setUp()
        
        let app = XCUIApplication()
        setupSnapshot(app)
        app.launch()
    }

    func testLaunch() throws {
        snapshot("0Launch")
        let app = XCUIApplication()
        XCUIDevice.sharedDevice().orientation = .Portrait // Cannot find 'XCUIDevice' in scope
    }

}

Based on google searching what I'm trying to do (rotate the simulator), I'm expecting XCUIDevice to be in scope. Here are places which recommend this code:

EDIT: The issue was one of my destinations for my test target was Mac Catalyst, which does not support XCUIDevice. Once I removed the mac catalyst destination, the error was resolved.

Thanks to @vadim-belyaev

Upvotes: 0

Views: 375

Answers (1)

Vadim Belyaev
Vadim Belyaev

Reputation: 2859

The modern syntax is:

XCUIDevice.shared.orientation = .portrait

Upvotes: 1

Related Questions