From 5fe5a3e925030943a1fd8f6ed297d9bb2deeaf3a Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 10 Oct 2023 16:32:08 -0700 Subject: [PATCH] Revert "feat(junit-playwright) (#1371)" (#1402) This reverts commit fb2188cd2a041768be664f899d32b856787a7b73. --- .../junit/BrowserContextFactory.java | 8 -- .../playwright/junit/BrowserFactory.java | 8 -- .../junit/DefaultBrowserContextFactory.java | 11 --- .../junit/DefaultBrowserFactory.java | 45 --------- .../junit/DefaultPlaywrightFactory.java | 10 -- .../playwright/junit/PlaywrightFactory.java | 7 -- .../playwright/junit/UsePlaywright.java | 23 ----- .../junit/impl/BrowserContextExtension.java | 91 ------------------ .../junit/impl/BrowserExtension.java | 77 --------------- .../playwright/junit/impl/ExtensionUtils.java | 21 ----- .../playwright/junit/impl/PageExtension.java | 61 ------------ .../junit/impl/PlaywrightExtension.java | 77 --------------- .../CustomBrowserContextFactory.java | 16 ---- .../playwright/CustomBrowserFactory.java | 10 -- .../TestFixturesWithCustomFactories.java | 93 ------------------- .../TestFixturesWithDefaultFactories.java | 92 ------------------ pom.xml | 11 --- 17 files changed, 661 deletions(-) delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/BrowserContextFactory.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/BrowserFactory.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserContextFactory.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserFactory.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/DefaultPlaywrightFactory.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/PlaywrightFactory.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/UsePlaywright.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserContextExtension.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserExtension.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/impl/ExtensionUtils.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/impl/PageExtension.java delete mode 100644 playwright/src/main/java/com/microsoft/playwright/junit/impl/PlaywrightExtension.java delete mode 100644 playwright/src/test/java/com/microsoft/playwright/CustomBrowserContextFactory.java delete mode 100644 playwright/src/test/java/com/microsoft/playwright/CustomBrowserFactory.java delete mode 100644 playwright/src/test/java/com/microsoft/playwright/TestFixturesWithCustomFactories.java delete mode 100644 playwright/src/test/java/com/microsoft/playwright/TestFixturesWithDefaultFactories.java diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/BrowserContextFactory.java b/playwright/src/main/java/com/microsoft/playwright/junit/BrowserContextFactory.java deleted file mode 100644 index 8cc672677..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/BrowserContextFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.microsoft.playwright.junit; - -import com.microsoft.playwright.Browser; -import com.microsoft.playwright.BrowserContext; - -public interface BrowserContextFactory { - BrowserContext newBrowserContext(Browser browser); -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/BrowserFactory.java b/playwright/src/main/java/com/microsoft/playwright/junit/BrowserFactory.java deleted file mode 100644 index f5aa66ec5..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/BrowserFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.microsoft.playwright.junit; - -import com.microsoft.playwright.Browser; -import com.microsoft.playwright.Playwright; - -public interface BrowserFactory { - Browser newBrowser(Playwright playwright); -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserContextFactory.java b/playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserContextFactory.java deleted file mode 100644 index 89877b81b..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserContextFactory.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.microsoft.playwright.junit; - -import com.microsoft.playwright.Browser; -import com.microsoft.playwright.BrowserContext; - -public class DefaultBrowserContextFactory implements BrowserContextFactory { - @Override - public BrowserContext newBrowserContext(Browser browser) { - return browser.newContext(); - } -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserFactory.java b/playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserFactory.java deleted file mode 100644 index 9b0764414..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/DefaultBrowserFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.microsoft.playwright.junit; - -import com.microsoft.playwright.Browser; -import com.microsoft.playwright.BrowserType; -import com.microsoft.playwright.Playwright; -import com.microsoft.playwright.PlaywrightException; - -public class DefaultBrowserFactory implements BrowserFactory { - private final boolean headed; - private final String browserEnv; - - public DefaultBrowserFactory() { - headed = isHeaded(); - browserEnv = getBrowserNameFromEnv(); - } - - @Override - public Browser newBrowser(Playwright playwright) { - BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions().setHeadless(!headed); - - switch (browserEnv) { - case "webkit": - return playwright.webkit().launch(launchOptions); - case "firefox": - return playwright.firefox().launch(launchOptions); - case "chromium": - return playwright.chromium().launch(launchOptions); - default: - throw new PlaywrightException("Invalid value set for BROWSER. Must be one of: chromium, firefox, webkit"); - } - } - - private static String getBrowserNameFromEnv() { - String browserName = System.getenv("BROWSER"); - if (browserName == null) { - browserName = "chromium"; - } - return browserName; - } - - private static boolean isHeaded() { - String headedEnv = System.getenv("HEADED"); - return headedEnv != null && !"0".equals(headedEnv) && !"false".equals(headedEnv); - } -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/DefaultPlaywrightFactory.java b/playwright/src/main/java/com/microsoft/playwright/junit/DefaultPlaywrightFactory.java deleted file mode 100644 index dccfd6b01..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/DefaultPlaywrightFactory.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.microsoft.playwright.junit; - -import com.microsoft.playwright.Playwright; - -public class DefaultPlaywrightFactory implements PlaywrightFactory { - @Override - public Playwright newPlaywright() { - return Playwright.create(); - } -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/PlaywrightFactory.java b/playwright/src/main/java/com/microsoft/playwright/junit/PlaywrightFactory.java deleted file mode 100644 index 70340c2d4..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/PlaywrightFactory.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.microsoft.playwright.junit; - -import com.microsoft.playwright.Playwright; - -public interface PlaywrightFactory { - Playwright newPlaywright(); -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/UsePlaywright.java b/playwright/src/main/java/com/microsoft/playwright/junit/UsePlaywright.java deleted file mode 100644 index 7200dd527..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/UsePlaywright.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.microsoft.playwright.junit; - -import com.microsoft.playwright.junit.impl.BrowserContextExtension; -import com.microsoft.playwright.junit.impl.BrowserExtension; -import com.microsoft.playwright.junit.impl.PageExtension; -import com.microsoft.playwright.junit.impl.PlaywrightExtension; -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({PlaywrightExtension.class, BrowserExtension.class, BrowserContextExtension.class, PageExtension.class}) -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface UsePlaywright { - Class playwrightFactory() default DefaultPlaywrightFactory.class; - - Class browserFactory() default DefaultBrowserFactory.class; - - Class browserContextFactory() default DefaultBrowserContextFactory.class; -} 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 deleted file mode 100644 index d96151cee..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserContextExtension.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.microsoft.playwright.junit.impl; - -import com.microsoft.playwright.Browser; -import com.microsoft.playwright.BrowserContext; -import com.microsoft.playwright.PlaywrightException; -import com.microsoft.playwright.junit.BrowserContextFactory; -import com.microsoft.playwright.junit.UsePlaywright; -import org.junit.jupiter.api.extension.*; - -import static com.microsoft.playwright.junit.impl.ExtensionUtils.*; - -public class BrowserContextExtension implements ParameterResolver, AfterEachCallback, AfterAllCallback { - private final static ThreadLocal threadLocalBrowserContext; - private final static ThreadLocal threadLocalBrowserContextFactory; - - static { - threadLocalBrowserContext = new ThreadLocal<>(); - threadLocalBrowserContextFactory = new ThreadLocal<>(); - } - - @Override - public void afterEach(ExtensionContext extensionContext) { - cleanupBrowserContext(); - } - - @Override - public void afterAll(ExtensionContext extensionContext) { - cleanupBrowserContextFactory(); - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - if (isClassHook(extensionContext) || !hasUsePlaywrightAnnotation(extensionContext)) { - return false; - } - Class clazz = parameterContext.getParameter().getType(); - return BrowserContext.class.equals(clazz); - } - - @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; - } - - Browser browser = BrowserExtension.getOrCreateBrowser(extensionContext); - BrowserContextFactory browserContextFactory = getBrowserContextFactoryInstance(extensionContext); - browserContext = browserContextFactory.newBrowserContext(browser); - threadLocalBrowserContext.set(browserContext); - return browserContext; - } - - private static BrowserContextFactory getBrowserContextFactoryInstance(ExtensionContext extensionContext) { - if (threadLocalBrowserContextFactory.get() != null) { - return threadLocalBrowserContextFactory.get(); - } - - UsePlaywright usePlaywrightAnnotation = getUsePlaywrightAnnotation(extensionContext); - - try { - BrowserContextFactory browserContextFactory = usePlaywrightAnnotation.browserContextFactory().newInstance(); - threadLocalBrowserContextFactory.set(browserContextFactory); - return browserContextFactory; - } catch (InstantiationException | IllegalAccessException e) { - throw new PlaywrightException("Unable to create an instance of the supplied BrowserContextFactory", e); - } - } - - private void cleanupBrowserContext() { - try { - BrowserContext browserContext = threadLocalBrowserContext.get(); - if (browserContext != null) { - browserContext.close(); - } - } finally { - threadLocalBrowserContext.remove(); - } - } - - private void cleanupBrowserContextFactory() { - BrowserContextFactory browserContextFactory = threadLocalBrowserContextFactory.get(); - if (browserContextFactory != null) { - threadLocalBrowserContextFactory.remove(); - } - } -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserExtension.java b/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserExtension.java deleted file mode 100644 index 0d079bba9..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/impl/BrowserExtension.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.microsoft.playwright.junit.impl; - -import com.microsoft.playwright.Browser; -import com.microsoft.playwright.Playwright; -import com.microsoft.playwright.PlaywrightException; -import com.microsoft.playwright.junit.BrowserFactory; -import com.microsoft.playwright.junit.UsePlaywright; -import org.junit.jupiter.api.extension.*; - -import static com.microsoft.playwright.junit.impl.ExtensionUtils.getUsePlaywrightAnnotation; -import static com.microsoft.playwright.junit.impl.ExtensionUtils.hasUsePlaywrightAnnotation; - -public class BrowserExtension implements ParameterResolver, AfterAllCallback { - private static final ThreadLocal threadLocalBrowser; - private static final ThreadLocal threadLocalBrowserFactory; - - static { - threadLocalBrowser = new ThreadLocal<>(); - threadLocalBrowserFactory = new ThreadLocal<>(); - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - if (!hasUsePlaywrightAnnotation(extensionContext)) { - return false; - } - Class clazz = parameterContext.getParameter().getType(); - return Browser.class.equals(clazz); - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - return getOrCreateBrowser(extensionContext); - } - - @Override - public void afterAll(ExtensionContext extensionContext) { - try { - Browser browser = threadLocalBrowser.get(); - if (browser != null) { - browser.close(); - } - } finally { - threadLocalBrowser.remove(); - threadLocalBrowserFactory.remove(); - } - } - - static Browser getOrCreateBrowser(ExtensionContext extensionContext) { - Browser browser = threadLocalBrowser.get(); - if (browser != null) { - return browser; - } - - Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext); - BrowserFactory browserFactory = getBrowserFactoryInstance(extensionContext); - browser = browserFactory.newBrowser(playwright); - threadLocalBrowser.set(browser); - return browser; - } - - private static BrowserFactory getBrowserFactoryInstance(ExtensionContext extensionContext) { - if (threadLocalBrowserFactory.get() != null) { - return threadLocalBrowserFactory.get(); - } - - UsePlaywright usePlaywrightAnnotation = getUsePlaywrightAnnotation(extensionContext); - - try { - BrowserFactory browserFactory = usePlaywrightAnnotation.browserFactory().newInstance(); - threadLocalBrowserFactory.set(browserFactory); - return browserFactory; - } catch (InstantiationException | IllegalAccessException e) { - throw new PlaywrightException("Unable to create an instance of the supplied BrowserFactory", e); - } - } -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/impl/ExtensionUtils.java b/playwright/src/main/java/com/microsoft/playwright/junit/impl/ExtensionUtils.java deleted file mode 100644 index 352d005aa..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/impl/ExtensionUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.microsoft.playwright.junit.impl; - -import com.microsoft.playwright.junit.UsePlaywright; -import org.junit.jupiter.api.extension.ExtensionContext; -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(); - } -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/impl/PageExtension.java b/playwright/src/main/java/com/microsoft/playwright/junit/impl/PageExtension.java deleted file mode 100644 index 7b8b77a83..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/impl/PageExtension.java +++ /dev/null @@ -1,61 +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.hasUsePlaywrightAnnotation; -import static com.microsoft.playwright.junit.impl.ExtensionUtils.isClassHook; - -public class PageExtension implements ParameterResolver, AfterEachCallback { - private final static ThreadLocal threadLocalPage; - - static { - threadLocalPage = new ThreadLocal<>(); - } - - @Override - public void afterEach(ExtensionContext extensionContext) { - cleanupPage(); - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - if (isClassHook(extensionContext) || !hasUsePlaywrightAnnotation(extensionContext)) { - return false; - } - Class clazz = parameterContext.getParameter().getType(); - return Page.class.equals(clazz); - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - return getOrCreatePage(extensionContext); - } - - private 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; - } - - private void cleanupPage() { - try { - Page page = threadLocalPage.get(); - if (page != null) { - if (!page.isClosed()) { - page.close(); - } - } - } finally { - threadLocalPage.remove(); - } - - } -} diff --git a/playwright/src/main/java/com/microsoft/playwright/junit/impl/PlaywrightExtension.java b/playwright/src/main/java/com/microsoft/playwright/junit/impl/PlaywrightExtension.java deleted file mode 100644 index 84671fc40..000000000 --- a/playwright/src/main/java/com/microsoft/playwright/junit/impl/PlaywrightExtension.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.microsoft.playwright.junit.impl; - -import com.microsoft.playwright.Playwright; -import com.microsoft.playwright.PlaywrightException; -import com.microsoft.playwright.junit.PlaywrightFactory; -import com.microsoft.playwright.junit.UsePlaywright; -import org.junit.jupiter.api.extension.*; - -import static com.microsoft.playwright.junit.impl.ExtensionUtils.getUsePlaywrightAnnotation; -import static com.microsoft.playwright.junit.impl.ExtensionUtils.hasUsePlaywrightAnnotation; - -public class PlaywrightExtension implements ParameterResolver, AfterAllCallback { - private static final ThreadLocal threadLocalPlaywright; - private static final ThreadLocal threadLocalPlaywrightFactory; - - static { - threadLocalPlaywright = new ThreadLocal<>(); - threadLocalPlaywrightFactory = new ThreadLocal<>(); - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - if (!hasUsePlaywrightAnnotation(extensionContext)) { - return false; - } - Class clazz = parameterContext.getParameter().getType(); - return Playwright.class.equals(clazz); - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - return getOrCreatePlaywright(extensionContext); - } - - @Override - public void afterAll(ExtensionContext extensionContext) { - closePlaywright(); - } - - static Playwright getOrCreatePlaywright(ExtensionContext extensionContext) { - Playwright playwright = threadLocalPlaywright.get(); - if (playwright != null) { - return playwright; - } - - PlaywrightFactory playwrightFactory = getPlaywrightFactoryInstance(extensionContext); - playwright = playwrightFactory.newPlaywright(); - threadLocalPlaywright.set(playwright); - return playwright; - } - - private static PlaywrightFactory getPlaywrightFactoryInstance(ExtensionContext extensionContext) { - if (threadLocalPlaywrightFactory.get() != null) { - return threadLocalPlaywrightFactory.get(); - } - - UsePlaywright usePlaywrightAnnotation = getUsePlaywrightAnnotation(extensionContext); - - try { - PlaywrightFactory playwrightFactory = usePlaywrightAnnotation.playwrightFactory().newInstance(); - threadLocalPlaywrightFactory.set(playwrightFactory); - return playwrightFactory; - } catch (InstantiationException | IllegalAccessException e) { - throw new PlaywrightException("Unable to create an instance of the supplied PlaywrightFactory", e); - } - } - - private static void closePlaywright() { - try { - if (threadLocalPlaywright.get() != null) { - threadLocalPlaywright.get().close(); - } - } finally { - threadLocalPlaywright.remove(); - } - } -} diff --git a/playwright/src/test/java/com/microsoft/playwright/CustomBrowserContextFactory.java b/playwright/src/test/java/com/microsoft/playwright/CustomBrowserContextFactory.java deleted file mode 100644 index 84f04413c..000000000 --- a/playwright/src/test/java/com/microsoft/playwright/CustomBrowserContextFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.microsoft.playwright; - -import com.microsoft.playwright.junit.BrowserContextFactory; -import com.microsoft.playwright.options.Cookie; - -import java.util.Collections; - -public class CustomBrowserContextFactory implements BrowserContextFactory { - @Override - public BrowserContext newBrowserContext(Browser browser) { - BrowserContext context = browser.newContext(); - Cookie cookie = new Cookie("foo", "bar").setUrl("https://microsoft.com"); - context.addCookies(Collections.singletonList(cookie)); - return context; - } -} diff --git a/playwright/src/test/java/com/microsoft/playwright/CustomBrowserFactory.java b/playwright/src/test/java/com/microsoft/playwright/CustomBrowserFactory.java deleted file mode 100644 index 5a1d693bf..000000000 --- a/playwright/src/test/java/com/microsoft/playwright/CustomBrowserFactory.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.microsoft.playwright; - -import com.microsoft.playwright.junit.BrowserFactory; - -public class CustomBrowserFactory implements BrowserFactory { - @Override - public Browser newBrowser(Playwright playwright) { - return playwright.firefox().launch(); - } -} diff --git a/playwright/src/test/java/com/microsoft/playwright/TestFixturesWithCustomFactories.java b/playwright/src/test/java/com/microsoft/playwright/TestFixturesWithCustomFactories.java deleted file mode 100644 index 4c641a26c..000000000 --- a/playwright/src/test/java/com/microsoft/playwright/TestFixturesWithCustomFactories.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.microsoft.playwright; - -import com.microsoft.playwright.junit.UsePlaywright; -import org.junit.jupiter.api.*; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@UsePlaywright(browserFactory = CustomBrowserFactory.class, browserContextFactory = CustomBrowserContextFactory.class) -public class TestFixturesWithCustomFactories { - private static Playwright playwrightFromBeforeAll; - private static Browser browserFromBeforeAll; - private BrowserContext browserContextFromBeforeEach; - private Page pageFromBeforeEach; - - @BeforeAll - static void beforeAll(Playwright playwright, Browser browser) { - assertNotNull(playwright); - assertNotNull(browser); - assertEquals("firefox", browser.browserType().name()); - playwrightFromBeforeAll = playwright; - browserFromBeforeAll = browser; - } - - @AfterAll - static void afterAll(Playwright playwright, Browser browser) { - assertNotNull(playwright); - assertNotNull(browser); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - } - - @BeforeEach - void beforeEach(Playwright playwright, Browser browser, BrowserContext browserContext, Page page) { - assertNotNull(playwright); - assertNotNull(browser); - assertNotNull(browserContext); - assertNotNull(page); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - assertEquals(1, browserContext.cookies().size()); - assertEquals("foo", browserContext.cookies().get(0).name); - - this.browserContextFromBeforeEach = browserContext; - this.pageFromBeforeEach = page; - } - - @AfterEach - void afterEach(Playwright playwright, Browser browser, BrowserContext browserContext, Page page) { - assertNotNull(playwright); - assertNotNull(browser); - assertNotNull(browserContext); - assertNotNull(page); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - } - - @Test - void objectsAreSameFromBeforeAll(Playwright playwright, Browser browser) { - assertNotNull(playwright); - assertNotNull(browser); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - } - - @Test - void objectsAreSameFromBeforeEach(BrowserContext browserContext, Page page) { - assertNotNull(browserContext); - assertNotNull(page); - assertEquals(this.browserContextFromBeforeEach, browserContext); - assertEquals(this.pageFromBeforeEach, page); - } - - @Test - void duplicatePlaywrightReturnTheSameObject(Playwright playwright1, Playwright playwright2) { - assertEquals(playwright1, playwright2); - } - - @Test - void duplicateBrowserReturnTheSameObject(Browser browser1, Browser browser2) { - assertEquals(browser1, browser2); - } - - @Test - void duplicateBrowserContextReturnTheSameObject(BrowserContext browserContext1, BrowserContext browserContext2) { - assertEquals(browserContext1, browserContext2); - } - - @Test - void duplicatePageReturnTheSameObject(Page page1, Page page2) { - assertEquals(page1, page2); - } -} diff --git a/playwright/src/test/java/com/microsoft/playwright/TestFixturesWithDefaultFactories.java b/playwright/src/test/java/com/microsoft/playwright/TestFixturesWithDefaultFactories.java deleted file mode 100644 index d4d1cff80..000000000 --- a/playwright/src/test/java/com/microsoft/playwright/TestFixturesWithDefaultFactories.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.microsoft.playwright; - -import com.microsoft.playwright.junit.UsePlaywright; -import org.junit.jupiter.api.*; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@UsePlaywright -public class TestFixturesWithDefaultFactories { - private static Playwright playwrightFromBeforeAll; - private static Browser browserFromBeforeAll; - private BrowserContext browserContextFromBeforeEach; - private Page pageFromBeforeEach; - - @BeforeAll - static void beforeAll(Playwright playwright, Browser browser) { - assertNotNull(playwright); - assertNotNull(browser); - String browserName = System.getenv("BROWSER") == null ? "chromium" : System.getenv("BROWSER"); - assertEquals(browserName, browser.browserType().name()); - playwrightFromBeforeAll = playwright; - browserFromBeforeAll = browser; - } - - @AfterAll - static void afterAll(Playwright playwright, Browser browser) { - assertNotNull(playwright); - assertNotNull(browser); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - } - - @BeforeEach - void beforeEach(Playwright playwright, Browser browser, BrowserContext browserContext, Page page) { - assertNotNull(playwright); - assertNotNull(browser); - assertNotNull(browserContext); - assertNotNull(page); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - - this.browserContextFromBeforeEach = browserContext; - this.pageFromBeforeEach = page; - } - - @AfterEach - void afterEach(Playwright playwright, Browser browser, BrowserContext browserContext, Page page) { - assertNotNull(playwright); - assertNotNull(browser); - assertNotNull(browserContext); - assertNotNull(page); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - } - - @Test - void objectsAreSameFromBeforeAll(Playwright playwright, Browser browser) { - assertNotNull(playwright); - assertNotNull(browser); - assertEquals(playwrightFromBeforeAll, playwright); - assertEquals(browserFromBeforeAll, browser); - } - - @Test - void objectsAreSameFromBeforeEach(BrowserContext browserContext, Page page) { - assertNotNull(browserContext); - assertNotNull(page); - assertEquals(this.browserContextFromBeforeEach, browserContext); - assertEquals(this.pageFromBeforeEach, page); - } - - @Test - void duplicatePlaywrightReturnTheSameObject(Playwright playwright1, Playwright playwright2) { - assertEquals(playwright1, playwright2); - } - - @Test - void duplicateBrowserReturnTheSameObject(Browser browser1, Browser browser2) { - assertEquals(browser1, browser2); - } - - @Test - void duplicateBrowserContextReturnTheSameObject(BrowserContext browserContext1, BrowserContext browserContext2) { - assertEquals(browserContext1, browserContext2); - } - - @Test - void duplicatePageReturnTheSameObject(Page page1, Page page2) { - assertEquals(page1, page2); - } -} diff --git a/pom.xml b/pom.xml index f89c81c0f..36a099d17 100644 --- a/pom.xml +++ b/pom.xml @@ -54,11 +54,6 @@ - - com.microsoft.playwright - playwright - ${project.version} - com.microsoft.playwright driver @@ -85,12 +80,6 @@ ${junit.version} test - - org.junit.jupiter - junit-jupiter-api - ${junit.version} - provided - org.java-websocket Java-WebSocket