How to use setOrientation method of io.appium.java_client.remote.MobileOptions class

Best io.appium code snippet using io.appium.java_client.remote.MobileOptions.setOrientation

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

MobileOptionsTest.java

Source: MobileOptionsTest.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client.remote;
18
19import org.junit.Test;
20import org.openqa.selenium.MutableCapabilities;
21import org.openqa.selenium.ScreenOrientation;
22
23import java.net.MalformedURLException;
24import java.net.URL;
25import java.time.Duration;
26import java.util.ArrayList;
27
28import static org.junit.Assert.*;
29
30public class MobileOptionsTest {
31    private MobileOptions mobileOptions = new MobileOptions<>();
32
33    @Test
34    public void acceptsExistingCapabilities() {
35        MutableCapabilities capabilities = new MutableCapabilities();
36        capabilities.setCapability("deviceName", "Pixel");
37        capabilities.setCapability("platformVersion", "10");
38        capabilities.setCapability("newCommandTimeout", 60);
39
40        mobileOptions = new MobileOptions<>(capabilities);
41
42        assertEquals("Pixel", mobileOptions.getDeviceName());
43        assertEquals("10", mobileOptions.getPlatformVersion());
44        assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout());
45    }
46
47    @Test
48    public void acceptsMobileCapabilities() throws MalformedURLException {
49        mobileOptions.setApp(new URL("http://example.com/myapp.apk"))
50                .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
51                .setPlatformVersion("10")
52                .setDeviceName("Pixel")
53                .setOtherApps("/path/to/app.apk")
54                .setLocale("fr_CA")
55                .setUdid("1ae203187fc012g")
56                .setOrientation(ScreenOrientation.LANDSCAPE)
57                .setNewCommandTimeout(Duration.ofSeconds(60))
58                .setLanguage("fr");
59
60        assertEquals("http://example.com/myapp.apk", mobileOptions.getApp());
61        assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, mobileOptions.getAutomationName());
62        assertEquals("10", mobileOptions.getPlatformVersion());
63        assertEquals("Pixel", mobileOptions.getDeviceName());
64        assertEquals("/path/to/app.apk", mobileOptions.getOtherApps());
65        assertEquals("fr_CA", mobileOptions.getLocale());
66        assertEquals("1ae203187fc012g", mobileOptions.getUdid());
67        assertEquals(ScreenOrientation.LANDSCAPE, mobileOptions.getOrientation());
68        assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout());
69        assertEquals("fr", mobileOptions.getLanguage());
70    }
71
72    @Test
73    public void acceptsMobileBooleanCapabilityDefaults() {
74        mobileOptions.setClearSystemFiles()
75                .setAutoWebview()
76                .setEnablePerformanceLogging()
77                .setEventTimings()
78                .setAutoWebview()
79                .setFullReset()
80                .setPrintPageSourceOnFindFailure();
81
82        assertTrue(mobileOptions.doesClearSystemFiles());
83        assertTrue(mobileOptions.doesAutoWebview());
84        assertTrue(mobileOptions.isEnablePerformanceLogging());
85        assertTrue(mobileOptions.doesEventTimings());
86        assertTrue(mobileOptions.doesAutoWebview());
87        assertTrue(mobileOptions.doesFullReset());
88        assertTrue(mobileOptions.doesPrintPageSourceOnFindFailure());
89    }
90
91    @Test
92    public void setsMobileBooleanCapabilities() {
93        mobileOptions.setClearSystemFiles(false)
94                .setAutoWebview(false)
95                .setEnablePerformanceLogging(false)
96                .setEventTimings(false)
97                .setAutoWebview(false)
98                .setFullReset(false)
99                .setPrintPageSourceOnFindFailure(false);
100
101        assertFalse(mobileOptions.doesClearSystemFiles());
102        assertFalse(mobileOptions.doesAutoWebview());
103        assertFalse(mobileOptions.isEnablePerformanceLogging());
104        assertFalse(mobileOptions.doesEventTimings());
105        assertFalse(mobileOptions.doesAutoWebview());
106        assertFalse(mobileOptions.doesFullReset());
107        assertFalse(mobileOptions.doesPrintPageSourceOnFindFailure());
108    }
109}
110
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)