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

org.openqa.selenium.devtools.v85.emulation.Emulation 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.emulation;

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;

/**
 * This domain emulates different environments for the page.
 */
public class Emulation {

    /**
     * Tells whether emulation is supported.
     */
    public static Command canEmulate() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Emulation.canEmulate", Map.copyOf(params), ConverterFunctions.map("result", java.lang.Boolean.class));
    }

    /**
     * Clears the overridden device metrics.
     */
    public static Command clearDeviceMetricsOverride() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Emulation.clearDeviceMetricsOverride", Map.copyOf(params));
    }

    /**
     * Clears the overridden Geolocation Position and Error.
     */
    public static Command clearGeolocationOverride() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Emulation.clearGeolocationOverride", Map.copyOf(params));
    }

    /**
     * Requests that page scale factor is reset to initial values.
     */
    @Beta()
    public static Command resetPageScaleFactor() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Emulation.resetPageScaleFactor", Map.copyOf(params));
    }

    /**
     * Enables or disables simulating a focused and active page.
     */
    @Beta()
    public static Command setFocusEmulationEnabled(java.lang.Boolean enabled) {
        java.util.Objects.requireNonNull(enabled, "enabled is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("enabled", enabled);
        return new Command<>("Emulation.setFocusEmulationEnabled", Map.copyOf(params));
    }

    /**
     * Enables CPU throttling to emulate slow CPUs.
     */
    @Beta()
    public static Command setCPUThrottlingRate(java.lang.Number rate) {
        java.util.Objects.requireNonNull(rate, "rate is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("rate", rate);
        return new Command<>("Emulation.setCPUThrottlingRate", Map.copyOf(params));
    }

    /**
     * Sets or clears an override of the default background color of the frame. This override is used
     * if the content does not specify one.
     */
    public static Command setDefaultBackgroundColorOverride(java.util.Optional color) {
        LinkedHashMap params = new LinkedHashMap<>();
        color.ifPresent(p -> params.put("color", p));
        return new Command<>("Emulation.setDefaultBackgroundColorOverride", Map.copyOf(params));
    }

    /**
     * Overrides the values of device screen dimensions (window.screen.width, window.screen.height,
     * window.innerWidth, window.innerHeight, and "device-width"/"device-height"-related CSS media
     * query results).
     */
    public static Command setDeviceMetricsOverride(java.lang.Integer width, java.lang.Integer height, java.lang.Number deviceScaleFactor, java.lang.Boolean mobile, java.util.Optional scale, java.util.Optional screenWidth, java.util.Optional screenHeight, java.util.Optional positionX, java.util.Optional positionY, java.util.Optional dontSetVisibleSize, java.util.Optional screenOrientation, java.util.Optional viewport) {
        java.util.Objects.requireNonNull(width, "width is required");
        java.util.Objects.requireNonNull(height, "height is required");
        java.util.Objects.requireNonNull(deviceScaleFactor, "deviceScaleFactor is required");
        java.util.Objects.requireNonNull(mobile, "mobile is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("width", width);
        params.put("height", height);
        params.put("deviceScaleFactor", deviceScaleFactor);
        params.put("mobile", mobile);
        scale.ifPresent(p -> params.put("scale", p));
        screenWidth.ifPresent(p -> params.put("screenWidth", p));
        screenHeight.ifPresent(p -> params.put("screenHeight", p));
        positionX.ifPresent(p -> params.put("positionX", p));
        positionY.ifPresent(p -> params.put("positionY", p));
        dontSetVisibleSize.ifPresent(p -> params.put("dontSetVisibleSize", p));
        screenOrientation.ifPresent(p -> params.put("screenOrientation", p));
        viewport.ifPresent(p -> params.put("viewport", p));
        return new Command<>("Emulation.setDeviceMetricsOverride", Map.copyOf(params));
    }

    @Beta()
    public static Command setScrollbarsHidden(java.lang.Boolean hidden) {
        java.util.Objects.requireNonNull(hidden, "hidden is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("hidden", hidden);
        return new Command<>("Emulation.setScrollbarsHidden", Map.copyOf(params));
    }

    @Beta()
    public static Command setDocumentCookieDisabled(java.lang.Boolean disabled) {
        java.util.Objects.requireNonNull(disabled, "disabled is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("disabled", disabled);
        return new Command<>("Emulation.setDocumentCookieDisabled", Map.copyOf(params));
    }

    public enum SetEmitTouchEventsForMouseConfiguration {

        MOBILE("mobile"), DESKTOP("desktop");

        private String value;

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

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

        public String toString() {
            return value;
        }

        public String toJson() {
            return value;
        }

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

    @Beta()
    public static Command setEmitTouchEventsForMouse(java.lang.Boolean enabled, java.util.Optional configuration) {
        java.util.Objects.requireNonNull(enabled, "enabled is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("enabled", enabled);
        configuration.ifPresent(p -> params.put("configuration", p));
        return new Command<>("Emulation.setEmitTouchEventsForMouse", Map.copyOf(params));
    }

    /**
     * Emulates the given media type or media feature for CSS media queries.
     */
    public static Command setEmulatedMedia(java.util.Optional media, java.util.Optional> features) {
        LinkedHashMap params = new LinkedHashMap<>();
        media.ifPresent(p -> params.put("media", p));
        features.ifPresent(p -> params.put("features", p));
        return new Command<>("Emulation.setEmulatedMedia", Map.copyOf(params));
    }

    public enum SetEmulatedVisionDeficiencyType {

        NONE("none"),
        ACHROMATOPSIA("achromatopsia"),
        BLURREDVISION("blurredVision"),
        DEUTERANOPIA("deuteranopia"),
        PROTANOPIA("protanopia"),
        TRITANOPIA("tritanopia");

        private String value;

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

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

        public String toString() {
            return value;
        }

        public String toJson() {
            return value;
        }

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

    /**
     * Emulates the given vision deficiency.
     */
    @Beta()
    public static Command setEmulatedVisionDeficiency(SetEmulatedVisionDeficiencyType type) {
        java.util.Objects.requireNonNull(type, "type is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("type", type);
        return new Command<>("Emulation.setEmulatedVisionDeficiency", Map.copyOf(params));
    }

    /**
     * Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position
     * unavailable.
     */
    public static Command setGeolocationOverride(java.util.Optional latitude, java.util.Optional longitude, java.util.Optional accuracy) {
        LinkedHashMap params = new LinkedHashMap<>();
        latitude.ifPresent(p -> params.put("latitude", p));
        longitude.ifPresent(p -> params.put("longitude", p));
        accuracy.ifPresent(p -> params.put("accuracy", p));
        return new Command<>("Emulation.setGeolocationOverride", Map.copyOf(params));
    }

    /**
     * Overrides value returned by the javascript navigator object.
     */
    @Beta()
    @Deprecated()
    public static Command setNavigatorOverrides(java.lang.String platform) {
        java.util.Objects.requireNonNull(platform, "platform is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("platform", platform);
        return new Command<>("Emulation.setNavigatorOverrides", Map.copyOf(params));
    }

    /**
     * Sets a specified page scale factor.
     */
    @Beta()
    public static Command setPageScaleFactor(java.lang.Number pageScaleFactor) {
        java.util.Objects.requireNonNull(pageScaleFactor, "pageScaleFactor is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("pageScaleFactor", pageScaleFactor);
        return new Command<>("Emulation.setPageScaleFactor", Map.copyOf(params));
    }

    /**
     * Switches script execution in the page.
     */
    public static Command setScriptExecutionDisabled(java.lang.Boolean value) {
        java.util.Objects.requireNonNull(value, "value is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("value", value);
        return new Command<>("Emulation.setScriptExecutionDisabled", Map.copyOf(params));
    }

    /**
     * Enables touch on platforms which do not support them.
     */
    public static Command setTouchEmulationEnabled(java.lang.Boolean enabled, java.util.Optional maxTouchPoints) {
        java.util.Objects.requireNonNull(enabled, "enabled is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("enabled", enabled);
        maxTouchPoints.ifPresent(p -> params.put("maxTouchPoints", p));
        return new Command<>("Emulation.setTouchEmulationEnabled", Map.copyOf(params));
    }

    /**
     * Turns on virtual time for all frames (replacing real-time with a synthetic time source) and sets
     * the current virtual time policy.  Note this supersedes any previous time budget.
     */
    @Beta()
    public static Command setVirtualTimePolicy(org.openqa.selenium.devtools.v85.emulation.model.VirtualTimePolicy policy, java.util.Optional budget, java.util.Optional maxVirtualTimeTaskStarvationCount, java.util.Optional waitForNavigation, java.util.Optional initialVirtualTime) {
        java.util.Objects.requireNonNull(policy, "policy is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("policy", policy);
        budget.ifPresent(p -> params.put("budget", p));
        maxVirtualTimeTaskStarvationCount.ifPresent(p -> params.put("maxVirtualTimeTaskStarvationCount", p));
        waitForNavigation.ifPresent(p -> params.put("waitForNavigation", p));
        initialVirtualTime.ifPresent(p -> params.put("initialVirtualTime", p));
        return new Command<>("Emulation.setVirtualTimePolicy", Map.copyOf(params), ConverterFunctions.map("virtualTimeTicksBase", java.lang.Number.class));
    }

    /**
     * Overrides default host system locale with the specified one.
     */
    @Beta()
    public static Command setLocaleOverride(java.util.Optional locale) {
        LinkedHashMap params = new LinkedHashMap<>();
        locale.ifPresent(p -> params.put("locale", p));
        return new Command<>("Emulation.setLocaleOverride", Map.copyOf(params));
    }

    /**
     * Overrides default host system timezone with the specified one.
     */
    @Beta()
    public static Command setTimezoneOverride(java.lang.String timezoneId) {
        java.util.Objects.requireNonNull(timezoneId, "timezoneId is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("timezoneId", timezoneId);
        return new Command<>("Emulation.setTimezoneOverride", Map.copyOf(params));
    }

    /**
     * Resizes the frame/viewport of the page. Note that this does not affect the frame's container
     * (e.g. browser window). Can be used to produce screenshots of the specified size. Not supported
     * on Android.
     */
    @Beta()
    @Deprecated()
    public static Command setVisibleSize(java.lang.Integer width, java.lang.Integer height) {
        java.util.Objects.requireNonNull(width, "width is required");
        java.util.Objects.requireNonNull(height, "height is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("width", width);
        params.put("height", height);
        return new Command<>("Emulation.setVisibleSize", Map.copyOf(params));
    }

    /**
     * Allows overriding user agent with the given string.
     */
    public static Command setUserAgentOverride(java.lang.String userAgent, java.util.Optional acceptLanguage, java.util.Optional platform, java.util.Optional userAgentMetadata) {
        java.util.Objects.requireNonNull(userAgent, "userAgent is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("userAgent", userAgent);
        acceptLanguage.ifPresent(p -> params.put("acceptLanguage", p));
        platform.ifPresent(p -> params.put("platform", p));
        userAgentMetadata.ifPresent(p -> params.put("userAgentMetadata", p));
        return new Command<>("Emulation.setUserAgentOverride", Map.copyOf(params));
    }

    public static Event virtualTimeBudgetExpired() {
        return new Event<>("Emulation.virtualTimeBudgetExpired", ConverterFunctions.empty());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy