user6633897 user6633897 - 2 months ago 31
Swift Question

how to rotate simulator using swift code in xcode ui test

I have a scenario where i have to rotate my simulator while xcode ui test is going.

To rotate the simulator, i use the below code

UIDevice.currentDevice().orientation
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")


but it is not working.

Is there any solution to rotate the simulator using swift code in xcode ui test?

Thanks

Answer

Have you tried this?

Swift 2.x

XCUIDevice.sharedDevice().orientation = .LandscapeLeft  
XCUIDevice.sharedDevice().orientation = .Portrait  

Swift 3.0

XCUIDevice.shared().orientation = .landscapeLeft
XCUIDevice.shared().orientation = .portrait