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

org.openqa.selenium.devtools.v90.performance.Performance 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-beta-4
Show newest version
package org.openqa.selenium.devtools.v90.performance;

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;

public class Performance {

    /**
     * Disable collecting and reporting metrics.
     */
    public static Command disable() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Performance.disable", params.build());
    }

    public enum EnableTimeDomain {

        TIMETICKS("timeTicks"), THREADTICKS("threadTicks");

        private String value;

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

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

        public String toString() {
            return value;
        }

        public String toJson() {
            return value;
        }

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

    /**
     * Enable collecting and reporting metrics.
     */
    public static Command enable(java.util.Optional timeDomain) {
        ImmutableMap.Builder params = ImmutableMap.builder();
        timeDomain.ifPresent(p -> params.put("timeDomain", p));
        return new Command<>("Performance.enable", params.build());
    }

    public enum SetTimeDomainTimeDomain {

        TIMETICKS("timeTicks"), THREADTICKS("threadTicks");

        private String value;

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

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

        public String toString() {
            return value;
        }

        public String toJson() {
            return value;
        }

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

    /**
     * Sets time domain to use for collecting and reporting duration metrics.
     * Note that this must be called before enabling metrics collection. Calling
     * this method while metrics collection is enabled returns an error.
     */
    @Beta()
    @Deprecated()
    public static Command setTimeDomain(SetTimeDomainTimeDomain timeDomain) {
        java.util.Objects.requireNonNull(timeDomain, "timeDomain is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("timeDomain", timeDomain);
        return new Command<>("Performance.setTimeDomain", params.build());
    }

    /**
     * Retrieve current values of run-time metrics.
     */
    public static Command> getMetrics() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Performance.getMetrics", params.build(), ConverterFunctions.map("metrics", new com.google.common.reflect.TypeToken>() {
        }.getType()));
    }

    public static Event metrics() {
        return new Event<>("Performance.metrics", input -> input.read(org.openqa.selenium.devtools.v90.performance.model.Metrics.class));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy