Compare commits
4 Commits
release-1.62
...
v1.41.1
| Author | SHA1 | Date | |
|---|---|---|---|
| fd0c9ca398 | |||
| ae3cfc9e91 | |||
| 8ed802234d | |||
| eefb9b68ff |
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>parent-pom</artifactId>
|
<artifactId>parent-pom</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>driver-bundle</artifactId>
|
<artifactId>driver-bundle</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>parent-pom</artifactId>
|
<artifactId>parent-pom</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>driver</artifactId>
|
<artifactId>driver</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.example</groupId>
|
<groupId>org.example</groupId>
|
||||||
<artifactId>examples</artifactId>
|
<artifactId>examples</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<name>Playwright Client Examples</name>
|
<name>Playwright Client Examples</name>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>parent-pom</artifactId>
|
<artifactId>parent-pom</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>playwright</artifactId>
|
<artifactId>playwright</artifactId>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import static com.microsoft.playwright.impl.Serialization.toJsonArray;
|
import static com.microsoft.playwright.impl.Serialization.toJsonArray;
|
||||||
|
|
||||||
public class Utils {
|
class Utils {
|
||||||
static <F, T> T convertType(F f, Class<T> t) {
|
static <F, T> T convertType(F f, Class<T> t) {
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -80,7 +80,7 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T clone(T f) {
|
static <T> T clone(T f) {
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,112 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.APIRequest;
|
|
||||||
import com.microsoft.playwright.Browser;
|
|
||||||
import com.microsoft.playwright.BrowserType;
|
|
||||||
import com.microsoft.playwright.Playwright;
|
|
||||||
import com.microsoft.playwright.options.ViewportSize;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class Options {
|
|
||||||
public String baseUrl;
|
|
||||||
public Path storageStatePath;
|
|
||||||
public ViewportSize viewportSize;
|
|
||||||
public String channel;
|
|
||||||
public Boolean headless;
|
|
||||||
public String browserName = "chromium";
|
|
||||||
public BrowserType.LaunchOptions launchOptions;
|
|
||||||
public Browser.NewContextOptions contextOption;
|
|
||||||
public APIRequest.NewContextOptions apiRequestOptions;
|
|
||||||
public Playwright.CreateOptions playwrightCreateOptions;
|
|
||||||
|
|
||||||
public Playwright.CreateOptions getPlaywrightCreateOptions() {
|
|
||||||
return playwrightCreateOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setPlaywrightCreateOptions(Playwright.CreateOptions playwrightCreateOptions) {
|
|
||||||
this.playwrightCreateOptions = playwrightCreateOptions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BrowserType.LaunchOptions getLaunchOptions() {
|
|
||||||
return launchOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setLaunchOptions(BrowserType.LaunchOptions launchOptions) {
|
|
||||||
this.launchOptions = launchOptions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Browser.NewContextOptions getContextOption() {
|
|
||||||
return contextOption;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setContextOption(Browser.NewContextOptions contextOption) {
|
|
||||||
this.contextOption = contextOption;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public APIRequest.NewContextOptions getApiRequestOptions() {
|
|
||||||
return apiRequestOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setApiRequestOptions(APIRequest.NewContextOptions apiRequestOptions) {
|
|
||||||
this.apiRequestOptions = apiRequestOptions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBaseUrl() {
|
|
||||||
return baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setBaseUrl(String baseUrl) {
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path getStorageStatePath() {
|
|
||||||
return storageStatePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setStorageStatePath(Path storageStatePath) {
|
|
||||||
this.storageStatePath = storageStatePath;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBrowserName() {
|
|
||||||
return browserName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setBrowserName(String browserName) {
|
|
||||||
this.browserName = browserName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getChannel() {
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setChannel(String channel) {
|
|
||||||
this.channel = channel;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isHeadless() {
|
|
||||||
return headless;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setHeadless(Boolean headless) {
|
|
||||||
this.headless = headless;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ViewportSize getViewportSize() {
|
|
||||||
return viewportSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Options setViewportSize(ViewportSize viewportSize) {
|
|
||||||
this.viewportSize = viewportSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.junit.impl.*;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@ExtendWith({OptionsExtension.class, PlaywrightExtension.class, BrowserExtension.class, BrowserContextExtension.class,
|
|
||||||
PageExtension.class, APIRequestContextExtension.class})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
public @interface UsePlaywright {
|
|
||||||
Class<? extends Options> options() default Options.class;
|
|
||||||
}
|
|
||||||
-45
@@ -1,45 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit.impl;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.APIRequestContext;
|
|
||||||
import com.microsoft.playwright.Playwright;
|
|
||||||
import com.microsoft.playwright.junit.Options;
|
|
||||||
import org.junit.jupiter.api.extension.*;
|
|
||||||
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
|
||||||
|
|
||||||
public class APIRequestContextExtension implements ParameterResolver, BeforeEachCallback, AfterAllCallback {
|
|
||||||
private static final ThreadLocal<APIRequestContext> threadLocalAPIRequestContext = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeEach(ExtensionContext extensionContext) {
|
|
||||||
threadLocalAPIRequestContext.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterAll(ExtensionContext extensionContext) {
|
|
||||||
threadLocalAPIRequestContext.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return isParameterSupported(parameterContext, extensionContext, APIRequestContext.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return getOrCreateAPIRequestContext(extensionContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static APIRequestContext getOrCreateAPIRequestContext(ExtensionContext extensionContext) {
|
|
||||||
APIRequestContext apiRequestContext = threadLocalAPIRequestContext.get();
|
|
||||||
if (apiRequestContext != null) {
|
|
||||||
return apiRequestContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
Options options = OptionsExtension.getOptions(extensionContext);
|
|
||||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
|
||||||
apiRequestContext = playwright.request().newContext(options.getApiRequestOptions());
|
|
||||||
threadLocalAPIRequestContext.set(apiRequestContext);
|
|
||||||
return apiRequestContext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-68
@@ -1,68 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit.impl;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.Browser;
|
|
||||||
import com.microsoft.playwright.BrowserContext;
|
|
||||||
import com.microsoft.playwright.impl.Utils;
|
|
||||||
import com.microsoft.playwright.junit.Options;
|
|
||||||
import org.junit.jupiter.api.extension.*;
|
|
||||||
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isClassHook;
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
|
||||||
|
|
||||||
public class BrowserContextExtension implements ParameterResolver, AfterEachCallback {
|
|
||||||
private static final ThreadLocal<BrowserContext> threadLocalBrowserContext = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterEach(ExtensionContext extensionContext) {
|
|
||||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
|
||||||
threadLocalBrowserContext.remove();
|
|
||||||
if (browserContext != null) {
|
|
||||||
browserContext.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return !isClassHook(extensionContext) && isParameterSupported(parameterContext, extensionContext, BrowserContext.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return getOrCreateBrowserContext(extensionContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BrowserContext getOrCreateBrowserContext(ExtensionContext extensionContext) {
|
|
||||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
|
||||||
if (browserContext != null) {
|
|
||||||
return browserContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
Options options = OptionsExtension.getOptions(extensionContext);
|
|
||||||
Browser browser = BrowserExtension.getOrCreateBrowser(extensionContext);
|
|
||||||
Browser.NewContextOptions contextOptions = getContextOptions(options);
|
|
||||||
browserContext = browser.newContext(contextOptions);
|
|
||||||
threadLocalBrowserContext.set(browserContext);
|
|
||||||
return browserContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Browser.NewContextOptions getContextOptions(Options options) {
|
|
||||||
Browser.NewContextOptions contextOptions = Utils.clone(options.getContextOption());
|
|
||||||
if (contextOptions == null) {
|
|
||||||
contextOptions = new Browser.NewContextOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.getBaseUrl() != null) {
|
|
||||||
contextOptions.setBaseURL(options.getBaseUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.getStorageStatePath() != null) {
|
|
||||||
contextOptions.setStorageStatePath(options.getStorageStatePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.getViewportSize() != null) {
|
|
||||||
contextOptions.setViewportSize(options.getViewportSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
return contextOptions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit.impl;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.Browser;
|
|
||||||
import com.microsoft.playwright.BrowserType;
|
|
||||||
import com.microsoft.playwright.Playwright;
|
|
||||||
import com.microsoft.playwright.PlaywrightException;
|
|
||||||
import com.microsoft.playwright.impl.Utils;
|
|
||||||
import com.microsoft.playwright.junit.Options;
|
|
||||||
import org.junit.jupiter.api.extension.*;
|
|
||||||
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
|
||||||
|
|
||||||
public class BrowserExtension implements ParameterResolver, AfterAllCallback {
|
|
||||||
private static final ThreadLocal<Browser> threadLocalBrowser = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterAll(ExtensionContext extensionContext) {
|
|
||||||
Browser browser = threadLocalBrowser.get();
|
|
||||||
threadLocalBrowser.remove();
|
|
||||||
if (browser != null) {
|
|
||||||
browser.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return isParameterSupported(parameterContext, extensionContext, Browser.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return getOrCreateBrowser(extensionContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Browser getOrCreateBrowser(ExtensionContext extensionContext) {
|
|
||||||
Browser browser = threadLocalBrowser.get();
|
|
||||||
if (browser != null) {
|
|
||||||
return browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
Options options = OptionsExtension.getOptions(extensionContext);
|
|
||||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
|
||||||
BrowserType.LaunchOptions launchOptions = getLaunchOptions(options);
|
|
||||||
|
|
||||||
switch (options.getBrowserName()) {
|
|
||||||
case "webkit":
|
|
||||||
browser = playwright.webkit().launch(launchOptions);
|
|
||||||
break;
|
|
||||||
case "firefox":
|
|
||||||
browser = playwright.firefox().launch(launchOptions);
|
|
||||||
break;
|
|
||||||
case "chromium":
|
|
||||||
browser = playwright.chromium().launch(launchOptions);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new PlaywrightException("Invalid browser name.");
|
|
||||||
}
|
|
||||||
|
|
||||||
threadLocalBrowser.set(browser);
|
|
||||||
return browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BrowserType.LaunchOptions getLaunchOptions(Options options) {
|
|
||||||
BrowserType.LaunchOptions launchOptions = Utils.clone(options.getLaunchOptions());
|
|
||||||
if (launchOptions == null) {
|
|
||||||
launchOptions = new BrowserType.LaunchOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.isHeadless() != null) {
|
|
||||||
launchOptions.setHeadless(options.isHeadless());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.getChannel() != null) {
|
|
||||||
options.setChannel(options.getChannel());
|
|
||||||
}
|
|
||||||
|
|
||||||
return launchOptions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit.impl;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.junit.UsePlaywright;
|
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
|
||||||
import org.junit.jupiter.api.extension.ParameterContext;
|
|
||||||
import org.junit.platform.commons.support.AnnotationSupport;
|
|
||||||
|
|
||||||
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
|
|
||||||
|
|
||||||
class ExtensionUtils {
|
|
||||||
static boolean hasUsePlaywrightAnnotation(ExtensionContext extensionContext) {
|
|
||||||
return AnnotationSupport.isAnnotated(extensionContext.getTestClass(), UsePlaywright.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
static UsePlaywright getUsePlaywrightAnnotation(ExtensionContext extensionContext) {
|
|
||||||
return findAnnotation(extensionContext.getTestClass(), UsePlaywright.class).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isClassHook(ExtensionContext extensionContext) {
|
|
||||||
return !extensionContext.getTestMethod().isPresent();
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isParameterSupported(ParameterContext parameterContext, ExtensionContext extensionContext, Class<?> subject) {
|
|
||||||
if (!hasUsePlaywrightAnnotation(extensionContext)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Class<?> clazz = parameterContext.getParameter().getType();
|
|
||||||
return subject.equals(clazz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit.impl;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.PlaywrightException;
|
|
||||||
import com.microsoft.playwright.junit.Options;
|
|
||||||
import com.microsoft.playwright.junit.UsePlaywright;
|
|
||||||
import org.junit.jupiter.api.extension.AfterAllCallback;
|
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
|
||||||
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.getUsePlaywrightAnnotation;
|
|
||||||
|
|
||||||
public class OptionsExtension implements AfterAllCallback {
|
|
||||||
private static final ThreadLocal<Options> threadLocalOptions = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterAll(ExtensionContext extensionContext) {
|
|
||||||
threadLocalOptions.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Options getOptions(ExtensionContext extensionContext) {
|
|
||||||
Options options = threadLocalOptions.get();
|
|
||||||
if (options != null) {
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
UsePlaywright usePlaywrightAnnotation = getUsePlaywrightAnnotation(extensionContext);
|
|
||||||
try {
|
|
||||||
options = usePlaywrightAnnotation.options().newInstance();
|
|
||||||
threadLocalOptions.set(options);
|
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
|
||||||
throw new PlaywrightException("Failed to create options", e);
|
|
||||||
}
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit.impl;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.BrowserContext;
|
|
||||||
import com.microsoft.playwright.Page;
|
|
||||||
import org.junit.jupiter.api.extension.*;
|
|
||||||
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isClassHook;
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
|
||||||
|
|
||||||
public class PageExtension implements ParameterResolver, AfterEachCallback {
|
|
||||||
private static final ThreadLocal<Page> threadLocalPage = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterEach(ExtensionContext extensionContext) {
|
|
||||||
Page page = threadLocalPage.get();
|
|
||||||
threadLocalPage.remove();
|
|
||||||
if (page != null) {
|
|
||||||
page.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return !isClassHook(extensionContext) && isParameterSupported(parameterContext, extensionContext, Page.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return getOrCreatePage(extensionContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Page getOrCreatePage(ExtensionContext extensionContext) {
|
|
||||||
Page page = threadLocalPage.get();
|
|
||||||
if (page != null) {
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
BrowserContext browserContext = BrowserContextExtension.getOrCreateBrowserContext(extensionContext);
|
|
||||||
page = browserContext.newPage();
|
|
||||||
threadLocalPage.set(page);
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.microsoft.playwright.junit.impl;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.Playwright;
|
|
||||||
import com.microsoft.playwright.junit.Options;
|
|
||||||
import org.junit.jupiter.api.extension.*;
|
|
||||||
|
|
||||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
|
||||||
|
|
||||||
public class PlaywrightExtension implements ParameterResolver, AfterAllCallback {
|
|
||||||
private static final ThreadLocal<Playwright> threadLocalPlaywright = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterAll(ExtensionContext extensionContext) {
|
|
||||||
Playwright playwright = threadLocalPlaywright.get();
|
|
||||||
threadLocalPlaywright.remove();
|
|
||||||
if (playwright != null) {
|
|
||||||
playwright.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return isParameterSupported(parameterContext, extensionContext, Playwright.class);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
|
||||||
return getOrCreatePlaywright(extensionContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Playwright getOrCreatePlaywright(ExtensionContext extensionContext) {
|
|
||||||
Playwright playwright = threadLocalPlaywright.get();
|
|
||||||
if (playwright != null) {
|
|
||||||
return playwright;
|
|
||||||
}
|
|
||||||
|
|
||||||
Options options = OptionsExtension.getOptions(extensionContext);
|
|
||||||
playwright = Playwright.create(options.getPlaywrightCreateOptions());
|
|
||||||
threadLocalPlaywright.set(playwright);
|
|
||||||
return playwright;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package com.microsoft.playwright;
|
|
||||||
|
|
||||||
import com.microsoft.playwright.junit.UsePlaywright;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
@UsePlaywright
|
|
||||||
public class TestPlaywrightFixtures {
|
|
||||||
private static Playwright playwrightFromBeforeAll;
|
|
||||||
private static Browser browserFromBeforeAll;
|
|
||||||
private BrowserContext browserContextFromBeforeEach;
|
|
||||||
private Page pageFromBeforeEach;
|
|
||||||
private static APIRequestContext apiRequestContextFromBeforeAll;
|
|
||||||
private APIRequestContext apiRequestContextFromBeforeEach;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public static void beforeAll(Playwright playwright, Browser browser, APIRequestContext apiRequestContext) {
|
|
||||||
assertNotNull(playwright);
|
|
||||||
assertNotNull(browser);
|
|
||||||
assertNotNull(apiRequestContext);
|
|
||||||
|
|
||||||
playwrightFromBeforeAll = playwright;
|
|
||||||
browserFromBeforeAll = browser;
|
|
||||||
apiRequestContextFromBeforeAll = apiRequestContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void beforeEach(Playwright playwright, Browser browser, BrowserContext browserContext, Page page, APIRequestContext apiRequestContext) {
|
|
||||||
assertEquals(playwrightFromBeforeAll, playwright);
|
|
||||||
assertEquals(browserFromBeforeAll, browser);
|
|
||||||
assertNotEquals(apiRequestContextFromBeforeAll, apiRequestContext);
|
|
||||||
|
|
||||||
assertNotNull(browserContext);
|
|
||||||
assertNotNull(page);
|
|
||||||
browserContextFromBeforeEach = browserContext;
|
|
||||||
pageFromBeforeEach = page;
|
|
||||||
apiRequestContextFromBeforeEach = apiRequestContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void objectShouldBeSameAsBeforeAll(Playwright playwright, Browser browser) {
|
|
||||||
assertEquals(playwrightFromBeforeAll, playwright);
|
|
||||||
assertEquals(browserFromBeforeAll, browser);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void objectShouldBeSameAsBeforeEach(BrowserContext browserContext, Page page, APIRequestContext apiRequestContext) {
|
|
||||||
assertEquals(browserContextFromBeforeEach, browserContext);
|
|
||||||
assertEquals(pageFromBeforeEach, page);
|
|
||||||
assertEquals(apiRequestContextFromBeforeEach, apiRequestContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>parent-pom</artifactId>
|
<artifactId>parent-pom</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>Playwright Parent Project</name>
|
<name>Playwright Parent Project</name>
|
||||||
<description>Java library to automate Chromium, Firefox and WebKit with a single API.
|
<description>Java library to automate Chromium, Firefox and WebKit with a single API.
|
||||||
@@ -86,12 +86,6 @@
|
|||||||
<version>${websocket.version}</version>
|
<version>${websocket.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1.41.0
|
1.41.1
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>api-generator</artifactId>
|
<artifactId>api-generator</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<name>Playwright - API Generator</name>
|
<name>Playwright - API Generator</name>
|
||||||
<description>
|
<description>
|
||||||
This is an internal module used to generate Java API from the upstream Playwright
|
This is an internal module used to generate Java API from the upstream Playwright
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>test-cli-fatjar</artifactId>
|
<artifactId>test-cli-fatjar</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<name>Test Playwright Command Line FatJar</name>
|
<name>Test Playwright Command Line FatJar</name>
|
||||||
<properties>
|
<properties>
|
||||||
<compiler.version>1.8</compiler.version>
|
<compiler.version>1.8</compiler.version>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>test-cli-version</artifactId>
|
<artifactId>test-cli-version</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<name>Test Playwright Command Line Version</name>
|
<name>Test Playwright Command Line Version</name>
|
||||||
<properties>
|
<properties>
|
||||||
<compiler.version>1.8</compiler.version>
|
<compiler.version>1.8</compiler.version>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>test-local-installation</artifactId>
|
<artifactId>test-local-installation</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<name>Test local installation</name>
|
<name>Test local installation</name>
|
||||||
<description>Runs Playwright test suite (copied from playwright module) against locally cached Playwright</description>
|
<description>Runs Playwright test suite (copied from playwright module) against locally cached Playwright</description>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>test-spring-boot-starter</artifactId>
|
<artifactId>test-spring-boot-starter</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<name>Test Playwright With Spring Boot</name>
|
<name>Test Playwright With Spring Boot</name>
|
||||||
<properties>
|
<properties>
|
||||||
<spring.version>2.4.3</spring.version>
|
<spring.version>2.4.3</spring.version>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.microsoft.playwright</groupId>
|
<groupId>com.microsoft.playwright</groupId>
|
||||||
<artifactId>update-version</artifactId>
|
<artifactId>update-version</artifactId>
|
||||||
<version>1.41.0-SNAPSHOT</version>
|
<version>1.41.1</version>
|
||||||
<name>Playwright - Update Version in Documentation</name>
|
<name>Playwright - Update Version in Documentation</name>
|
||||||
<description>
|
<description>
|
||||||
This is an internal module used to update versions in the documentation based on
|
This is an internal module used to update versions in the documentation based on
|
||||||
|
|||||||
Reference in New Issue
Block a user