Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 824
user6633897 Avatar asked Sep 26 '16 12:09

user6633897


2 Answers

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

Swift 5.x

XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait
like image 120
Rashwan L Avatar answered Nov 14 '22 10:11

Rashwan L


Swift 4:

XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait
like image 4
ergunkocak Avatar answered Nov 14 '22 09:11

ergunkocak