Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Xcode UI Testing is it possible to get the orientation of the view

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?

like image 246
will3321 Avatar asked Mar 09 '16 18:03

will3321


2 Answers

You can get the orientation using this line

XCUIDevice.sharedDevice().orientation
like image 182
Tharak Avatar answered Nov 02 '22 23:11

Tharak


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))
}
like image 37
Alexandros Spyropoulos Avatar answered Nov 03 '22 01:11

Alexandros Spyropoulos