For my app I am trying to run a basic UI test on whether the view stays fixed in its orientation when the actual device is rotated. I know how to simulate the physical rotation (using UIDeviceOrientation), but is there a way to get the orientation of the actual view?
You can get the orientation using this line
XCUIDevice.sharedDevice().orientation
I found a workaround. It's not great but it's doing the job. I'll try to find a more elegant way if there is one.
What you need to do is to find an Interface and check it's orientation. In my case I want to test that the UI remains in .Portrait orientation, when my Device is turned to .Landscape.
func testSPSCLaunchScreenLandscape() {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
XCUIDevice.sharedDevice().orientation = .LandscapeLeft
XCTAssert(UIInterfaceOrientationIsPortrait(UIApplication.sharedApplication().statusBarOrientation))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With