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

org.openqa.selenium.devtools.v85.browser.Browser 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.26.0
Show newest version
package org.openqa.selenium.devtools.v85.browser;

import org.openqa.selenium.Beta;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.ConverterFunctions;
import java.util.Map;
import java.util.LinkedHashMap;
import org.openqa.selenium.json.JsonInput;

/**
 * The Browser domain defines methods and events for browser managing.
 */
public class Browser {

    /**
     * Set permission settings for given origin.
     */
    @Beta()
    public static Command setPermission(org.openqa.selenium.devtools.v85.browser.model.PermissionDescriptor permission, org.openqa.selenium.devtools.v85.browser.model.PermissionSetting setting, java.util.Optional origin, java.util.Optional browserContextId) {
        java.util.Objects.requireNonNull(permission, "permission is required");
        java.util.Objects.requireNonNull(setting, "setting is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("permission", permission);
        params.put("setting", setting);
        origin.ifPresent(p -> params.put("origin", p));
        browserContextId.ifPresent(p -> params.put("browserContextId", p));
        return new Command<>("Browser.setPermission", Map.copyOf(params));
    }

    /**
     * Grant specific permissions to the given origin and reject all others.
     */
    @Beta()
    public static Command grantPermissions(java.util.List permissions, java.util.Optional origin, java.util.Optional browserContextId) {
        java.util.Objects.requireNonNull(permissions, "permissions is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("permissions", permissions);
        origin.ifPresent(p -> params.put("origin", p));
        browserContextId.ifPresent(p -> params.put("browserContextId", p));
        return new Command<>("Browser.grantPermissions", Map.copyOf(params));
    }

    /**
     * Reset all permission management for all origins.
     */
    @Beta()
    public static Command resetPermissions(java.util.Optional browserContextId) {
        LinkedHashMap params = new LinkedHashMap<>();
        browserContextId.ifPresent(p -> params.put("browserContextId", p));
        return new Command<>("Browser.resetPermissions", Map.copyOf(params));
    }

    public enum SetDownloadBehaviorBehavior {

        DENY("deny"), ALLOW("allow"), ALLOWANDNAME("allowAndName"), DEFAULT("default");

        private String value;

        SetDownloadBehaviorBehavior(String value) {
            this.value = value;
        }

        public static SetDownloadBehaviorBehavior fromString(String s) {
            return java.util.Arrays.stream(SetDownloadBehaviorBehavior.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within SetDownloadBehaviorBehavior "));
        }

        public String toString() {
            return value;
        }

        public String toJson() {
            return value;
        }

        private static SetDownloadBehaviorBehavior fromJson(JsonInput input) {
            return fromString(input.nextString());
        }
    }

    /**
     * Set the behavior when downloading a file.
     */
    @Beta()
    public static Command setDownloadBehavior(SetDownloadBehaviorBehavior behavior, java.util.Optional browserContextId, java.util.Optional downloadPath) {
        java.util.Objects.requireNonNull(behavior, "behavior is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("behavior", behavior);
        browserContextId.ifPresent(p -> params.put("browserContextId", p));
        downloadPath.ifPresent(p -> params.put("downloadPath", p));
        return new Command<>("Browser.setDownloadBehavior", Map.copyOf(params));
    }

    /**
     * Close browser gracefully.
     */
    public static Command close() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Browser.close", Map.copyOf(params));
    }

    /**
     * Crashes browser on the main thread.
     */
    @Beta()
    public static Command crash() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Browser.crash", Map.copyOf(params));
    }

    /**
     * Crashes GPU process.
     */
    @Beta()
    public static Command crashGpuProcess() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Browser.crashGpuProcess", Map.copyOf(params));
    }

    public static class GetVersionResponse {

        private final java.lang.String protocolVersion;

        private final java.lang.String product;

        private final java.lang.String revision;

        private final java.lang.String userAgent;

        private final java.lang.String jsVersion;

        public GetVersionResponse(java.lang.String protocolVersion, java.lang.String product, java.lang.String revision, java.lang.String userAgent, java.lang.String jsVersion) {
            this.protocolVersion = java.util.Objects.requireNonNull(protocolVersion, "protocolVersion is required");
            this.product = java.util.Objects.requireNonNull(product, "product is required");
            this.revision = java.util.Objects.requireNonNull(revision, "revision is required");
            this.userAgent = java.util.Objects.requireNonNull(userAgent, "userAgent is required");
            this.jsVersion = java.util.Objects.requireNonNull(jsVersion, "jsVersion is required");
        }

        /**
         * Protocol version.
         */
        public java.lang.String getProtocolVersion() {
            return protocolVersion;
        }

        /**
         * Product name.
         */
        public java.lang.String getProduct() {
            return product;
        }

        /**
         * Product revision.
         */
        public java.lang.String getRevision() {
            return revision;
        }

        /**
         * User-Agent.
         */
        public java.lang.String getUserAgent() {
            return userAgent;
        }

        /**
         * V8 version.
         */
        public java.lang.String getJsVersion() {
            return jsVersion;
        }

        private static GetVersionResponse fromJson(JsonInput input) {
            java.lang.String protocolVersion = null;
            java.lang.String product = null;
            java.lang.String revision = null;
            java.lang.String userAgent = null;
            java.lang.String jsVersion = null;
            input.beginObject();
            while (input.hasNext()) {
                switch(input.nextName()) {
                    case "protocolVersion":
                        protocolVersion = input.nextString();
                        break;
                    case "product":
                        product = input.nextString();
                        break;
                    case "revision":
                        revision = input.nextString();
                        break;
                    case "userAgent":
                        userAgent = input.nextString();
                        break;
                    case "jsVersion":
                        jsVersion = input.nextString();
                        break;
                    default:
                        input.skipValue();
                        break;
                }
            }
            input.endObject();
            return new GetVersionResponse(protocolVersion, product, revision, userAgent, jsVersion);
        }
    }

    /**
     * Returns version information.
     */
    public static Command getVersion() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Browser.getVersion", Map.copyOf(params), input -> input.read(org.openqa.selenium.devtools.v85.browser.Browser.GetVersionResponse.class));
    }

    /**
     * Returns the command line switches for the browser process if, and only if
     * --enable-automation is on the commandline.
     */
    @Beta()
    public static Command> getBrowserCommandLine() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Browser.getBrowserCommandLine", Map.copyOf(params), ConverterFunctions.map("arguments", input -> input.readArray(java.lang.String.class)));
    }

    /**
     * Get Chrome histograms.
     */
    @Beta()
    public static Command> getHistograms(java.util.Optional query, java.util.Optional delta) {
        LinkedHashMap params = new LinkedHashMap<>();
        query.ifPresent(p -> params.put("query", p));
        delta.ifPresent(p -> params.put("delta", p));
        return new Command<>("Browser.getHistograms", Map.copyOf(params), ConverterFunctions.map("histograms", input -> input.readArray(org.openqa.selenium.devtools.v85.browser.model.Histogram.class)));
    }

    /**
     * Get a Chrome histogram by name.
     */
    @Beta()
    public static Command getHistogram(java.lang.String name, java.util.Optional delta) {
        java.util.Objects.requireNonNull(name, "name is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("name", name);
        delta.ifPresent(p -> params.put("delta", p));
        return new Command<>("Browser.getHistogram", Map.copyOf(params), ConverterFunctions.map("histogram", org.openqa.selenium.devtools.v85.browser.model.Histogram.class));
    }

    /**
     * Get position and size of the browser window.
     */
    @Beta()
    public static Command getWindowBounds(org.openqa.selenium.devtools.v85.browser.model.WindowID windowId) {
        java.util.Objects.requireNonNull(windowId, "windowId is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("windowId", windowId);
        return new Command<>("Browser.getWindowBounds", Map.copyOf(params), ConverterFunctions.map("bounds", org.openqa.selenium.devtools.v85.browser.model.Bounds.class));
    }

    public static class GetWindowForTargetResponse {

        private final org.openqa.selenium.devtools.v85.browser.model.WindowID windowId;

        private final org.openqa.selenium.devtools.v85.browser.model.Bounds bounds;

        public GetWindowForTargetResponse(org.openqa.selenium.devtools.v85.browser.model.WindowID windowId, org.openqa.selenium.devtools.v85.browser.model.Bounds bounds) {
            this.windowId = java.util.Objects.requireNonNull(windowId, "windowId is required");
            this.bounds = java.util.Objects.requireNonNull(bounds, "bounds is required");
        }

        /**
         * Browser window id.
         */
        public org.openqa.selenium.devtools.v85.browser.model.WindowID getWindowId() {
            return windowId;
        }

        /**
         * Bounds information of the window. When window state is 'minimized', the restored window
         * position and size are returned.
         */
        public org.openqa.selenium.devtools.v85.browser.model.Bounds getBounds() {
            return bounds;
        }

        private static GetWindowForTargetResponse fromJson(JsonInput input) {
            org.openqa.selenium.devtools.v85.browser.model.WindowID windowId = null;
            org.openqa.selenium.devtools.v85.browser.model.Bounds bounds = null;
            input.beginObject();
            while (input.hasNext()) {
                switch(input.nextName()) {
                    case "windowId":
                        windowId = input.read(org.openqa.selenium.devtools.v85.browser.model.WindowID.class);
                        break;
                    case "bounds":
                        bounds = input.read(org.openqa.selenium.devtools.v85.browser.model.Bounds.class);
                        break;
                    default:
                        input.skipValue();
                        break;
                }
            }
            input.endObject();
            return new GetWindowForTargetResponse(windowId, bounds);
        }
    }

    /**
     * Get the browser window that contains the devtools target.
     */
    @Beta()
    public static Command getWindowForTarget(java.util.Optional targetId) {
        LinkedHashMap params = new LinkedHashMap<>();
        targetId.ifPresent(p -> params.put("targetId", p));
        return new Command<>("Browser.getWindowForTarget", Map.copyOf(params), input -> input.read(org.openqa.selenium.devtools.v85.browser.Browser.GetWindowForTargetResponse.class));
    }

    /**
     * Set position and/or size of the browser window.
     */
    @Beta()
    public static Command setWindowBounds(org.openqa.selenium.devtools.v85.browser.model.WindowID windowId, org.openqa.selenium.devtools.v85.browser.model.Bounds bounds) {
        java.util.Objects.requireNonNull(windowId, "windowId is required");
        java.util.Objects.requireNonNull(bounds, "bounds is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("windowId", windowId);
        params.put("bounds", bounds);
        return new Command<>("Browser.setWindowBounds", Map.copyOf(params));
    }

    /**
     * Set dock tile details, platform-specific.
     */
    @Beta()
    public static Command setDockTile(java.util.Optional badgeLabel, java.util.Optional image) {
        LinkedHashMap params = new LinkedHashMap<>();
        badgeLabel.ifPresent(p -> params.put("badgeLabel", p));
        image.ifPresent(p -> params.put("image", p));
        return new Command<>("Browser.setDockTile", Map.copyOf(params));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy