diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java index d2815d50..97986fe5 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java @@ -187,14 +187,18 @@ public class PageImpl extends ChannelOwner implements Page { @Override public void addListener(EventType type, Listener listener) { - willAddFileChooserListener(); + if (type == EventType.FILECHOOSER) { + willAddFileChooserListener(); + } listeners.add(type, listener); } @Override public void removeListener(EventType type, Listener listener) { listeners.remove(type, listener); - didRemoveFileChooserListener(); + if (type == EventType.FILECHOOSER) { + didRemoveFileChooserListener(); + } } @Override diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBase.java b/playwright/src/test/java/com/microsoft/playwright/TestBase.java index 599cc125..708c4891 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestBase.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestBase.java @@ -24,56 +24,61 @@ import org.junit.jupiter.api.BeforeEach; import java.io.IOException; public class TestBase { - static Server server; - static Server httpsServer; - static BrowserType browserType; - static Playwright playwright; - static Browser browser; - static boolean isChromium; - static boolean isWebKit; - static boolean isFirefox; - static boolean headful; - Page page; - BrowserContext context; + static Server server; + static Server httpsServer; + static BrowserType browserType; + static Playwright playwright; + static Browser browser; + static boolean isChromium; + static boolean isWebKit; + static boolean isFirefox; + static boolean headful; + Page page; + BrowserContext context; - @BeforeAll - static void launchBrowser() { - playwright = Playwright.create(); - BrowserType.LaunchOptions options = new BrowserType.LaunchOptions(); - browserType = playwright.chromium(); - browser = browserType.launch(options); - isChromium = true; - isWebKit = false; - headful = false; - } + @BeforeAll + static void launchBrowser() { + playwright = Playwright.create(); + BrowserType.LaunchOptions options = new BrowserType.LaunchOptions(); + browserType = playwright.chromium(); + browser = browserType.launch(options); + isChromium = true; + isWebKit = false; + headful = false; + } - @BeforeAll - static void startServer() throws IOException { - server = Server.createHttp(8907); - httpsServer = Server.createHttps(8908); - } + @AfterAll + static void closeBrowser() { + browser.close(); + browser = null; + } - @AfterAll - static void stopServer() throws IOException { - browser.close(); - server.stop(); - server = null; - httpsServer.stop(); - httpsServer = null; - } + @BeforeAll + static void startServer() throws IOException { + server = Server.createHttp(8907); + httpsServer = Server.createHttps(8908); + } - @BeforeEach - void setUp() { - server.reset(); - httpsServer.reset(); - context = browser.newContext(); - page = context.newPage(); - } + @AfterAll + static void stopServer() throws IOException { + server.stop(); + server = null; + httpsServer.stop(); + httpsServer = null; + } - @AfterEach - void tearDown() { - context.close(); - context = null; - page = null; - } + @BeforeEach + void createContextAndPage() { + server.reset(); + httpsServer.reset(); + context = browser.newContext(); + page = context.newPage(); + } + + @AfterEach + void closeContext() { + context.close(); + context = null; + page = null; + } }