Basically there is nothing to solve the problem with the Xcode 8 error. When you get this error, just don't run anything else to do atm. I never had this problem on Xcode 7. What the error message tells you is that it failed to get the requested orientation and your code codes look good:
XCUIDevice.shared().orientation = .landscapeLeft XCUIDevice.shared().orientation = .portrait
Apple, I hope, will solve this problem soon. You can also report make a mistake for Apple.
source share