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

org.openqa.selenium.devtools.v88.domsnapshot.DOMSnapshot Maven / Gradle / Ivy

package org.openqa.selenium.devtools.v88.domsnapshot;

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 facilitates obtaining document snapshots with DOM, layout, and style information.
 */
@Beta()
public class DOMSnapshot {

    /**
     * Disables DOM snapshot agent for the given page.
     */
    public static Command disable() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("DOMSnapshot.disable", params.build());
    }

    /**
     * Enables DOM snapshot agent for the given page.
     */
    public static Command enable() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("DOMSnapshot.enable", params.build());
    }

    public static class GetSnapshotResponse {

        private final java.util.List domNodes;

        private final java.util.List layoutTreeNodes;

        private final java.util.List computedStyles;

        public GetSnapshotResponse(java.util.List domNodes, java.util.List layoutTreeNodes, java.util.List computedStyles) {
            this.domNodes = java.util.Objects.requireNonNull(domNodes, "domNodes is required");
            this.layoutTreeNodes = java.util.Objects.requireNonNull(layoutTreeNodes, "layoutTreeNodes is required");
            this.computedStyles = java.util.Objects.requireNonNull(computedStyles, "computedStyles is required");
        }

        /**
         * The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
         */
        public java.util.List getDomNodes() {
            return domNodes;
        }

        /**
         * The nodes in the layout tree.
         */
        public java.util.List getLayoutTreeNodes() {
            return layoutTreeNodes;
        }

        /**
         * Whitelisted ComputedStyle properties for each node in the layout tree.
         */
        public java.util.List getComputedStyles() {
            return computedStyles;
        }

        private static GetSnapshotResponse fromJson(JsonInput input) {
            java.util.List domNodes = null;
            java.util.List layoutTreeNodes = null;
            java.util.List computedStyles = null;
            input.beginObject();
            while (input.hasNext()) {
                switch(input.nextName()) {
                    case "domNodes":
                        domNodes = input.read(new com.google.common.reflect.TypeToken>() {
                        }.getType());
                        break;
                    case "layoutTreeNodes":
                        layoutTreeNodes = input.read(new com.google.common.reflect.TypeToken>() {
                        }.getType());
                        break;
                    case "computedStyles":
                        computedStyles = input.read(new com.google.common.reflect.TypeToken>() {
                        }.getType());
                        break;
                    default:
                        input.skipValue();
                        break;
                }
            }
            input.endObject();
            return new GetSnapshotResponse(domNodes, layoutTreeNodes, computedStyles);
        }
    }

    /**
     * Returns a document snapshot, including the full DOM tree of the root node (including iframes,
     * template contents, and imported documents) in a flattened array, as well as layout and
     * white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
     * flattened.
     */
    @Deprecated()
    public static Command getSnapshot(java.util.List computedStyleWhitelist, java.util.Optional includeEventListeners, java.util.Optional includePaintOrder, java.util.Optional includeUserAgentShadowTree) {
        java.util.Objects.requireNonNull(computedStyleWhitelist, "computedStyleWhitelist is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("computedStyleWhitelist", computedStyleWhitelist);
        includeEventListeners.ifPresent(p -> params.put("includeEventListeners", p));
        includePaintOrder.ifPresent(p -> params.put("includePaintOrder", p));
        includeUserAgentShadowTree.ifPresent(p -> params.put("includeUserAgentShadowTree", p));
        return new Command<>("DOMSnapshot.getSnapshot", params.build(), input -> input.read(org.openqa.selenium.devtools.v88.domsnapshot.DOMSnapshot.GetSnapshotResponse.class));
    }

    public static class CaptureSnapshotResponse {

        private final java.util.List documents;

        private final java.util.List strings;

        public CaptureSnapshotResponse(java.util.List documents, java.util.List strings) {
            this.documents = java.util.Objects.requireNonNull(documents, "documents is required");
            this.strings = java.util.Objects.requireNonNull(strings, "strings is required");
        }

        /**
         * The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
         */
        public java.util.List getDocuments() {
            return documents;
        }

        /**
         * Shared string table that all string properties refer to with indexes.
         */
        public java.util.List getStrings() {
            return strings;
        }

        private static CaptureSnapshotResponse fromJson(JsonInput input) {
            java.util.List documents = null;
            java.util.List strings = null;
            input.beginObject();
            while (input.hasNext()) {
                switch(input.nextName()) {
                    case "documents":
                        documents = input.read(new com.google.common.reflect.TypeToken>() {
                        }.getType());
                        break;
                    case "strings":
                        strings = input.read(new com.google.common.reflect.TypeToken>() {
                        }.getType());
                        break;
                    default:
                        input.skipValue();
                        break;
                }
            }
            input.endObject();
            return new CaptureSnapshotResponse(documents, strings);
        }
    }

    /**
     * Returns a document snapshot, including the full DOM tree of the root node (including iframes,
     * template contents, and imported documents) in a flattened array, as well as layout and
     * white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
     * flattened.
     */
    public static Command captureSnapshot(java.util.List computedStyles, java.util.Optional includePaintOrder, java.util.Optional includeDOMRects) {
        java.util.Objects.requireNonNull(computedStyles, "computedStyles is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("computedStyles", computedStyles);
        includePaintOrder.ifPresent(p -> params.put("includePaintOrder", p));
        includeDOMRects.ifPresent(p -> params.put("includeDOMRects", p));
        return new Command<>("DOMSnapshot.captureSnapshot", params.build(), input -> input.read(org.openqa.selenium.devtools.v88.domsnapshot.DOMSnapshot.CaptureSnapshotResponse.class));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy