diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/Options.java b/playwright/src/main/java/com/microsoft/playwright/junit/Options.java index 35eec6f6..330ca532 100644 --- a/playwright/src/main/java/com/microsoft/playwright/junit/Options.java +++ b/playwright/src/main/java/com/microsoft/playwright/junit/Options.java @@ -13,6 +13,7 @@ public class Options { public String deviceName; // Custom attribute to be used in page.getByTestId(). data-testid is used by default. public String testIdAttribute; + public Boolean ignoreHTTPSErrors; public BrowserType.LaunchOptions launchOptions; public Browser.NewContextOptions contextOptions; public APIRequest.NewContextOptions apiRequestOptions; @@ -67,4 +68,9 @@ public Options setHeadless(Boolean headless) { this.headless = headless; return this; } + + public Options setIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) { + this.ignoreHTTPSErrors = ignoreHTTPSErrors; + return this; + } } diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/impl/APIRequestContextExtension.java b/playwright/src/main/java/com/microsoft/playwright/junit/impl/APIRequestContextExtension.java index a4d57d8c..3bd43ccd 100644 --- a/playwright/src/main/java/com/microsoft/playwright/junit/impl/APIRequestContextExtension.java +++ b/playwright/src/main/java/com/microsoft/playwright/junit/impl/APIRequestContextExtension.java @@ -1,7 +1,9 @@ package com.microsoft.playwright.junit.impl; +import com.microsoft.playwright.APIRequest; import com.microsoft.playwright.APIRequestContext; import com.microsoft.playwright.Playwright; +import com.microsoft.playwright.impl.Utils; import com.microsoft.playwright.junit.Options; import org.junit.jupiter.api.extension.*; @@ -38,8 +40,20 @@ static APIRequestContext getOrCreateAPIRequestContext(ExtensionContext extension Options options = OptionsExtension.getOptions(extensionContext); Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext); - apiRequestContext = playwright.request().newContext(options.apiRequestOptions); + apiRequestContext = playwright.request().newContext(getContextOptions(options)); threadLocalAPIRequestContext.set(apiRequestContext); return apiRequestContext; } + + private static APIRequest.NewContextOptions getContextOptions(Options options) { + APIRequest.NewContextOptions contextOptions = Utils.clone(options.apiRequestOptions); + if(contextOptions == null) { + contextOptions = new APIRequest.NewContextOptions(); + } + + if(options.ignoreHTTPSErrors != null) { + contextOptions.ignoreHTTPSErrors = options.ignoreHTTPSErrors; + } + return contextOptions; + } } diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserContextExtension.java b/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserContextExtension.java index bf5e99d3..57b7b21a 100644 --- a/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserContextExtension.java +++ b/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserContextExtension.java @@ -72,6 +72,10 @@ private static Browser.NewContextOptions getContextOptions(Playwright playwright contextOptions.hasTouch = deviceDescriptor.hasTouch; } + if(options.ignoreHTTPSErrors != null) { + contextOptions.setIgnoreHTTPSErrors(options.ignoreHTTPSErrors); + } + return contextOptions; } }