org.openqa.selenium.ScreenOrientation源码实例Demo

类org.openqa.selenium.ScreenOrientation源码实例Demo

下面列出了org.openqa.selenium.ScreenOrientation 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: vividus   文件: WebDriverManager.java
@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());
}
 
源代码2 项目: vividus   文件: WebDriverManager.java
@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;
}
 
源代码3 项目: vividus   文件: WebDriverManagerTests.java
@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());
}
 
源代码4 项目: vividus   文件: WebDriverManagerTests.java
@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);
}
 
源代码5 项目: java-client   文件: AndroidOptionsTest.java
@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());
}
 
源代码6 项目: java-client   文件: BaseListenerTest.java
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();
    }
}
 
源代码7 项目: java-client   文件: IOSOptionsTest.java
@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());
}
 
源代码8 项目: java-client   文件: MobileOptionsTest.java
@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());
}
 
源代码9 项目: vividus   文件: AshotFactory.java
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));
}
 
源代码10 项目: vividus   文件: WebDriverManagerTests.java
@ParameterizedTest
@EnumSource(ScreenOrientation.class)
void shouldNotDetectOrientationForDesktop(ScreenOrientation orientation)
{
    mockWebDriverHavingCapabilities(Map.of(CapabilityType.PLATFORM_NAME, Platform.WIN10.toString()));
    assertFalse(webDriverManager.isOrientation(orientation));
}
 
源代码11 项目: vividus   文件: WebDriverManagerTests.java
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)
    );
}
 
源代码12 项目: vividus   文件: WebDriverManagerTests.java
@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);
}
 
源代码13 项目: vividus   文件: WebDriverManagerTests.java
@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);
}
 
源代码14 项目: vividus   文件: WebDriverManagerTests.java
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))
    );
}
 
源代码15 项目: vividus   文件: WebDriverManagerTests.java
@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();
}
 
@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"));
}
 
源代码17 项目: coteafs-appium   文件: VodQATest.java
/**
 * @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();
}
 
源代码18 项目: coteafs-appium   文件: VodQATest.java
/**
 * @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());
}
 
源代码19 项目: functional-tests-core   文件: MobileSettings.java
/**
 * 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;
    }
}
 
源代码20 项目: java-client   文件: AppiumDriver.java
@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);
    }
}
 
源代码21 项目: java-client   文件: AndroidDriverTest.java
@Test
public void orientationTest() {
    assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation());
    driver.rotate(ScreenOrientation.LANDSCAPE);
    assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation());
    driver.rotate(ScreenOrientation.PORTRAIT);
}
 
源代码22 项目: selenium   文件: AugmenterTest.java
@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());
}
 
源代码23 项目: vividus   文件: AshotFactoryTests.java
private void mockDeviceAndOrientation()
{
    String deviceName = "Google pixel 3";
    when(webDriverFactory.getCapability(SauceLabsCapabilityType.DEVICE_NAME, false)).thenReturn(deviceName);
    when(webDriverManager.isOrientation(ScreenOrientation.LANDSCAPE)).thenReturn(true);
}
 
源代码24 项目: bobcat   文件: WebDriverWrapper.java
@Override
public ScreenOrientation getOrientation() {
  return ((Rotatable) super.getWrappedDriver()).getOrientation();
}
 
源代码25 项目: bobcat   文件: WebDriverWrapper.java
@Override
public void rotate(ScreenOrientation screenOrientation) {
  ((Rotatable) super.getWrappedDriver()).rotate(screenOrientation);
}
 
源代码26 项目: xframium-java   文件: AbstractRotateGesture.java
public void setParameters( Object[] parameterArray )
{
	setOrientation( (ScreenOrientation) parameterArray[ 0 ] );
}
 
源代码27 项目: java-client   文件: AppiumDriver.java
@Override
public void rotate(ScreenOrientation orientation) {
    execute(DriverCommand.SET_SCREEN_ORIENTATION,
            ImmutableMap.of("orientation", orientation.value().toUpperCase()));
}
 
源代码28 项目: java-client   文件: DefaultListener.java
@Override public void beforeRotation(WebDriver driver, ScreenOrientation orientation) {
    ((RotationEventListener) dispatcher).beforeRotation(driver, orientation);
}
 
源代码29 项目: java-client   文件: DefaultListener.java
@Override public void afterRotation(WebDriver driver, ScreenOrientation orientation) {
    ((RotationEventListener) dispatcher).afterRotation(driver, orientation);
}
 
源代码30 项目: java-client   文件: EmptyWebDriver.java
@Override public void rotate(ScreenOrientation orientation) {
    //The rotation does nothing there
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法