All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openqa.selenium.devtools.overlay.Overlay Maven / Gradle / Ivy

Go to download

Selenium automates browsers. That's it! What you do with that power is entirely up to you.

There is a newer version: 4.0.0-rc-1
Show newest version
package org.openqa.selenium.devtools.overlay;

import org.openqa.selenium.Beta;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.ConverterFunctions;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.json.JsonInput;

/**
 * This domain provides various functionality related to drawing atop the inspected page.
 */
@Beta()
public class Overlay {

    /**
     * Disables domain notifications.
     */
    public static Command disable() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Overlay.disable", params.build());
    }

    /**
     * Enables domain notifications.
     */
    public static Command enable() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Overlay.enable", params.build());
    }

    /**
     * For testing.
     */
    public static Command> getHighlightObjectForTest(org.openqa.selenium.devtools.dom.model.NodeId nodeId, java.util.Optional includeDistance, java.util.Optional includeStyle, java.util.Optional colorFormat) {
        java.util.Objects.requireNonNull(nodeId, "nodeId is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("nodeId", nodeId);
        includeDistance.ifPresent(p -> params.put("includeDistance", p));
        includeStyle.ifPresent(p -> params.put("includeStyle", p));
        colorFormat.ifPresent(p -> params.put("colorFormat", p));
        return new Command<>("Overlay.getHighlightObjectForTest", params.build(), ConverterFunctions.map("highlight", new com.google.common.reflect.TypeToken>() {
        }.getType()));
    }

    /**
     * Hides any highlight.
     */
    public static Command hideHighlight() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Overlay.hideHighlight", params.build());
    }

    /**
     * Highlights owner element of the frame with given id.
     */
    public static Command highlightFrame(org.openqa.selenium.devtools.page.model.FrameId frameId, java.util.Optional contentColor, java.util.Optional contentOutlineColor) {
        java.util.Objects.requireNonNull(frameId, "frameId is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("frameId", frameId);
        contentColor.ifPresent(p -> params.put("contentColor", p));
        contentOutlineColor.ifPresent(p -> params.put("contentOutlineColor", p));
        return new Command<>("Overlay.highlightFrame", params.build());
    }

    /**
     * Highlights DOM node with given id or with the given JavaScript object wrapper. Either nodeId or
     * objectId must be specified.
     */
    public static Command highlightNode(org.openqa.selenium.devtools.overlay.model.HighlightConfig highlightConfig, java.util.Optional nodeId, java.util.Optional backendNodeId, java.util.Optional objectId, java.util.Optional selector) {
        java.util.Objects.requireNonNull(highlightConfig, "highlightConfig is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("highlightConfig", highlightConfig);
        nodeId.ifPresent(p -> params.put("nodeId", p));
        backendNodeId.ifPresent(p -> params.put("backendNodeId", p));
        objectId.ifPresent(p -> params.put("objectId", p));
        selector.ifPresent(p -> params.put("selector", p));
        return new Command<>("Overlay.highlightNode", params.build());
    }

    /**
     * Highlights given quad. Coordinates are absolute with respect to the main frame viewport.
     */
    public static Command highlightQuad(org.openqa.selenium.devtools.dom.model.Quad quad, java.util.Optional color, java.util.Optional outlineColor) {
        java.util.Objects.requireNonNull(quad, "quad is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("quad", quad);
        color.ifPresent(p -> params.put("color", p));
        outlineColor.ifPresent(p -> params.put("outlineColor", p));
        return new Command<>("Overlay.highlightQuad", params.build());
    }

    /**
     * Highlights given rectangle. Coordinates are absolute with respect to the main frame viewport.
     */
    public static Command highlightRect(java.lang.Integer x, java.lang.Integer y, java.lang.Integer width, java.lang.Integer height, java.util.Optional color, java.util.Optional outlineColor) {
        java.util.Objects.requireNonNull(x, "x is required");
        java.util.Objects.requireNonNull(y, "y is required");
        java.util.Objects.requireNonNull(width, "width is required");
        java.util.Objects.requireNonNull(height, "height is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("x", x);
        params.put("y", y);
        params.put("width", width);
        params.put("height", height);
        color.ifPresent(p -> params.put("color", p));
        outlineColor.ifPresent(p -> params.put("outlineColor", p));
        return new Command<>("Overlay.highlightRect", params.build());
    }

    /**
     * Enters the 'inspect' mode. In this mode, elements that user is hovering over are highlighted.
     * Backend then generates 'inspectNodeRequested' event upon element selection.
     */
    public static Command setInspectMode(org.openqa.selenium.devtools.overlay.model.InspectMode mode, java.util.Optional highlightConfig) {
        java.util.Objects.requireNonNull(mode, "mode is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("mode", mode);
        highlightConfig.ifPresent(p -> params.put("highlightConfig", p));
        return new Command<>("Overlay.setInspectMode", params.build());
    }

    /**
     * Highlights owner element of all frames detected to be ads.
     */
    public static Command setShowAdHighlights(java.lang.Boolean show) {
        java.util.Objects.requireNonNull(show, "show is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("show", show);
        return new Command<>("Overlay.setShowAdHighlights", params.build());
    }

    public static Command setPausedInDebuggerMessage(java.util.Optional message) {
        ImmutableMap.Builder params = ImmutableMap.builder();
        message.ifPresent(p -> params.put("message", p));
        return new Command<>("Overlay.setPausedInDebuggerMessage", params.build());
    }

    /**
     * Requests that backend shows debug borders on layers
     */
    public static Command setShowDebugBorders(java.lang.Boolean show) {
        java.util.Objects.requireNonNull(show, "show is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("show", show);
        return new Command<>("Overlay.setShowDebugBorders", params.build());
    }

    /**
     * Requests that backend shows the FPS counter
     */
    public static Command setShowFPSCounter(java.lang.Boolean show) {
        java.util.Objects.requireNonNull(show, "show is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("show", show);
        return new Command<>("Overlay.setShowFPSCounter", params.build());
    }

    /**
     * Requests that backend shows paint rectangles
     */
    public static Command setShowPaintRects(java.lang.Boolean result) {
        java.util.Objects.requireNonNull(result, "result is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("result", result);
        return new Command<>("Overlay.setShowPaintRects", params.build());
    }

    /**
     * Requests that backend shows layout shift regions
     */
    public static Command setShowLayoutShiftRegions(java.lang.Boolean result) {
        java.util.Objects.requireNonNull(result, "result is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("result", result);
        return new Command<>("Overlay.setShowLayoutShiftRegions", params.build());
    }

    /**
     * Requests that backend shows scroll bottleneck rects
     */
    public static Command setShowScrollBottleneckRects(java.lang.Boolean show) {
        java.util.Objects.requireNonNull(show, "show is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("show", show);
        return new Command<>("Overlay.setShowScrollBottleneckRects", params.build());
    }

    /**
     * Requests that backend shows hit-test borders on layers
     */
    public static Command setShowHitTestBorders(java.lang.Boolean show) {
        java.util.Objects.requireNonNull(show, "show is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("show", show);
        return new Command<>("Overlay.setShowHitTestBorders", params.build());
    }

    /**
     * Paints viewport size upon main frame resize.
     */
    public static Command setShowViewportSizeOnResize(java.lang.Boolean show) {
        java.util.Objects.requireNonNull(show, "show is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("show", show);
        return new Command<>("Overlay.setShowViewportSizeOnResize", params.build());
    }

    /**
     * Add a dual screen device hinge
     */
    public static Command setShowHinge(java.util.Optional hingeConfig) {
        ImmutableMap.Builder params = ImmutableMap.builder();
        hingeConfig.ifPresent(p -> params.put("hingeConfig", p));
        return new Command<>("Overlay.setShowHinge", params.build());
    }

    public static Event inspectNodeRequested() {
        return new Event<>("Overlay.inspectNodeRequested", ConverterFunctions.map("backendNodeId", org.openqa.selenium.devtools.dom.model.BackendNodeId.class));
    }

    public static Event nodeHighlightRequested() {
        return new Event<>("Overlay.nodeHighlightRequested", ConverterFunctions.map("nodeId", org.openqa.selenium.devtools.dom.model.NodeId.class));
    }

    public static Event screenshotRequested() {
        return new Event<>("Overlay.screenshotRequested", ConverterFunctions.map("viewport", org.openqa.selenium.devtools.page.model.Viewport.class));
    }

    public static Event inspectModeCanceled() {
        return new Event<>("Overlay.inspectModeCanceled", input -> null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy