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

org.openqa.selenium.devtools.v85.audits.Audits 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.audits;

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;

/**
 * Audits domain allows investigation of page violations and possible improvements.
 */
@Beta()
public class Audits {

    public static class GetEncodedResponseResponse {

        private final java.util.Optional body;

        private final java.lang.Integer originalSize;

        private final java.lang.Integer encodedSize;

        public GetEncodedResponseResponse(java.util.Optional body, java.lang.Integer originalSize, java.lang.Integer encodedSize) {
            this.body = body;
            this.originalSize = java.util.Objects.requireNonNull(originalSize, "originalSize is required");
            this.encodedSize = java.util.Objects.requireNonNull(encodedSize, "encodedSize is required");
        }

        /**
         * The encoded body as a base64 string. Omitted if sizeOnly is true.
         */
        public java.util.Optional getBody() {
            return body;
        }

        /**
         * Size before re-encoding.
         */
        public java.lang.Integer getOriginalSize() {
            return originalSize;
        }

        /**
         * Size after re-encoding.
         */
        public java.lang.Integer getEncodedSize() {
            return encodedSize;
        }

        private static GetEncodedResponseResponse fromJson(JsonInput input) {
            java.util.Optional body = java.util.Optional.empty();
            java.lang.Integer originalSize = 0;
            java.lang.Integer encodedSize = 0;
            input.beginObject();
            while (input.hasNext()) {
                switch(input.nextName()) {
                    case "body":
                        body = java.util.Optional.ofNullable(input.nextString());
                        break;
                    case "originalSize":
                        originalSize = input.nextNumber().intValue();
                        break;
                    case "encodedSize":
                        encodedSize = input.nextNumber().intValue();
                        break;
                    default:
                        input.skipValue();
                        break;
                }
            }
            input.endObject();
            return new GetEncodedResponseResponse(body, originalSize, encodedSize);
        }
    }

    public enum GetEncodedResponseEncoding {

        WEBP("webp"), JPEG("jpeg"), PNG("png");

        private String value;

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

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

        public String toString() {
            return value;
        }

        public String toJson() {
            return value;
        }

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

    /**
     * Returns the response body and size if it were re-encoded with the specified settings. Only
     * applies to images.
     */
    public static Command getEncodedResponse(org.openqa.selenium.devtools.v85.network.model.RequestId requestId, GetEncodedResponseEncoding encoding, java.util.Optional quality, java.util.Optional sizeOnly) {
        java.util.Objects.requireNonNull(requestId, "requestId is required");
        java.util.Objects.requireNonNull(encoding, "encoding is required");
        LinkedHashMap params = new LinkedHashMap<>();
        params.put("requestId", requestId);
        params.put("encoding", encoding);
        quality.ifPresent(p -> params.put("quality", p));
        sizeOnly.ifPresent(p -> params.put("sizeOnly", p));
        return new Command<>("Audits.getEncodedResponse", Map.copyOf(params), input -> input.read(org.openqa.selenium.devtools.v85.audits.Audits.GetEncodedResponseResponse.class));
    }

    /**
     * Disables issues domain, prevents further issues from being reported to the client.
     */
    public static Command disable() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Audits.disable", Map.copyOf(params));
    }

    /**
     * Enables issues domain, sends the issues collected so far to the client by means of the
     * `issueAdded` event.
     */
    public static Command enable() {
        LinkedHashMap params = new LinkedHashMap<>();
        return new Command<>("Audits.enable", Map.copyOf(params));
    }

    public static Event issueAdded() {
        return new Event<>("Audits.issueAdded", ConverterFunctions.map("issue", org.openqa.selenium.devtools.v85.audits.model.InspectorIssue.class));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy