org.openqa.selenium.ScreenOrientation Java Examples
The following examples show how to use
org.openqa.selenium.ScreenOrientation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebDriverManager.java From vividus with Apache License 2.0 | 6 votes |
@Override public Dimension getSize() { if (isMobile()) { Dimension dimension = webDriverManagerContext.getParameter(WebDriverManagerParameter.SCREEN_SIZE); if (dimension == null) { dimension = runInNativeContext(this::getSize); webDriverManagerContext.putParameter(WebDriverManagerParameter.SCREEN_SIZE, dimension); } return isOrientation(ScreenOrientation.LANDSCAPE) ? new Dimension(dimension.height, dimension.width) : dimension; } return getSize(getWebDriver()); }
Example #2
Source File: WebDriverManager.java From vividus with Apache License 2.0 | 6 votes |
@Override public boolean isOrientation(ScreenOrientation orientation) { if (!isMobile()) { return false; } ScreenOrientation screenOrientation = webDriverManagerContext.getParameter(WebDriverManagerParameter.ORIENTATION); if (screenOrientation == null) { screenOrientation = webDriverProvider.getUnwrapped(Rotatable.class).getOrientation(); webDriverManagerContext.putParameter(WebDriverManagerParameter.ORIENTATION, screenOrientation); } return orientation == screenOrientation; }
Example #3
Source File: AndroidOptionsTest.java From java-client with Apache License 2.0 | 6 votes |
@Test public void acceptsMobileCapabilities() throws MalformedURLException { androidOptions.setApp(new URL("http://example.com/myapp.apk")) .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2) .setPlatformVersion("10") .setDeviceName("Pixel") .setOtherApps("/path/to/app.apk") .setLocale("fr_CA") .setUdid("1ae203187fc012g") .setOrientation(ScreenOrientation.LANDSCAPE) .setNewCommandTimeout(Duration.ofSeconds(60)) .setLanguage("fr"); assertEquals("http://example.com/myapp.apk", androidOptions.getApp()); assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, androidOptions.getAutomationName()); assertEquals("10", androidOptions.getPlatformVersion()); assertEquals("Pixel", androidOptions.getDeviceName()); assertEquals("/path/to/app.apk", androidOptions.getOtherApps()); assertEquals("fr_CA", androidOptions.getLocale()); assertEquals("1ae203187fc012g", androidOptions.getUdid()); assertEquals(ScreenOrientation.LANDSCAPE, androidOptions.getOrientation()); assertEquals(Duration.ofSeconds(60), androidOptions.getNewCommandTimeout()); assertEquals("fr", androidOptions.getLanguage()); }
Example #4
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testGetSize() { MobileDriver<?> mobileDriver = mock(MobileDriver.class, withSettings().extraInterfaces(HasCapabilities.class)); Set<String> contexts = new HashSet<>(); contexts.add(WEBVIEW_CONTEXT); contexts.add(NATIVE_APP_CONTEXT); mockMobileDriverContext(mobileDriver, WEBVIEW_CONTEXT, contexts); lenient().when(webDriverManagerContext.getParameter(WebDriverManagerParameter.SCREEN_SIZE)).thenReturn(null); lenient().when(webDriverManagerContext.getParameter(WebDriverManagerParameter.ORIENTATION)) .thenReturn(ScreenOrientation.PORTRAIT); WebDriverManager spy = spyIsMobile(true); Window window = mock(Window.class); when(mockOptions(mobileDriver).window()).thenReturn(window); when(window.getSize()).thenReturn(mock(Dimension.class)); assertNotNull(spy.getSize()); }
Example #5
Source File: BaseListenerTest.java From java-client with Apache License 2.0 | 6 votes |
protected boolean assertThatRotationListenerWorks(EmptyWebDriver driver, TestListener listener, String prefix) { try { driver.rotate(ScreenOrientation.LANDSCAPE); driver.rotate(ScreenOrientation.PORTRAIT); assertThat(listener.messages, contains(prefix + "Attempt to change screen orientation. The new screen orientation is " + ScreenOrientation.LANDSCAPE.toString(), prefix + "The screen orientation has been changed to " + ScreenOrientation.LANDSCAPE.toString(), prefix + "Attempt to change screen orientation. The new screen orientation is " + ScreenOrientation.PORTRAIT.toString(), prefix + "The screen orientation has been changed to " + ScreenOrientation.PORTRAIT.toString())); return true; } finally { listener.messages.clear(); } }
Example #6
Source File: IOSOptionsTest.java From java-client with Apache License 2.0 | 6 votes |
@Test public void acceptsMobileCapabilities() throws MalformedURLException { iosOptions.setApp(new URL("http://example.com/myapp.apk")) .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2) .setPlatformVersion("10") .setDeviceName("Pixel") .setOtherApps("/path/to/app.apk") .setLocale("fr_CA") .setUdid("1ae203187fc012g") .setOrientation(ScreenOrientation.LANDSCAPE) .setNewCommandTimeout(Duration.ofSeconds(60)) .setLanguage("fr"); assertEquals("http://example.com/myapp.apk", iosOptions.getApp()); assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, iosOptions.getAutomationName()); assertEquals("10", iosOptions.getPlatformVersion()); assertEquals("Pixel", iosOptions.getDeviceName()); assertEquals("/path/to/app.apk", iosOptions.getOtherApps()); assertEquals("fr_CA", iosOptions.getLocale()); assertEquals("1ae203187fc012g", iosOptions.getUdid()); assertEquals(ScreenOrientation.LANDSCAPE, iosOptions.getOrientation()); assertEquals(Duration.ofSeconds(60), iosOptions.getNewCommandTimeout()); assertEquals("fr", iosOptions.getLanguage()); }
Example #7
Source File: MobileOptionsTest.java From java-client with Apache License 2.0 | 6 votes |
@Test public void acceptsMobileCapabilities() throws MalformedURLException { mobileOptions.setApp(new URL("http://example.com/myapp.apk")) .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2) .setPlatformVersion("10") .setDeviceName("Pixel") .setOtherApps("/path/to/app.apk") .setLocale("fr_CA") .setUdid("1ae203187fc012g") .setOrientation(ScreenOrientation.LANDSCAPE) .setNewCommandTimeout(Duration.ofSeconds(60)) .setLanguage("fr"); assertEquals("http://example.com/myapp.apk", mobileOptions.getApp()); assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, mobileOptions.getAutomationName()); assertEquals("10", mobileOptions.getPlatformVersion()); assertEquals("Pixel", mobileOptions.getDeviceName()); assertEquals("/path/to/app.apk", mobileOptions.getOtherApps()); assertEquals("fr_CA", mobileOptions.getLocale()); assertEquals("1ae203187fc012g", mobileOptions.getUdid()); assertEquals(ScreenOrientation.LANDSCAPE, mobileOptions.getOrientation()); assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout()); assertEquals("fr", mobileOptions.getLanguage()); }
Example #8
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("nativeApplicationViewportProvider") void testGetScreenSizeForPortraitOrientation(ScreenOrientation orientation, Dimension dimension, Dimension viewport) { lenient().when(webDriverProvider.getUnwrapped(MobileDriver.class)).thenReturn(mobileDriver); lenient().when(webDriverProvider.getUnwrapped(Rotatable.class)).thenReturn(mobileDriver); when(mobileDriver.getOrientation()).thenReturn(orientation); when(mobileDriver.getContext()).thenReturn(NATIVE_APP_CONTEXT); WebDriverManager spy = spyIsMobile(true); Options options = mock(Options.class); when(mobileDriver.manage()).thenReturn(options); Window window = mock(Window.class); when(options.window()).thenReturn(window); when(window.getSize()).thenReturn(dimension); assertEquals(viewport, spy.getSize()); verify(webDriverManagerContext).putParameter(WebDriverManagerParameter.SCREEN_SIZE, dimension); }
Example #9
Source File: AndroidDriverTest.java From java-client with Apache License 2.0 | 5 votes |
@Test public void orientationTest() { assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation()); driver.rotate(ScreenOrientation.LANDSCAPE); assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation()); driver.rotate(ScreenOrientation.PORTRAIT); }
Example #10
Source File: AppiumDriver.java From java-client with Apache License 2.0 | 5 votes |
@Override public ScreenOrientation getOrientation() { Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION); String orientation = response.getValue().toString().toLowerCase(); if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) { return ScreenOrientation.LANDSCAPE; } else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) { return ScreenOrientation.PORTRAIT; } else { throw new WebDriverException("Unexpected orientation returned: " + orientation); } }
Example #11
Source File: MobileSettings.java From functional-tests-core with Apache License 2.0 | 5 votes |
/** * Get screen orientation settings. * <p> * * @return ScreenOrientation. */ private ScreenOrientation getScreenOrientation() { String orientation = this.properties.getProperty("orientation", "none"); if (orientation.toLowerCase().contains("port")) { return ScreenOrientation.PORTRAIT; } else if (orientation.toLowerCase().contains("land")) { return ScreenOrientation.LANDSCAPE; } else { return null; } }
Example #12
Source File: VodQATest.java From coteafs-appium with Apache License 2.0 | 5 votes |
/** * @param orientation * @author wasiqb * @since Oct 21, 2018 */ @Test(dataProvider = "getOrientation") public void testRotation(final ScreenOrientation orientation) { this.main.onDevice() .rotate(orientation); assertThat(this.main.onDevice() .rotation() .name()).isEqualTo(orientation.name()); }
Example #13
Source File: VodQATest.java From coteafs-appium with Apache License 2.0 | 5 votes |
/** * @return orientation list * @author wasiqb * @since Oct 21, 2018 */ @DataProvider public static Iterator<Object[]> getOrientation() { final List<Object[]> data = new ArrayList<>(); data.add(new Object[] { ScreenOrientation.LANDSCAPE }); data.add(new Object[] { ScreenOrientation.PORTRAIT }); return data.iterator(); }
Example #14
Source File: AugmenterTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void shouldBeAbleToAugmentMultipleTimes() { Capabilities caps = new ImmutableCapabilities("canRotate", true, "magic.numbers", true); StubExecutor stubExecutor = new StubExecutor(caps); stubExecutor.expect(DriverCommand.GET_SCREEN_ORIENTATION, Collections.emptyMap(), ScreenOrientation.PORTRAIT.name()); RemoteWebDriver driver = new RemoteWebDriver(stubExecutor, caps); WebDriver augmented = getAugmenter() .addDriverAugmentation( "canRotate", Rotatable.class, (c, exe) -> new RemoteRotatable(exe)) .augment(driver); assertThat(driver).isNotSameAs(augmented); assertThat(augmented).isInstanceOf(Rotatable.class); assertThat(augmented).isNotInstanceOf(HasMagicNumbers.class); WebDriver augmentedAgain = getAugmenter() .addDriverAugmentation( "magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42) .augment(augmented); assertThat(augmented).isNotSameAs(augmentedAgain); assertThat(augmentedAgain).isInstanceOf(Rotatable.class); assertThat(augmentedAgain).isInstanceOf(HasMagicNumbers.class); ((Rotatable) augmentedAgain).getOrientation(); // Should not throw. assertThat(((HasCapabilities) augmentedAgain).getCapabilities()) .isSameAs(driver.getCapabilities()); }
Example #15
Source File: AshotFactory.java From vividus with Apache License 2.0 | 5 votes |
private AShot createAShot(ShootingStrategy baseShootingStrategy, ScreenshotShootingStrategy screenshotShootingStrategy, boolean viewportScreenshot) { String deviceName = webDriverFactory.getCapability(SauceLabsCapabilityType.DEVICE_NAME, false); boolean landscapeOrientation = webDriverManager.isOrientation(ScreenOrientation.LANDSCAPE); ShootingStrategy shootingStrategy = screenshotShootingStrategy.getDecoratedShootingStrategy( baseShootingStrategy, viewportScreenshot, landscapeOrientation, deviceName); return new AShot().shootingStrategy(shootingStrategy) .coordsProvider(screenshotShootingStrategy == ScreenshotShootingStrategy.SIMPLE ? CeilingJsCoordsProvider.getSimple(javascriptActions) : CeilingJsCoordsProvider.getScrollAdjusted(javascriptActions)); }
Example #16
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testGetNativeApplicationViewportCached() { mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, MobilePlatform.IOS)); when(webDriverProvider.getUnwrapped(Rotatable.class)).thenReturn(mobileDriver); lenient().when(webDriverManagerContext.getParameter(WebDriverManagerParameter.ORIENTATION)).thenReturn(null); when(mobileDriver.getOrientation()).thenReturn(ScreenOrientation.PORTRAIT); Dimension dimension = new Dimension(375, 667); lenient().when(webDriverManagerContext.getParameter(WebDriverManagerParameter.SCREEN_SIZE)) .thenReturn(dimension); Dimension actualDimension = webDriverManager.getSize(); assertEquals(dimension.getHeight(), actualDimension.getHeight()); assertEquals(dimension.getWidth(), actualDimension.getWidth()); verify(this.mobileDriver, never()).manage(); }
Example #17
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 5 votes |
@ParameterizedTest @EnumSource(ScreenOrientation.class) void shouldNotDetectOrientationForDesktop(ScreenOrientation orientation) { mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, Platform.WIN10.toString())); assertFalse(webDriverManager.isOrientation(orientation)); }
Example #18
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 5 votes |
static Stream<Arguments> nativeApplicationViewportProvider() { return Stream.of( Arguments.of(ScreenOrientation.LANDSCAPE, new Dimension(375, 667), new Dimension(667, 375)), Arguments.of(ScreenOrientation.PORTRAIT, new Dimension(375, 667), new Dimension(375, 667)) ); }
Example #19
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testOrientationCached() { mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, MobilePlatform.IOS)); when(webDriverManagerContext.getParameter(WebDriverManagerParameter.ORIENTATION)) .thenReturn(ScreenOrientation.PORTRAIT); assertTrue(webDriverManager.isOrientation(ScreenOrientation.PORTRAIT)); verifyNoInteractions(mobileDriver); }
Example #20
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 5 votes |
@ParameterizedTest @MethodSource("orientationProvider") void testIsOrientation(ScreenOrientation actualOrientation, ScreenOrientation orientationToCheck, String platform) { when(webDriverProvider.getUnwrapped(Rotatable.class)).thenReturn(mobileDriver); when(webDriverManagerContext.getParameter(WebDriverManagerParameter.ORIENTATION)).thenReturn(null); when(mobileDriver.getOrientation()).thenReturn(actualOrientation); mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, platform)); assertEquals(actualOrientation == orientationToCheck, webDriverManager.isOrientation(orientationToCheck)); verify(webDriverManagerContext).putParameter(WebDriverManagerParameter.ORIENTATION, actualOrientation); }
Example #21
Source File: Edition112_iOS_Screenshot_Orientation.java From appiumpro with Apache License 2.0 | 5 votes |
@Test public void testScreenshots() throws Exception { Thread.sleep(2000); String desktop = System.getenv("HOME") + "/Desktop"; driver.rotate(ScreenOrientation.LANDSCAPE); File regularScreenshot = driver.getScreenshotAs(OutputType.FILE); driver.setSetting("screenshotOrientation", "landscapeRight"); File adjustedScreenshot = driver.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(regularScreenshot, new File(desktop + "/screen1.png")); FileUtils.copyFile(adjustedScreenshot, new File(desktop + "/screen2.png")); }
Example #22
Source File: WebDriverManagerTests.java From vividus with Apache License 2.0 | 5 votes |
static Stream<Arguments> orientationProvider() { return Stream.of( Arguments.of(ScreenOrientation.LANDSCAPE, ScreenOrientation.PORTRAIT, MobilePlatform.ANDROID), Arguments.of(ScreenOrientation.PORTRAIT, ScreenOrientation.PORTRAIT, MobilePlatform.ANDROID), Arguments.of(ScreenOrientation.LANDSCAPE, ScreenOrientation.PORTRAIT, MobilePlatform.IOS), Arguments.of(ScreenOrientation.PORTRAIT, ScreenOrientation.PORTRAIT, MobilePlatform.IOS), Arguments.of(ScreenOrientation.LANDSCAPE, ScreenOrientation.LANDSCAPE, MobilePlatform.ANDROID), Arguments.of(ScreenOrientation.PORTRAIT, ScreenOrientation.LANDSCAPE, MobilePlatform.ANDROID), Arguments.of(ScreenOrientation.LANDSCAPE, ScreenOrientation.LANDSCAPE, MobilePlatform.IOS), Arguments.of(ScreenOrientation.PORTRAIT, ScreenOrientation.LANDSCAPE, MobilePlatform.IOS) ); }
Example #23
Source File: RotationListener2.java From java-client with Apache License 2.0 | 4 votes |
@Override public void afterRotation(WebDriver driver, ScreenOrientation orientation) { messages.add("Externally defined listener: The screen orientation has been changed to " + orientation.toString()); }
Example #24
Source File: GetScreenOrientation.java From selenium with Apache License 2.0 | 4 votes |
@Override public ScreenOrientation call() { return ((Rotatable) getUnwrappedDriver()).getOrientation(); }
Example #25
Source File: EmptyWebDriver.java From java-client with Apache License 2.0 | 4 votes |
@Override public void rotate(ScreenOrientation orientation) { //The rotation does nothing there }
Example #26
Source File: EmptyWebDriver.java From java-client with Apache License 2.0 | 4 votes |
@Override public ScreenOrientation getOrientation() { return null; }
Example #27
Source File: RotationListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void beforeRotation(WebDriver driver, ScreenOrientation orientation) { messages.add("Attempt to change screen orientation. The new screen orientation is " + orientation.toString()); }
Example #28
Source File: RotationListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void afterRotation(WebDriver driver, ScreenOrientation orientation) { messages.add("The screen orientation has been changed to " + orientation.toString()); }
Example #29
Source File: RotationListener2.java From java-client with Apache License 2.0 | 4 votes |
@Override public void beforeRotation(WebDriver driver, ScreenOrientation orientation) { messages.add("Externally defined listener: Attempt to change screen orientation. " + "The new screen orientation is " + orientation.toString()); }
Example #30
Source File: IOSDriverTest.java From java-client with Apache License 2.0 | 4 votes |
@Test public void orientationTest() { assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation()); driver.rotate(ScreenOrientation.LANDSCAPE); assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation()); driver.rotate(ScreenOrientation.PORTRAIT); }