Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & Test Observability

Change Device Orientation

Learn how to change the device orientation for Selenium tests on BrowserStack Automate.

When testing an application for smart devices, consider the context and circumstances in which that application will be used in different layouts. With the custom deviceOrientation capability, you can change the device orientation and observe your application behaviour.

Capability Description Expected values
deviceOrientation Set the screen orientation of the mobile device A string.
Default is portrait.

portrait if you want the device to be in portrait mode, landscape otherwise.

Use the following sample code snippets to set the device orientation to landscape:

If you are using BrowserStack SDK, you can set the following capabilities in the browserstack.yml file:

Copy icon Copy snippet

BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.

// Change device orientation to landscape

MutableCapabilities capabilities = new MutableCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("deviceOrientation", "landscape");
capabilities.setCapability("bstack:options", browserstackOptions);
// Change device orientation to landscape

var capabilities = {
	'bstack:options' : {
		"deviceOrientation" : "landscape",
	}
}
// To get landscape orientation on android device
ChromeOptions capabilities = new ChromeOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("deviceOrientation", "landscape");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);

// To get landscape orientation on iOS devices
SafariOptions capabilities = new SafariOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("deviceOrientation", "landscape");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
# Change device orientation to landscape

$caps = array(
 "deviceOrientation" => "landscape"
);
# Change device orientation to landscape

desired_cap = {
	'bstack:options' : {
		"deviceOrientation" : "landscape",
	}
}
# Change device orientation to landscape

capabilities = {
	'bstack:options' => {
		"deviceOrientation" => "landscape",
	}
}
// Change device orientation to landscape

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceOrientation", "landscape");
// Change device orientation to landscape

var capabilities = {
 "deviceOrientation" : "landscape"
}
// To get landscape orientation on android device
ChromeOptions capability = new ChromeOptions();
capability.AddAdditionalCapability("deviceOrientation", "landscape", true);

// To get landscape orientation on iOS devices
SafariOptions capability = new SafariOptions();
capability.AddAdditionalCapability("deviceOrientation", "landscape");
# Change device orientation to landscape

$caps = array(
 "deviceOrientation" => "landscape"
);
# Change device orientation to landscape

capabilities = {
 "deviceOrientation" : "landscape"
}
# Change device orientation to landscape

caps = Selenium::WebDriver::Remote::Capabilities.new
caps["deviceOrientation"] = "landscape"
Note: Changing the orientation of your mobile device can be done only before test execution starts, using a capability. The orientation cannot be changed in the middle of the test script.

The deviceOrientation capability in landscape mode is as follows: Change device orientation in landscape mode

If deviceOrientation capability is not set, the test will run in portrait mode as shown in the following figure:

Device orientation as portrait

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Download Copy