Search in sources :

Example 1 with GetWindowForTargetResponse

use of org.openqa.selenium.devtools.v100.browser.Browser.GetWindowForTargetResponse in project selenium_cdp by sergueik.

the class WindowSizeDevToolsTest method test1.

@Test
public void test1() {
    System.err.println("test1");
    // Act
    try {
        final GetWindowForTargetResponse result = chromeDevTools.send(Browser.getWindowForTarget(Optional.empty()));
        windowId = result.getWindowId();
        System.err.println(String.format("top: %d left: %d width: %d height: %d state: %s", result.getBounds().getTop().get(), result.getBounds().getLeft().get(), result.getBounds().getWidth().get(), result.getBounds().getHeight().get(), result.getBounds().getWindowState().get()));
    } catch (DevToolsException e) {
        System.err.println("DevToolsException exception " + "in test2" + " (ignored): " + Utils.processExceptionMessage(e.getMessage()));
    }
}
Also used : GetWindowForTargetResponse(org.openqa.selenium.devtools.v100.browser.Browser.GetWindowForTargetResponse) DevToolsException(org.openqa.selenium.devtools.DevToolsException) Test(org.junit.Test)

Example 2 with GetWindowForTargetResponse

use of org.openqa.selenium.devtools.v100.browser.Browser.GetWindowForTargetResponse in project selenium_cdp by sergueik.

the class ChromeDevToolsTest method broserGetWindowBoundsTest.

@Test
public // https://chromedevtools.github.io/devtools-protocol/tot/Browser#method-getWindowForTarget
void broserGetWindowBoundsTest() {
    GetWindowForTargetResponse response = chromeDevTools.send(Browser.getWindowForTarget(Optional.empty()));
    WindowID windowId = response.getWindowId();
    Bounds bounds = response.getBounds();
    System.err.println(String.format("Method Browser.getWindowForTarget result: windowId: %d" + "\nBounds: top: %d, left: %d, width: %d, height: %d", Long.parseLong(windowId.toString()), bounds.getLeft().get(), bounds.getTop().get(), bounds.getWidth().get(), bounds.getHeight().get()));
    @SuppressWarnings("unused") Optional<WindowID> windowIdArg = Optional.of(windowId);
    try {
        bounds = chromeDevTools.send(Browser.getWindowBounds(windowId));
        chromeDevTools.createSessionIfThereIsNotOne();
        @SuppressWarnings("unused") SessionID id = chromeDevTools.getCdpSession();
    } catch (TimeoutException e) {
        System.err.println("Exception (ignored): " + e.toString());
        bounds = null;
    }
    // https://github.com/SeleniumHQ/selenium/issues/7369
    chromeDevTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
    // https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/devtools/DevTools.java
    // https://github.com/SeleniumHQ/selenium/blob/master/java/client/test/org/openqa/selenium/devtools/ChromeDevToolsNetworkTest.java
    // but Browser has no events, Network has
    chromeDevTools.addListener(Network.dataReceived(), o -> {
        Assert.assertNotNull(o.getRequestId());
        // TODO: Command<GetResponseBodyResponse> - get something practical
        System.err.println("Response body: " + Network.getResponseBody(o.getRequestId()).getMethod());
    });
    driver.get("https://apache.org");
    if (bounds != null) {
        System.err.print(String.format("Method Browser.getWindowBounds(%d): ", Long.parseLong(windowId.toString())));
        if (bounds.getTop().isPresent()) {
            System.err.println(String.format("top: %d, left: %d, width: %d, height: %d", bounds.getTop().get(), bounds.getLeft().get(), bounds.getWidth().get(), bounds.getHeight().get()));
        } else {
            System.err.println("undefined");
        }
    } else {
        System.err.println("Method Browser.getWindowBounds failed");
    }
}
Also used : WindowID(org.openqa.selenium.devtools.v100.browser.model.WindowID) Bounds(org.openqa.selenium.devtools.v100.browser.model.Bounds) GetWindowForTargetResponse(org.openqa.selenium.devtools.v100.browser.Browser.GetWindowForTargetResponse) SessionID(org.openqa.selenium.devtools.idealized.target.model.SessionID) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 GetWindowForTargetResponse (org.openqa.selenium.devtools.v100.browser.Browser.GetWindowForTargetResponse)2 TimeoutException (org.openqa.selenium.TimeoutException)1 DevToolsException (org.openqa.selenium.devtools.DevToolsException)1 SessionID (org.openqa.selenium.devtools.idealized.target.model.SessionID)1 Bounds (org.openqa.selenium.devtools.v100.browser.model.Bounds)1 WindowID (org.openqa.selenium.devtools.v100.browser.model.WindowID)1