How to use DeviceRotation class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.DeviceRotation

Source:AppiumDriver.java Github

copy

Full Screen

...25import io.appium.java_client.service.local.AppiumDriverLocalService;26import io.appium.java_client.service.local.AppiumServiceBuilder;27import org.openqa.selenium.By;28import org.openqa.selenium.Capabilities;29import org.openqa.selenium.DeviceRotation;30import org.openqa.selenium.ScreenOrientation;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.WebDriverException;33import org.openqa.selenium.WebElement;34import org.openqa.selenium.html5.Location;35import org.openqa.selenium.remote.DesiredCapabilities;36import org.openqa.selenium.remote.DriverCommand;37import org.openqa.selenium.remote.ErrorHandler;38import org.openqa.selenium.remote.ExecuteMethod;39import org.openqa.selenium.remote.Response;40import org.openqa.selenium.remote.html5.RemoteLocationContext;41import org.openqa.selenium.remote.http.HttpClient;42import java.net.URL;43import java.util.LinkedHashSet;44import java.util.List;45import java.util.Map;46import java.util.Set;47/**48* @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.49 * Instances of the defined type will be returned via findElement* and findElements*50 * Warning (!!!). Allowed types:51 * {@link org.openqa.selenium.WebElement}52 * {@link org.openqa.selenium.remote.RemoteWebElement}53 * {@link io.appium.java_client.MobileElement} and its subclasses that designed54 * specifically55 * for each target mobile OS (still Android and iOS)56*/57@SuppressWarnings("unchecked")58public class AppiumDriver<T extends WebElement>59 extends DefaultGenericMobileDriver<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 private final String platformName;66 private final String automationName;67 /**68 * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}69 * or class that extends it. Default commands or another vendor-specific70 * commands may be specified there.71 * @param capabilities take a look72 * at {@link org.openqa.selenium.Capabilities}73 */74 public AppiumDriver(AppiumCommandExecutor executor, Capabilities capabilities) {75 super(executor, capabilities);76 this.executeMethod = new AppiumExecutionMethod(this);77 locationContext = new RemoteLocationContext(executeMethod);78 super.setErrorHandler(errorHandler);79 this.remoteAddress = executor.getAddressOfRemoteServer();80 Object capabilityPlatform1 = getCapabilities().getCapability(PLATFORM_NAME);81 Object capabilityAutomation1 = getCapabilities().getCapability(AUTOMATION_NAME);82 Object capabilityPlatform2 = capabilities.getCapability(PLATFORM_NAME);83 Object capabilityAutomation2 = capabilities.getCapability(AUTOMATION_NAME);84 platformName = ofNullable(ofNullable(super.getPlatformName())85 .orElse(capabilityPlatform1 != null ? String.valueOf(capabilityPlatform1) : null))86 .orElse(capabilityPlatform2 != null ? String.valueOf(capabilityPlatform2) : null);87 automationName = ofNullable(ofNullable(super.getAutomationName())88 .orElse(capabilityAutomation1 != null ? String.valueOf(capabilityAutomation1) : null))89 .orElse(capabilityAutomation2 != null ? String.valueOf(capabilityAutomation2) : null);90 this.setElementConverter(new JsonToMobileElementConverter(this, this));91 }92 public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {93 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),94 desiredCapabilities);95 }96 public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,97 Capabilities desiredCapabilities) {98 this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,99 httpClientFactory), desiredCapabilities);100 }101 public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {102 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),103 desiredCapabilities);104 }105 public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,106 Capabilities desiredCapabilities) {107 this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),108 desiredCapabilities);109 }110 public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {111 this(builder.build(), desiredCapabilities);112 }113 public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,114 Capabilities desiredCapabilities) {115 this(builder.build(), httpClientFactory, desiredCapabilities);116 }117 public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {118 this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,119 desiredCapabilities);120 }121 public AppiumDriver(Capabilities desiredCapabilities) {122 this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);123 }124 /**125 * @param originalCapabilities the given {@link Capabilities}.126 * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has127 * to be set up128 * @return {@link Capabilities} with changed mobile platform value129 */130 protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities,131 String newPlatform) {132 DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities);133 dc.setCapability(PLATFORM_NAME, newPlatform);134 return dc;135 }136 @Override public List<T> findElements(By by) {137 return super.findElements(by);138 }139 @Override public List<T> findElements(String by, String using) {140 return super.findElements(by, using);141 }142 @Override public List<T> findElementsById(String id) {143 return super.findElementsById(id);144 }145 public List<T> findElementsByLinkText(String using) {146 return super.findElementsByLinkText(using);147 }148 public List<T> findElementsByPartialLinkText(String using) {149 return super.findElementsByPartialLinkText(using);150 }151 public List<T> findElementsByTagName(String using) {152 return super.findElementsByTagName(using);153 }154 public List<T> findElementsByName(String using) {155 return super.findElementsByName(using);156 }157 public List<T> findElementsByClassName(String using) {158 return super.findElementsByClassName(using);159 }160 public List<T> findElementsByCssSelector(String using) {161 return super.findElementsByCssSelector(using);162 }163 public List<T> findElementsByXPath(String using) {164 return super.findElementsByXPath(using);165 }166 @Override public List<T> findElementsByAccessibilityId(String using) {167 return super.findElementsByAccessibilityId(using);168 }169 @Override public ExecuteMethod getExecuteMethod() {170 return executeMethod;171 }172 @Override public WebDriver context(String name) {173 checkNotNull(name, "Must supply a context name");174 execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name));175 return this;176 }177 @Override public Set<String> getContextHandles() {178 Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);179 Object value = response.getValue();180 try {181 List<String> returnedValues = (List<String>) value;182 return new LinkedHashSet<>(returnedValues);183 } catch (ClassCastException ex) {184 throw new WebDriverException(185 "Returned value cannot be converted to List<String>: " + value, ex);186 }187 }188 @Override public String getContext() {189 String contextName =190 String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());191 if ("null".equalsIgnoreCase(contextName)) {192 return null;193 }194 return contextName;195 }196 @Override public DeviceRotation rotation() {197 Response response = execute(DriverCommand.GET_SCREEN_ROTATION);198 DeviceRotation deviceRotation =199 new DeviceRotation((Map<String, Number>) response.getValue());200 if (deviceRotation.getX() < 0 || deviceRotation.getY() < 0 || deviceRotation.getZ() < 0) {201 throw new WebDriverException("Unexpected orientation returned: " + deviceRotation);202 }203 return deviceRotation;204 }205 @Override public void rotate(DeviceRotation rotation) {206 execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters());207 }208 @Override public void rotate(ScreenOrientation orientation) {209 execute(DriverCommand.SET_SCREEN_ORIENTATION,210 ImmutableMap.of("orientation", orientation.value().toUpperCase()));211 }212 @Override public ScreenOrientation getOrientation() {213 Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);214 String orientation = response.getValue().toString().toLowerCase();215 if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {216 return ScreenOrientation.LANDSCAPE;217 } else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {218 return ScreenOrientation.PORTRAIT;219 } else {...

Full Screen

Full Screen

Source:BasePage.java Github

copy

Full Screen

1package Pages;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.MobileElement;4import io.appium.java_client.pagefactory.AppiumFieldDecorator;5import org.openqa.selenium.DeviceRotation;6import org.openqa.selenium.Dimension;7import org.openqa.selenium.OutputType;8import org.openqa.selenium.TakesScreenshot;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.support.FindBy;11import org.openqa.selenium.support.PageFactory;12import org.openqa.selenium.support.ui.WebDriverWait;13import java.io.File;14/*Class which has */15public abstract class BasePage {16 @FindBy(id = "sign_in_button")17 protected WebElement LoginButton;18 19 @FindBy(xpath = "//android.widget.EditText[@resource-id='ap_email_login']")20 protected WebElement emailTextField;21 22 @FindBy(xpath = "//android.widget.Button[@text='Continue']")23 protected WebElement continueButton;24 25 @FindBy(xpath = "//android.widget.EditText[@resource-id='ap_password']")26 protected WebElement enterPassword;27 28 @FindBy(xpath = "//android.widget.Button[@resource-id='signInSubmit']")29 protected WebElement signInSubmitButton;30 31 @FindBy(xpath = "//android.view.View[@text='close']")32 protected static WebElement closeLanguageDialog;33 34 @FindBy(xpath = "//android.widget.EditText[@resource-id='com.amazon.mShop.android.shopping:id/rs_search_src_text']")35 protected WebElement searchTextBox;36 37 @FindBy(xpath = "//android.widget.TextView[@resource-id='com.amazon.mShop.android.shopping:id/loc_ux_update_current_pin_code']")38 protected static WebElement useMyCurrentLocationClick;39 40 @FindBy(id = "com.android.packageinstaller:id/permission_allow_button")41 protected static WebElement allowLocationButton;42 43 @FindBy(xpath = "//android.widget.ListView/android.widget.LinearLayout[3]")44 protected WebElement selectItem;45 46 @FindBy(xpath = "//android.view.View[@resource-id='add-to-wishlist-button-submit'][@text='ADD TO WISH LIST']")47 protected WebElement wishlistButtonStack;48 49 @FindBy(xpath = "//android.widget.Button[@class='android.widget.Button']")50 protected MobileElement sizeButtons;51 52 @FindBy(xpath = "//android.widget.Button[@resource-id='add-to-cart-button']")53 protected MobileElement addToCartButton;54 public static WebDriverWait wait;55 protected static Dimension size;56 protected static AppiumDriver<MobileElement> driver;57 58 public BasePage(AppiumDriver<MobileElement> driver) throws Exception {59 BasePage.driver = driver;60 PageFactory.initElements(new AppiumFieldDecorator(driver), this); 61 }62 public static boolean takeScreenshot(final String name) {63 String screenshotDirectory = System.getProperty("appium.screenshots.dir",64 System.getProperty("java.io.tmpdir", ""));65 File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);66 return screenshot.renameTo(new File(screenshotDirectory, String.format("%s.png", name)));67 }68 public static void sleep(int sleeptime) {69 try {70 Thread.sleep(sleeptime);71 } catch (InterruptedException e) {72 e.printStackTrace();73 }74 }75 76 public static void closeLanguageDialog() {77 takeScreenshot("closeLanguageDialog");78 try {79 closeLanguageDialog.click();80 } catch (Exception e) {81 System.err.println("Unable to click Login button");82 }83 takeScreenshot("closeLanguageDialog2");84 }85 86 public static void useMyCurrentLocationClick() {87 takeScreenshot("useMyCurrentLocationClick");88 try {89 useMyCurrentLocationClick.click();90 } catch (Exception e) {91 System.err.println("use My Current Location button not present");92 }93 takeScreenshot("useMyCurrentLocationClick2");94 95 takeScreenshot("allowLocationButton");96 try {97 allowLocationButton.click();98 } catch (Exception e) {99 System.err.println("allow Location Button not present");100 }101 takeScreenshot("allowLocationButton2");102 }103 104 public static void orientationTest() {105 driver.rotate(new DeviceRotation(0, 0, 90));106 takeScreenshot("selectItem");107 BasePage.sleep(2);108 driver.rotate(new DeviceRotation(0, 0, 180));109 takeScreenshot("selectItem");110 BasePage.sleep(2);111 driver.rotate(new DeviceRotation(0, 0, 270));112 takeScreenshot("selectItem");113 BasePage.sleep(2);114 driver.rotate(new DeviceRotation(0, 0, 0));115 takeScreenshot("selectItem");116 BasePage.sleep(2);117 }118}

Full Screen

Full Screen

Source:UIAutomator2Test.java Github

copy

Full Screen

...5import org.junit.After;6import org.junit.Ignore;7import org.junit.Test;8import org.openqa.selenium.By;9import org.openqa.selenium.DeviceRotation;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.WebDriverWait;13import java.time.Duration;14public class UIAutomator2Test extends BaseAndroidTest {15 @After16 public void afterMethod() {17 driver.rotate(new DeviceRotation(0, 0, 0));18 }19 @Test20 public void testLandscapeRightRotation() {21 new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions22 .elementToBeClickable(driver.findElement(By.id("android:id/content"))23 .findElement(AppiumBy.accessibilityId("Graphics"))));24 DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90);25 driver.rotate(landscapeRightRotation);26 assertEquals(driver.rotation(), landscapeRightRotation);27 }28 @Test29 public void testLandscapeLeftRotation() {30 new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions31 .elementToBeClickable(driver.findElement(By.id("android:id/content"))32 .findElement(AppiumBy.accessibilityId("Graphics"))));33 DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270);34 driver.rotate(landscapeLeftRotation);35 assertEquals(driver.rotation(), landscapeLeftRotation);36 }37 @Test38 public void testPortraitUpsideDown() {39 new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions40 .elementToBeClickable(driver.findElement(By.id("android:id/content"))41 .findElement(AppiumBy.accessibilityId("Graphics"))));42 DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180);43 driver.rotate(landscapeRightRotation);44 assertEquals(driver.rotation(), landscapeRightRotation);45 }46 /**47 * ignoring.48 */49 @Ignore50 public void testToastMSGIsDisplayed() {51 final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));52 Activity activity = new Activity("io.appium.android.apis", ".view.PopupMenu1");53 driver.startActivity(activity);54 wait.until(ExpectedConditions.presenceOfElementLocated(AppiumBy55 .accessibilityId("Make a Popup!")));56 WebElement popUpElement = driver.findElement(AppiumBy.accessibilityId("Make a Popup!"));...

Full Screen

Full Screen

Source:InvokeBrowser.java Github

copy

Full Screen

...4import java.net.MalformedURLException;5import java.net.URL;6import java.util.concurrent.TimeUnit;7import org.apache.xerces.util.URI.MalformedURIException;8import org.openqa.selenium.DeviceRotation;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.firefox.FirefoxProfile;11import org.openqa.selenium.remote.CapabilityType;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.chrome.*;1415import io.appium.java_client.AppiumDriver;16import io.appium.java_client.MobileElement;1718public class InvokeBrowser implements GlobalObjects {19 public enum browsers {20 FIRFOX, CHROME21 }2223 public void invokeBrowser(browsers browserName) throws MalformedURIException, MalformedURLException {24 // File app = new File("C:\\Program25 // Files\\Experitest\\SeeTest\\bin\\ipas","eribank.apk");26 DesiredCapabilities capabilities = new DesiredCapabilities();27 capabilities.setCapability(CapabilityType.BROWSER_NAME, "CHROME");28 capabilities.setCapability("deviceName", "ZY2232GXWX");29 capabilities.setCapability("platformName", "Android");30 capabilities.setCapability("platformVersion", "6.0.1");31 // capabilities.setCapability("app", app.getAbsolutePath());32 /*33 * capabilities.setCapability("app-package",34 * "com.experitest.ExperiBank");35 * capabilities.setCapability("app-activity", ".LoginActivity")36 */;37 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");38 URL url = new URL("http://127.0.0.1:4723/wd/hub");3940 switch (browserName) {41 case FIRFOX:42 if (objReadConfigProps.PLATFORM.equals("WEB")) {43 objGlobal.driver = new FirefoxDriver();44 objGlobal.driver.get(objReadConfigProps.URL);45 }4647 if (objReadConfigProps.PLATFORM.equals("MOBILE")) {48 objGlobal.driver = new AppiumDriver(url, capabilities) {49 @Override50 public MobileElement scrollToExact(String arg0) {51 // TODO Auto-generated method stub52 return null;53 }5455 @Override56 public MobileElement scrollTo(String arg0) {57 // TODO Auto-generated method stub58 return null;59 }6061 @Override62 public DeviceRotation rotation() {63 // TODO Auto-generated method stub64 return null;65 }6667 @Override68 public void rotate(DeviceRotation arg0) {69 // TODO Auto-generated method stub7071 }72 };73 objGlobal.driver.get(objReadConfigProps.URL);74 }75 break;7677 case CHROME:78 if (objReadConfigProps.PLATFORM.equals("WEB")) {79 //System.setProperty("webdriver.chrome.driver", "---PATH TO CHROME EXE FILE---");80 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");81 objGlobal.driver = new ChromeDriver();82 objGlobal.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);83 objGlobal.driver.get(objReadConfigProps.URL);84 }8586 if (objReadConfigProps.PLATFORM.equals("MOBILE")) {87 objGlobal.driver = new AppiumDriver(url, capabilities) {88 @Override89 public MobileElement scrollToExact(String arg0) {90 // TODO Auto-generated method stub91 return null;92 }9394 @Override95 public MobileElement scrollTo(String arg0) {96 // TODO Auto-generated method stub97 return null;98 }99100 @Override101 public DeviceRotation rotation() {102 // TODO Auto-generated method stub103 return null;104 }105106 @Override107 public void rotate(DeviceRotation arg0) {108 // TODO Auto-generated method stub109110 }111 };112 objGlobal.driver.navigate();113 objGlobal.driver.get(objReadConfigProps.URL);114 115 }116 break;117118 default:119 throw new IllegalArgumentException("Invalid selection method");120121 } ...

Full Screen

Full Screen

Source:Basics.java Github

copy

Full Screen

...9import io.appium.java_client.android.nativekey.AndroidKey;10import io.appium.java_client.android.nativekey.KeyEvent;11import io.appium.java_client.remote.AndroidMobileCapabilityType;12import org.openqa.selenium.By;13import org.openqa.selenium.DeviceRotation;14import org.openqa.selenium.ScreenOrientation;15import org.openqa.selenium.interactions.Actions;16import org.openqa.selenium.support.ui.ExpectedConditions;17import org.openqa.selenium.support.ui.WebDriverWait;18import java.beans.Visibility;19import java.net.MalformedURLException;20public class Basics extends BaseMobileTesting{21 public static void main(String[] args) throws MalformedURLException, InterruptedException {22 AndroidDriver<AndroidElement> driverAndroid = BaseMobileTesting.Capabilites();23 AndroidElement preferenceButton = driverAndroid.findElement(By.xpath("//android.widget.TextView[@text='Preference']"));24 preferenceButton.click();25 //xpath, id, class name, androidUIautomator26 // tagName[@id='hello']27 AndroidElement preference = driverAndroid.findElement(By.xpath("//android.widget.TextView[@text='3. Preference dependencies']"));28 WebDriverWait wait = new WebDriverWait(driverAndroid, 5);29 wait.until(ExpectedConditions.visibilityOf(preference));30 preference.click();31 AndroidElement wifiCheckBox = driverAndroid.findElement(By.id("android:id/checkbox"));32 wifiCheckBox.click();33 // driverAndroid.rotate(ScreenOrientation.LANDSCAPE);34 DeviceRotation deviceRotation = new DeviceRotation(90,90,90);35 driverAndroid.rotate(deviceRotation);36 AndroidElement wifiSettings = driverAndroid.findElement(By.xpath("(//android.widget.RelativeLayout)[2]"));37 wifiSettings.click();38 Thread.sleep(1000);39 AndroidElement wifiSettingsInputBox = driverAndroid.findElement(By.id("android:id/edit"));40 wifiSettingsInputBox.sendKeys("Hello World");41 AndroidElement okButton = driverAndroid.findElement(By.id("android:id/button1"));42 okButton.click();43 driverAndroid.pressKey(new KeyEvent(AndroidKey.HOME));44 Thread.sleep(4000);45 }46}...

Full Screen

Full Screen

Source:RemoteRotatable.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.remote;18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.DeviceRotation;20import org.openqa.selenium.Rotatable;21import org.openqa.selenium.ScreenOrientation;22import org.openqa.selenium.internal.Require;23import java.util.Map;24class RemoteRotatable implements Rotatable {25 private final ExecuteMethod executeMethod;26 public RemoteRotatable(ExecuteMethod executeMethod) {27 this.executeMethod = Require.nonNull("Execute method", executeMethod);28 }29 @Override30 public void rotate(ScreenOrientation orientation) {31 executeMethod.execute(DriverCommand.SET_SCREEN_ORIENTATION, ImmutableMap.of("orientation", orientation));32 }33 @Override34 public ScreenOrientation getOrientation() {35 return ScreenOrientation.valueOf(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}

Full Screen

Full Screen

Source:SupportsRotation.java Github

copy

Full Screen

...15 */16package io.appium.java_client.remote;17import com.google.common.collect.ImmutableMap;18import io.appium.java_client.ExecutesMethod;19import org.openqa.selenium.DeviceRotation;20import org.openqa.selenium.Rotatable;21import org.openqa.selenium.ScreenOrientation;22import org.openqa.selenium.WebDriver;23import org.openqa.selenium.remote.DriverCommand;24import org.openqa.selenium.remote.Response;25import java.util.Map;26public interface SupportsRotation extends WebDriver, ExecutesMethod, Rotatable {27 /**28 * Get device rotation.29 *30 * @return The rotation value.31 */32 default DeviceRotation rotation() {33 Response response = execute(DriverCommand.GET_SCREEN_ROTATION);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());...

Full Screen

Full Screen

Source:AddRotatable.java Github

copy

Full Screen

1package org.openqa.selenium.remote;2import com.google.common.collect.ImmutableMap;3import java.lang.reflect.Method;4import org.openqa.selenium.DeviceRotation;5import org.openqa.selenium.Rotatable;6import org.openqa.selenium.ScreenOrientation;7public class AddRotatable8 implements AugmenterProvider9{10 public AddRotatable() {}11 12 public Class<?> getDescribedInterface()13 {14 return Rotatable.class;15 }16 17 public InterfaceImplementation getImplementation(Object value) {18 new InterfaceImplementation() {19 public Object invoke(ExecuteMethod executeMethod, Object self, Method method, Object... args) {20 String m = method.getName();21 Object response;22 Object response; switch (m) {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;42 }43 };44 }45}...

Full Screen

Full Screen

DeviceRotation

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.DeviceRotation;2import org.openqa.selenium.ScreenOrientation;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5import java.net.URL;6public class RotateScreen {7 public static void main(String[] args) throws Exception {8 DesiredCapabilities capabilities = new DesiredCapabilities();9 capabilities.setCapability("platformName", "Android");10 capabilities.setCapability("deviceName", "Android Emulator");11 capabilities.setCapability("appPackage", "com.android.calculator2");12 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");13 capabilities.setCapability("automationName", "UiAutomator2");14 driver.rotate(ScreenOrientation.LANDSCAPE);15 driver.rotate(ScreenOrientation.PORTRAIT);16 driver.rotate(new DeviceRotation(90, 90, 90));17 Thread.sleep(5000);18 driver.quit();19 }20}

Full Screen

Full Screen

DeviceRotation

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.*;2import org.openqa.selenium.remote.*;3import org.openqa.selenium.html5.*;4import java.net.URL;5import java.net.MalformedURLException;6import java.util.concurrent.TimeUnit;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.openqa.selenium.support.ui.ExpectedCondition;10import org.openqa.selenium.support.ui.FluentWait;11import org.openqa.selenium.support.ui.Wait;12import java.util.concurrent.TimeUnit;13import java.util.function.Function;14import java.util.function.Predicate;15import java.util.function.Supplier;16import java.util.List;17import java.util.ArrayList;18import java.util.Arrays;19import java.util.Map;20import java.util.HashMap;21import java.util.Set;22import java.util.HashSet;23import java.util.stream.Collectors;24import java.util.stream.Stream;25public class DeviceRotation {26 public static void main(String[] args) throws MalformedURLException {27 DesiredCapabilities caps = new DesiredCapabilities();28 caps.setCapability("deviceName", "iPhone 6");29 caps.setCapability("platformName", "iOS");30 caps.setCapability("platformVersion", "9.1");31 caps.setCapability("browserName", "Safari");32 caps.setCapability("udid", "f4a0b1e3b9b3d0b3ce3f7e6b4d8f8b2f0b1d2e2d");33 caps.setCapability("deviceOrientation", "portrait");34 caps.setCapability("appiumVersion", "1.4.16");

Full Screen

Full Screen

DeviceRotation

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.DeviceRotation;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.interactions.touch.TouchActions;4import org.testng.annotations.Test;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;9import io.appium.java_client.remote.MobileCapabilityType;10public class TouchActionDemo {11 public void f() throws MalformedURLException {12 DesiredCapabilities cap = new DesiredCapabilities();13 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");14 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");15 cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.0");16 cap.setCapability("appPackage", "com.android.calculator2");17 cap.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

DeviceRotation

Using AI Code Generation

copy

Full Screen

1package com.test;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.testng.annotations.AfterMethod;6import org.testng.annotations.BeforeMethod;7import org.testng.annotations.Test;8import java.net.MalformedURLException;9import java.net.URL;10public class AppiumTest {11 private WebDriver driver;12 public void setUp() throws MalformedURLException {13 DesiredCapabilities caps = new DesiredCapabilities();14 caps.setCapability("platformName", "Android");15 caps.setCapability("platformVersion", "6.0");16 caps.setCapability("deviceName", "Android Emulator");17 caps.setCapability("appPackage", "com.android.calculator2");18 caps.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen
copy
1public class Leaker {2 private static final Map<String, Object> CACHE = new HashMap<String, Object>();34 // Keep adding until failure.5 public static void addToCache(String key, Object value) { Leaker.CACHE.put(key, value); }6}7
Full Screen

Selenium 4 Tutorial:

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.

Chapters:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

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

...Most popular Stackoverflow questions on DeviceRotation

Most used methods in DeviceRotation

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful