playwright-java icon indicating copy to clipboard operation
playwright-java copied to clipboard

[Feature]: provide test fixtures for TestNG similar to JUnits @UsePlaywright functionality

Open bpoplawski opened this issue 8 months ago • 1 comments

🚀 Feature Request

Please provide test fixtures for TestNG testing framework which would work similarly as in JUnit framework. This could work similarly to @UsePlaywright, reducing boilerplate code.

In other words a similar funcitonality to Junit one provided here: https://playwright.dev/java/docs/junit

Example

Example is to use annotation like suggested in : https://playwright.dev/java/docs/junit

@UsePlaywright public class TestExample { @Test void shouldClickButton(Page page) { page.navigate("data:text/html,"); page.locator("button").click(); assertEquals("Clicked", page.evaluate("result")); }

Motivation

Motivation is a fact that TestNG is also broadly used

bpoplawski avatar Apr 29 '25 09:04 bpoplawski

TestNG doesn't have the capability to provide fixtures easily. We would need to create a base class that test classes would need to inherit from which isn't ideal because java doesn't allow multiple inheritance. All the other ways to pass parameters to a test results in conflicts with other aspects of TestNG.

For example, if we use a @DataProvider annotation to provide Playwright fixtures, the user can no longer use @Parameters functionality of TestNG.

In my opinion, supporting TestNG will bring more maintenance headaches than is worth it because we don't know how the user is using TestNG.

As a workaround, you could use @UsePlaywright annotation and in your own base class, create an instance of the factory and configure Playwright objects yourself.

uchagani avatar Apr 30 '25 13:04 uchagani