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()));
}
}
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");
}
}
Aggregations