Question

I am writing automation test for my program and wish to automate the device orientation as well... I am using the below code to set an orientation to a device,

UIATarget.localTarget().setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT);

but I also wish to get the present orientation of the device. I couldn't find any getDeviceOrientation() method to get the orientation.

Was it helpful?

Solution

Have you tried:

var orientation = UIATarget.localTarget().deviceOrientation()

From the documentation:

deviceOrientation

Discussion

The returned value is a constant that represents the physical orientation of the device and may be different from the current orientation of your app’s user interface. The possible values are as follows:

UIA_DEVICE_ORIENTATION_UNKNOWN
UIA_DEVICE_ORIENTATION_PORTRAIT
UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN
UIA_DEVICE_ORIENTATION_LANDSCAPELEFT
UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT
UIA_DEVICE_ORIENTATION_FACEUP
UIA_DEVICE_ORIENTATION_FACEDOWN

EDIT

Device orientation is probably not available on the simulator. It's better to use interfaceOrientation() on the UIAApplication object instead.

var target = UIATarget.localTarget();
var app = target.frontMostApp();
var orientation = app.interfaceOrientation();

if (orientation == UIA_INTERFACE_ORIENTATION_PORTRAIT || orientation == UIA_INTERFACE_ORIENTATION_PORTRAIT_UPSIDEDOWN) {
    UIALogger.logDebug("Portrait");
} else if (orientation == UIA_INTERFACE_ORIENTATION_LANDSCAPELEFT || orientation == UIA_INTERFACE_ORIENTATION_LANDSCAPERIGHT) {
    UIALogger.logDebug("Landscape");    
}

This guide is pretty good.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top