How to test app in Landscape or Portrait Mode using XCUITest
Why to test apps in Landscape or Portrait?
How to screen app in Landscape or Portrait Mode using XCUITest
iOS apps are developed to serve various determination from entertainment to eCommerce. At times a certain app/feature cater better vision and compatibility in certain screen orientations, viz Portrait and Landscape. While the nonpayment screen orientation for a mobile application is Portrait, in certain lawsuit like watching movies and playing games, the screen orientation makes a difference in the user experience. Based on the coating and its use cause, screen orientation can be altered to serve the purpose and provide best user experience. Hence, it should be tested for the application before making a release.
Overview
Why Orientation Testing Matters
- Users rotate screens frequently, hence layouts should adapt properly.
- Some UI constituent repositing or resize in different orientations.
How to Switch Orientation in XCUITest
- Use the XCUIDevice.shared.orientation property to set .portrait or .landscape.
- Call XCUIDevice.shared.orientation = .landscapeLeft or .portrait etc.
Validating UI Orientation
- Check layout constraints or element perspective after modification.
- Validate that no controls overlap or behave falsely.
This guide demonstrate how to programmatically switch orientations and validate UI responsiveness using XCUITest (iOS).
Why to test apps in Landscape or Portrait?
In Mobile devices, its useful to view contents of the app in landscape and portrait modes depend upon usages and ease of accessing for users.
Most mobile users use apps and their devices on both landscape and portrait mode. Hence it becomes important to test our apps too on both orientations.
It is noteworthy, that you are setting and dealing with the device orientation, which indirectly shall revolve the apps screen as well and display the app on mandatory orientations.
How to test if an app is in Landscape or Portrait?
To simply bring the current interface orientation of an iOS device, you can use the below command:
XCUIDevice.shared.orientation
where, orientationis an in-built variable of classUIDevicewhich returns the current device orientation in tests.
This consist of instance properties such as, (each regress Boolean value)
- isPortrait
- isLandscape
- isFlat
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
- isValidInterfaceOrientation
isPortrait
- returns true if the orientation of the device is portrait
- homecoming false if the orientation of the gimmick is landscape
For Example,
var device = XCUIDevice.shared.orientation print (device.isPortrait) // returns true or false
isLandscape
- homecoming true if the orientation of the device is landscape
- homecoming mistaken if the orientation of the gimmick is portrait
For Example,
var device = XCUIDevice.shared.orientation print (device.isLandscape) // returns true or mistaken
How to set and test the device in Landscape or Portrait?
An app can be set to landscape or portrait orientation, by using one of the four twist revolution options:
- .portrait
- .portraitUpsideDown
- .landscapeLeft
- .landscapeRight
Let us appear into each of the above in item with examples of code snippets in Swift language.
.portrait
It pose the device on portrait mode vertically having devices ’ home button on the bottom
For Example,
var device = XCUIDevice.shared.orientation device = .portrait // device under test is set to portrait XCTAssertTrue (device.isPortrait) // tests if device is in portrayal
.portraitUpsideDown
It pose the device on portrait modality vertically having device ’ abode button on the top
For Example,
var device = XCUIDevice.shared.orientation device = .portraitUpsideDown XCTAssertTrue (device.isPortrait) // tests if device is in portraiture
.landscapeLeft
It sets the gimmick on landscape mode horizontally having device ’ s home push on the right
Example:
var device = XCUIDevice.shared.orientation device = .landscapeLeft XCTAssertTrue (device.isLandscape) // tests if device is in landscape
.landscapeRight
It fix the device on landscape mode horizontally hold device ’ s habitation push on the left
For example,
var gimmick = XCUIDevice.shared.orientation device = .landscapeRight XCTAssertTrue (device.isLandscape) // tests if twist is in landscape
How to run XCUITest in Landscape or Portrait with BrowserStack integration?
While, you can configure our tests to run on landscape as well as portraiture mode from test book itself, we can also configure the same on CI shape file while integrating with.
For Landscape orientation:
roll -u `` username: accesskey '' \ -X POST `` https: //api-cloud.browserstack.com/app-automate/xcuitest/v2/build '' \ -d ' {`` deviceOrientation '': `` landscape '', `` devices '': [`` iPhone 8 Plus-11.0 ''], `` app '': `` bs: //f5L3azt9pLzE995f49376eb1fa3c284dc321f8d '', `` testSuite '': `` bs: //6eb1fa3c284ddbe9971b2d1aee0d52943b9c081 ''} ' \ -H `` Content-Type: application/json ''For Portrait orientation:
curl -u `` username: accesskey '' \ -X POST `` https: //api-cloud.browserstack.com/app-automate/xcuitest/v2/build '' \ -d ' {`` deviceOrientation '': `` portrait '', `` devices '': [`` iPhone 8 Plus-11.0 ''], `` app '': `` bs: //f5L3azt9pLzE995f49376eb1fa3c284dc321f8d '', `` testSuite '': `` bs: //6eb1fa3c284ddbe9971b2d1aee0d52943b9c081 ''} ' \ -H `` Content-Type: application/json ''Conclusion
While testing mobile covering, it is always advocate to test on real devices, to check that the are direct into consideration. Testing on emulator and simulator does not provide accurate results as it just mimics the device environs, dismiss existent world scenario.
Hence tests like running apps in Landscape or Portrait mode should be make on existent devices only. allows access to a large fleet of Android and iOS nomadic device, so lots so that.
On This Page
# Ask-and-Contributeabout this topic with our Discord community.
Related Guides
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free