Best Selenium code snippet using org.openqa.selenium.DeviceRotation.parameters
Source:AppiumDriver.java
...57@SuppressWarnings("unchecked")58public class AppiumDriver<T extends WebElement>59 extends DefaultGenericMobileDriver<T> implements ComparesImages, FindsByImage<T>, FindsByCustom<T> {60 private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);61 // frequently used command parameters62 private URL remoteAddress;63 private RemoteLocationContext locationContext;64 private ExecuteMethod executeMethod;65 /**66 * Creates a new instance based on command {@code executor} and {@code capabilities}.67 *68 * @param executor is an instance of {@link HttpCommandExecutor}69 * or class that extends it. Default commands or another vendor-specific70 * commands may be specified there.71 * @param capabilities take a look at {@link Capabilities}72 */73 public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {74 super(executor, capabilities);75 this.executeMethod = new AppiumExecutionMethod(this);76 locationContext = new RemoteLocationContext(executeMethod);77 super.setErrorHandler(errorHandler);78 this.remoteAddress = executor.getAddressOfRemoteServer();79 this.setElementConverter(new JsonToMobileElementConverter(this, this));80 }81 public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {82 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),83 desiredCapabilities);84 }85 public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,86 Capabilities desiredCapabilities) {87 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,88 httpClientFactory), desiredCapabilities);89 }90 public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {91 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),92 desiredCapabilities);93 }94 public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,95 Capabilities desiredCapabilities) {96 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),97 desiredCapabilities);98 }99 public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {100 this(builder.build(), desiredCapabilities);101 }102 public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,103 Capabilities desiredCapabilities) {104 this(builder.build(), httpClientFactory, desiredCapabilities);105 }106 public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {107 this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,108 desiredCapabilities);109 }110 public AppiumDriver(Capabilities desiredCapabilities) {111 this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);112 }113 /**114 * Changes platform name and returns new capabilities.115 *116 * @param originalCapabilities the given {@link Capabilities}.117 * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has118 * to be set up119 * @return {@link Capabilities} with changed mobile platform value120 */121 protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities,122 String newPlatform) {123 DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities);124 dc.setCapability(PLATFORM_NAME, newPlatform);125 return dc;126 }127 @Override public List<T> findElements(By by) {128 return super.findElements(by);129 }130 @Override public List<T> findElements(String by, String using) {131 return super.findElements(by, using);132 }133 @Override public List<T> findElementsById(String id) {134 return super.findElementsById(id);135 }136 public List<T> findElementsByLinkText(String using) {137 return super.findElementsByLinkText(using);138 }139 public List<T> findElementsByPartialLinkText(String using) {140 return super.findElementsByPartialLinkText(using);141 }142 public List<T> findElementsByTagName(String using) {143 return super.findElementsByTagName(using);144 }145 public List<T> findElementsByName(String using) {146 return super.findElementsByName(using);147 }148 public List<T> findElementsByClassName(String using) {149 return super.findElementsByClassName(using);150 }151 public List<T> findElementsByCssSelector(String using) {152 return super.findElementsByCssSelector(using);153 }154 public List<T> findElementsByXPath(String using) {155 return super.findElementsByXPath(using);156 }157 @Override public List<T> findElementsByAccessibilityId(String using) {158 return super.findElementsByAccessibilityId(using);159 }160 @Override public ExecuteMethod getExecuteMethod() {161 return executeMethod;162 }163 @Override public WebDriver context(String name) {164 checkNotNull(name, "Must supply a context name");165 try {166 execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name));167 return this;168 } catch (WebDriverException e) {169 throw new NoSuchContextException(e.getMessage(), e);170 }171 }172 @Override public Set<String> getContextHandles() {173 Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);174 Object value = response.getValue();175 try {176 List<String> returnedValues = (List<String>) value;177 return new LinkedHashSet<>(returnedValues);178 } catch (ClassCastException ex) {179 throw new WebDriverException(180 "Returned value cannot be converted to List<String>: " + value, ex);181 }182 }183 @Override public String getContext() {184 String contextName =185 String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());186 if ("null".equalsIgnoreCase(contextName)) {187 return null;188 }189 return contextName;190 }191 @Override public DeviceRotation rotation() {192 Response response = execute(DriverCommand.GET_SCREEN_ROTATION);193 DeviceRotation deviceRotation =194 new DeviceRotation((Map<String, Number>) response.getValue());195 if (deviceRotation.getX() < 0 || deviceRotation.getY() < 0 || deviceRotation.getZ() < 0) {196 throw new WebDriverException("Unexpected orientation returned: " + deviceRotation);197 }198 return deviceRotation;199 }200 @Override public void rotate(DeviceRotation rotation) {201 execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters());202 }203 @Override public void rotate(ScreenOrientation orientation) {204 execute(DriverCommand.SET_SCREEN_ORIENTATION,205 ImmutableMap.of("orientation", orientation.value().toUpperCase()));206 }207 @Override public ScreenOrientation getOrientation() {208 Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);209 String orientation = response.getValue().toString().toLowerCase();210 if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {211 return ScreenOrientation.LANDSCAPE;212 } else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {213 return ScreenOrientation.PORTRAIT;214 } else {215 throw new WebDriverException("Unexpected orientation returned: " + orientation);...
Source:RemoteRotatable.java
...36 (String) executeMethod.execute(DriverCommand.GET_SCREEN_ORIENTATION, null));37 }38 @Override39 public void rotate(DeviceRotation rotation) {40 executeMethod.execute(DriverCommand.SET_SCREEN_ORIENTATION, rotation.parameters());41 }42 @Override43 public DeviceRotation rotation() {44 Object result = executeMethod.execute(DriverCommand.GET_SCREEN_ROTATION, null);45 if (!(result instanceof Map)) {46 throw new IllegalStateException("Unexpected return value: " + result);47 }48 @SuppressWarnings("unchecked") Map<String, Number> raw = (Map<String, Number>) result;49 return new DeviceRotation(raw);50 }51}...
Source:SupportsRotation.java
...34 //noinspection unchecked35 return new DeviceRotation((Map<String, Number>) response.getValue());36 }37 default void rotate(DeviceRotation rotation) {38 execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters());39 }40 default void rotate(ScreenOrientation orientation) {41 execute(DriverCommand.SET_SCREEN_ORIENTATION,42 ImmutableMap.of("orientation", orientation.value().toUpperCase()));43 }44 /**45 * Get device orientation.46 *47 * @return The orientation value.48 */49 default ScreenOrientation getOrientation() {50 Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);51 String orientation = String.valueOf(response.getValue());52 return ScreenOrientation.valueOf(orientation.toUpperCase());...
Source:AddRotatable.java
...23 case "rotate": Object response;24 if ((args[0] instanceof ScreenOrientation)) {25 response = executeMethod.execute("setScreenOrientation", ImmutableMap.of("orientation", args[0])); } else { Object response;26 if ((args[0] instanceof DeviceRotation)) {27 response = executeMethod.execute("setScreenOrientation", ((DeviceRotation)args[0]).parameters());28 } else29 throw new IllegalArgumentException("rotate parameter must be either of type 'ScreenOrientation' or 'DeviceRotation'");30 }31 break;32 case "getOrientation": 33 response = ScreenOrientation.valueOf((String)executeMethod.execute("getScreenOrientation", null));34 break;35 case "rotation": 36 response = (DeviceRotation)executeMethod.execute("getScreenRotation", null);37 break;38 default: 39 throw new IllegalArgumentException(method.getName() + ", Not defined in rotatable interface"); }40 Object response;41 return response;...
parameters
Using AI Code Generation
1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.openqa.selenium.remote.SessionId;6import org.openqa.selenium.remote.SessionNotFoundException;7import org.openqa.selenium.remote.SessionNotCreatedException;8import org.openqa.selenium.remote.http.HttpClient;9import org.openqa.selenium.remote.http.HttpMethod;10import org.openqa.selenium.remote.http.HttpRequest;11import org.openqa.selenium.remote.http.HttpResponse;12import org.openqa.selenium.remote.http.W3CHttpCommandCodec;13import org.openqa.selenium.remote.http.W3CHttpResponseCodec;14import org.openqa.selenium.remote.internal.ApacheHttpClient;15import java.io.IOException;16import java.net.URL;17import java.util.HashMap;18import java.util.Map;19public class SetDeviceRotation {20 public static void main(String[] args) throws IOException {21 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Desktop\\chromedriver.exe");22 WebDriver driver = new ChromeDriver();23 System.out.println("Before rotation");24 System.out.println("Current URL is " + driver.getCurrentUrl());25 System.out.println("Current Title is " + driver.getTitle());26 Map<String, Object> params = new HashMap<>();27 params.put("x", 100);28 params.put("y", 100);29 params.put("z", 100);30 params.put("duration", 5);31 RemoteWebDriver rwd = (RemoteWebDriver) driver;32 SessionId id = rwd.getSessionId();33 HttpClient client = new ApacheHttpClient.Factory().createClient(url);34 W3CHttpCommandCodec codec = new W3CHttpCommandCodec();35 W3CHttpResponseCodec responseCodec = new W3CHttpResponseCodec();36 HttpRequest request = codec.encode(new HttpRequest(HttpMethod.POST, "/session/" + id + "/orientation"), params);37 HttpResponse response = client.execute(request);
parameters
Using AI Code Generation
1import org.openqa.selenium.remote.DesiredCapabilities;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.remote.MobileCapabilityType;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.openqa.selenium.DeviceRotation;6import java.net.URL;7import java.net.MalformedURLException;8public class DeviceRotationExample {9public static void main(String[] args) throws MalformedURLException {10DesiredCapabilities caps = new DesiredCapabilities();11caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");12caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");13caps.setCapability(MobileCapabilityType.APP, "
parameters
Using AI Code Generation
1import org.openqa.selenium.DeviceRotation;2import org.openqa.selenium.ScreenOrientation;3import org.openqa.selenium.remote.RemoteWebDriver;4import org.openqa.selenium.remote.SessionId;5import io.appium.java_client.AppiumDriver;6import io.appium.java_client.MobileElement;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.android.AndroidElement;9public class DeviceRotationDemo {10 public static void main(String[] args) {11 AndroidDriver<AndroidElement> driver = null;12 try {
parameters
Using AI Code Generation
1driver.rotate(new DeviceRotation(0, 90, 0));2driver.rotate(new DeviceRotation(0, 0, 0));3driver.rotate(new DeviceRotation(0, 0, 0));4driver.rotate(new DeviceRotation(0, 90, 0));5driver.rotate(new DeviceRotation(0, 0, 0));6driver.rotate(new DeviceRotation(0, 90, 0));7driver.rotate(new DeviceRotation(0, 0, 0));8driver.rotate(new DeviceRotation(0, 0, 0));9driver.rotate(new DeviceRotation(0, 90, 0));10driver.rotate(new DeviceRotation(0, 0, 0));11driver.rotate(new DeviceRotation(0, 0, 0));12driver.rotate(new DeviceRotation(0, 90, 0));13driver.rotate(new DeviceRotation(0, 0, 0));14driver.rotate(new DeviceRotation(0,
parameters
Using AI Code Generation
1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import org.openqa.selenium.DeviceRotation;4import java.net.URL;5public class DeviceRotationTest {6public static void main(String[] args) throws Exception {7DesiredCapabilities capabilities = new DesiredCapabilities();8capabilities.setCapability("deviceName", "Android Emulator");9capabilities.setCapability("platformName", "Android");10capabilities.setCapability("platformVersion", "4.4.2");11capabilities.setCapability("appPackage", "com.android.calculator2");12capabilities.setCapability("appActivity", "Calculator");
parameters
Using AI Code Generation
1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import org.openqa.selenium.DeviceRotation;4import org.openqa.selenium.ScreenOrientation;5import java.net.URL;6import java.net.MalformedURLException;7public class RotateDevice {8 public static void main(String[] args) throws MalformedURLException {9 DesiredCapabilities capabilities = new DesiredCapabilities();10 capabilities.setCapability("BROWSER_NAME", "Android");11 capabilities.setCapability("VERSION", "4.4"); 12 capabilities.setCapability("deviceName","emulator-5554");13 capabilities.setCapability("platformName","Android");
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!