Search code examples
orientationswift4xcode9xcuitest

Unable to set Device Orientation in XCUITest on Swift 4


I have been running the tests successfully till Xcode 8. After updating to Xcode to 9 & 9.0.1 and upgrading to swift 4 number of problems has been araising one after the other.

Now code compiles and launches the app(Finally) but when setting the simulator orientation app crashes with following error.

caught nsinternalinconsistencyexception activity cannot be used after its scope has completed

This is how I set my orientation

 XCUIDevice.shared.orientation = .portrait

Solution

  • Untill xcode 8, subclassing XCUITest class and rotating the device from setup() function was allowed. But from xcode 9 it should be done only in the testFunctions()