diff --git a/playwright/src/main/java/com/microsoft/playwright/Coverage.java b/playwright/src/main/java/com/microsoft/playwright/Coverage.java new file mode 100644 index 000000000..2803eb9e5 --- /dev/null +++ b/playwright/src/main/java/com/microsoft/playwright/Coverage.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.playwright; + +import java.util.List; + +/** + * Coverage gathers information about parts of JavaScript and CSS that were used by the page. + * + *

Coverage APIs are only supported on Chromium-based browsers. + */ +public interface Coverage { + class StartJSCoverageOptions { + /** + * Whether anonymous scripts generated by the page should be reported. Defaults to {@code false}. + */ + public Boolean reportAnonymousScripts; + /** + * Whether to reset coverage on every navigation. Defaults to {@code true}. + */ + public Boolean resetOnNavigation; + + public StartJSCoverageOptions setReportAnonymousScripts(boolean reportAnonymousScripts) { + this.reportAnonymousScripts = reportAnonymousScripts; + return this; + } + + public StartJSCoverageOptions setResetOnNavigation(boolean resetOnNavigation) { + this.resetOnNavigation = resetOnNavigation; + return this; + } + } + + class StartCSSCoverageOptions { + /** + * Whether to reset coverage on every navigation. Defaults to {@code true}. + */ + public Boolean resetOnNavigation; + + public StartCSSCoverageOptions setResetOnNavigation(boolean resetOnNavigation) { + this.resetOnNavigation = resetOnNavigation; + return this; + } + } + + class ScriptCoverage { + /** Script URL. */ + public String url; + /** Script ID. */ + public String scriptId; + /** Script content, if applicable. */ + public String source; + /** V8-specific function coverage. */ + public List functions; + } + + class FunctionCoverage { + public String functionName; + public boolean isBlockCoverage; + public List ranges; + } + + class FunctionCoverageRange { + public int startOffset; + public int endOffset; + public int count; + } + + class StyleSheetCoverage { + /** StyleSheet URL. */ + public String url; + /** StyleSheet content, if available. */ + public String text; + /** StyleSheet ranges that were used, sorted and non-overlapping. */ + public List ranges; + } + + class StyleSheetCoverageRange { + public int start; + public int end; + } + + /** + * Starts JavaScript coverage with default options. + */ + default void startJSCoverage() { + startJSCoverage(null); + } + + /** + * Starts JavaScript coverage. + * + *

Anonymous scripts do not have an associated URL and are created dynamically using {@code eval} or {@code new + * Function}. When {@link StartJSCoverageOptions#setReportAnonymousScripts(boolean)} is enabled, anonymous scripts are + * reported with an empty URL. + */ + void startJSCoverage(StartJSCoverageOptions options); + + /** + * Stops JavaScript coverage and returns reports for all scripts. + */ + List stopJSCoverage(); + + /** + * Starts CSS coverage with default options. + */ + default void startCSSCoverage() { + startCSSCoverage(null); + } + + /** + * Starts CSS coverage. + */ + void startCSSCoverage(StartCSSCoverageOptions options); + + /** + * Stops CSS coverage and returns reports for all stylesheets. + * + *

CSS coverage does not include dynamically injected style tags without source URLs. + */ + List stopCSSCoverage(); +} diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java index db240171f..05c6a741c 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Page.java +++ b/playwright/src/main/java/com/microsoft/playwright/Page.java @@ -3874,6 +3874,12 @@ public WaitForWorkerOptions setTimeout(double timeout) { * @since v1.45 */ Clock clock(); + /** + * Browser-specific coverage implementation. + * + *

Coverage APIs are only supported on Chromium-based browsers. + */ + Coverage coverage(); /** * Adds a script which would be evaluated in one of the following scenarios: *