org.openqa.selenium.WebDriver.Window Java Examples

The following examples show how to use org.openqa.selenium.WebDriver.Window. 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 vote down vote up
@Override
public void resize(WebDriver webDriver, BrowserWindowSize browserWindowSize)
{
    if (isElectronApp() || isMobile(WebDriverUtil.unwrap(webDriver, HasCapabilities.class).getCapabilities()))
    {
        return;
    }
    Window window = webDriver.manage().window();
    if (browserWindowSize == null)
    {
        window.maximize();
    }
    else
    {
        window.setSize(browserWindowSize.toDimension());
    }
}
 
Example #2
Source File: WebDriverManagerTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: WebDriverManagerTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: VividusWebDriverFactoryTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
private void runCreateTest(boolean remoteExecution, String browserName) throws Exception
{
    vividusWebDriverFactory.setRemoteExecution(remoteExecution);
    vividusWebDriverFactory.setWebDriverEventListeners(List.of(webDriverEventListener));

    when(bddRunContext.getRunningStory()).thenReturn(createRunningStory(browserName));
    EventFiringWebDriver eventFiringWebDriver = mock(EventFiringWebDriver.class);
    PowerMockito.whenNew(EventFiringWebDriver.class).withArguments(driver).thenReturn(eventFiringWebDriver);
    Options options = mock(Options.class);
    when(eventFiringWebDriver.manage()).thenReturn(options);
    Window window = mock(Window.class);
    when(options.window()).thenReturn(window);
    when(eventFiringWebDriver.getCapabilities()).thenReturn(mock(Capabilities.class));
    BrowserWindowSize windowSize = new BrowserWindowSize("1920x1080");
    when(browserWindowSizeProvider.getBrowserWindowSize(remoteExecution))
            .thenReturn(windowSize);
    VividusWebDriver vividusWebDriver = vividusWebDriverFactory.create();
    assertEquals(eventFiringWebDriver, vividusWebDriver.getWrappedDriver());
    verify(eventFiringWebDriver).register(webDriverEventListener);
    assertEquals(remoteExecution, vividusWebDriver.isRemote());
    verify(webDriverManagerContext).reset(WebDriverManagerParameter.DESIRED_CAPABILITIES);
    verify(webDriverManager).resize(eventFiringWebDriver, windowSize);
}
 
Example #5
Source File: WindowsActionsTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testCloseAllWindowsExceptOneNotMobile()
{
    when(webDriverProvider.get()).thenReturn(webDriver);
    Set<String> windows = new LinkedHashSet<>(List.of(WINDOW1, WINDOW2));
    TargetLocator targetLocator = mock(TargetLocator.class);
    when(webDriver.getWindowHandles()).thenReturn(windows);
    when(webDriver.switchTo()).thenReturn(targetLocator);
    Options options = mock(Options.class);
    Window window = mock(Window.class);
    when(webDriver.manage()).thenReturn(options);
    when(options.window()).thenReturn(window);
    when(window.getSize()).thenAnswer(i -> new Dimension(DIMENSION_SIZE, DIMENSION_SIZE));
    when(webDriverManager.isAndroid()).thenReturn(false);
    windowsActions.closeAllWindowsExceptOne();
    verify(webDriver, times(1)).close();
}
 
Example #6
Source File: AbstractDriver.java    From coteafs-selenium with Apache License 2.0 6 votes vote down vote up
private void setScreen(final PlaybackSetting playback) {
    final ScreenState state = playback.getScreenState();
    if (getPlatform() == DESKTOP) {
        LOG.i("Setting screen size of Browser to {}...", state);
        switch (state) {
            case FULL_SCREEN:
                manageWindow(Window::fullscreen);
                break;
            case MAXIMIZED:
                manageWindow(Window::maximize);
                break;
            case NORMAL:
            default:
                final ScreenResolution resolution = playback.getScreenResolution();
                LOG.i("Setting screen resolution to [{}]...", resolution);
                manageWindow(w -> w.setSize(new Dimension(resolution.getWidth(), resolution.getHeight())));
                manageWindow(w -> w.setPosition(new Point(0, 0)));
                break;
        }
    }
}
 
Example #7
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void windowSize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Dimension actual = window.getSize();
    AssertJUnit.assertNotNull(actual);
    java.awt.Dimension expected = EventQueueWait.call(frame, "getSize");
    AssertJUnit.assertEquals(expected.width, actual.width);
    AssertJUnit.assertEquals(expected.height, actual.height);
}
 
Example #8
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void windowPosition() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Point actual = window.getPosition();
    AssertJUnit.assertNotNull(actual);
    java.awt.Point expected = EventQueueWait.call(frame, "getLocation");
    AssertJUnit.assertEquals(expected.x, actual.x);
    AssertJUnit.assertEquals(expected.y, actual.y);
}
 
Example #9
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void windowSetSize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Dimension actual = window.getSize();
    AssertJUnit.assertNotNull(actual);
    java.awt.Dimension expected = EventQueueWait.call(frame, "getSize");
    AssertJUnit.assertEquals(expected.width, actual.width);
    AssertJUnit.assertEquals(expected.height, actual.height);
    window.setSize(new Dimension(expected.width * 2, expected.height * 2));
    actual = window.getSize();
    AssertJUnit.assertEquals(expected.width * 2, actual.width);
    AssertJUnit.assertEquals(expected.height * 2, actual.height);
}
 
Example #10
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void windowSetPosition() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Point actual = window.getPosition();
    AssertJUnit.assertNotNull(actual);
    java.awt.Point expected = EventQueueWait.call(frame, "getLocation");
    AssertJUnit.assertEquals(expected.x, actual.x);
    AssertJUnit.assertEquals(expected.y, actual.y);
    window.setPosition(new Point(expected.x + 10, expected.y + 10));
    actual = window.getPosition();
    AssertJUnit.assertEquals(expected.x + 10, actual.x);
    AssertJUnit.assertEquals(expected.y + 10, actual.y);
}
 
Example #11
Source File: WebDriverManagerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testResizeWebDriverWithDesiredBrowserSize()
{
    WebDriver webDriver = mockWebDriverHavingCapabilities(Map.of());
    BrowserWindowSize browserWindowSize = mock(BrowserWindowSize.class);
    Window window = mock(Window.class);
    when(mockOptions(webDriver).window()).thenReturn(window);
    Dimension dimension = mock(Dimension.class);
    when(browserWindowSize.toDimension()).thenReturn(dimension);
    webDriverManager.resize(browserWindowSize);
    verify(window).setSize(dimension);
}
 
Example #12
Source File: WebDriverManagerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testResizeWebDriverWithNullBrowserSize()
{
    WebDriver webDriver = mockWebDriverHavingCapabilities();
    Window window = mock(Window.class);
    when(mockOptions(webDriver).window()).thenReturn(window);
    webDriverManager.resize(null);
    verify(window).maximize();
}
 
Example #13
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void windowMaximize() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    window.maximize();
}
 
Example #14
Source File: WebDriverBrowserTest.java    From webtester-core with Apache License 2.0 5 votes vote down vote up
private Window mockWindow() {
    Options options = mock(Options.class);
    doReturn(options).when(webDriver).manage();
    Window window = mock(Window.class);
    doReturn(window).when(options).window();
    return window;
}
 
Example #15
Source File: AbstractDriver.java    From coteafs-selenium with Apache License 2.0 4 votes vote down vote up
private void manageWindow(final Consumer<Window> window) {
    window.accept(getDriver().manage()
        .window());
}
 
Example #16
Source File: WebDriverBrowserTest.java    From webtester-core with Apache License 2.0 4 votes vote down vote up
@Test
public void testThatMaximizingTheCurrentWindowInvokesCorrectWebDriverMethods() {
    Window window = mockWindow();
    cut.maximizeCurrentWindow();
    verify(window).maximize();
}