user6633897 user6633897 - 1 year ago 172
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

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?


Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download