Skip to content

Commit

Permalink
feat(junit): Added ignoreHttpsErrors option (#1500)
Browse files Browse the repository at this point in the history
Added ignoreHttpsErrors option
  • Loading branch information
uchagani authored Feb 27, 2024
1 parent b9b3552 commit be06d1e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,4 +68,9 @@ public Options setHeadless(Boolean headless) {
this.headless = headless;
return this;
}

public Options setIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -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.*;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit be06d1e

Please sign in to comment.