{"id":15151842,"url":"https://github.com/uchagani/junit-playwright","last_synced_at":"2025-10-24T08:31:12.967Z","repository":{"id":42050728,"uuid":"472174321","full_name":"uchagani/junit-playwright","owner":"uchagani","description":"JUnit 5 Extension to run Playwright-Java tests in parallel","archived":false,"fork":false,"pushed_at":"2023-01-29T01:29:14.000Z","size":80,"stargazers_count":6,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-01-31T00:32:52.365Z","etag":null,"topics":["automation","java","junit5","playwright","playwright-java","testing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uchagani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-21T03:32:33.000Z","updated_at":"2023-11-27T10:00:57.000Z","dependencies_parsed_at":"2023-02-15T20:00:18.192Z","dependency_job_id":null,"html_url":"https://github.com/uchagani/junit-playwright","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uchagani%2Fjunit-playwright","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uchagani%2Fjunit-playwright/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uchagani%2Fjunit-playwright/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uchagani%2Fjunit-playwright/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uchagani","download_url":"https://codeload.github.com/uchagani/junit-playwright/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237937778,"owners_count":19390543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","java","junit5","playwright","playwright-java","testing"],"created_at":"2024-09-26T15:22:31.553Z","updated_at":"2025-10-24T08:31:07.559Z","avatar_url":"https://github.com/uchagani.png","language":"Java","readme":"# junit-playwright\n\n`junit-playwright` allows you to run your JUnit 5 Playwright tests in parallel easily.  `junit-playwright` provides\nisolated environments for each test and exposes Playwright-related objects as test parameters for you to use in your\ntests.\n\n## Note\n\n`junit-playwright` has recently been updated to v2.0. This brings some breaking changes. Please see the documentation in\nthe wiki for v1 docs.  It is recommended to upgrade to v2.0.  Migration help can be found at the end of this readme.\n\n## Installation\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.uchagani\u003c/groupId\u003e\n    \u003cartifactId\u003ejunit-playwright\u003c/artifactId\u003e\n    \u003cversion\u003e3.0.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Getting Started\n\n`junit-playwright` will inject Playwright objects in your tests.  There are two different interfaces that you can implement based on the type of testing that you want to do:  Browser or API.\n\n## Browser Testing\n\n### Create a config class\n\nCreate a class and implement the `PlaywrightBrowserConfig` interface\n\n```java\npublic class DefaultBrowserConfig implements PlaywrightBrowserConfig {\n\n    @Override\n    public BrowserConfig getBrowserConfig() {\n        return new BrowserConfig()\n                .chromium()\n                .launch();\n    }\n}\n```\n\n`PlaywrightBrowserConfig` has one method: `getBrowserConfig`. Through the `BrowserConfig` object you can specify your\nplaywright-related config. The API is similar to playwright-java. All the options that you would specify to initialize\nPlaywright, Browser, BrowserContext, or Page you can do via `BrowserConfig` object.\n\n### Writing tests\n\nTo inject Playwright objects into your test there are two parts:\n\n1. Add the `@UseBrowserConfig` annotation to your test class and specify your config class.\n2. Add the Playwright object that you need to interact with in your test as a test parameter.\n\n```java\n\n@UseBrowserConfig(DefaultBrowserConfig.class)\npublic class InjectBrowserTests {\n    @Test\n    public void someTest(Page page) {\n        page.navigate(\"https://playwright.dev/java/\");\n    }\n}\n```\n\n`junit-playwright` gives you the following Playwright-related test parameters:\n\n* [Playwright](https://playwright.dev/java/docs/api/class-playwright)\n* [Browser](https://playwright.dev/docs/api/class-browser)\n* [BrowserContext](https://playwright.dev/java/docs/api/class-browsercontext)\n* [Page](https://playwright.dev/java/docs/api/class-page)\n\n## API Testing\n\nTwo use Playwright's [APIRequestContext](https://playwright.dev/java/docs/api/class-apirequestcontext) you need to implement the `PlaywrightRestConfig` interface:\n\n```java\npublic class DefaultRestConfig implements PlaywrightRestConfig {\n    @Override\n    public RestConfig getRestConfig() {\n        return new RestConfig();\n    }\n}\n```\n\nThen you can use this config in your tests:\n\n```java\n@UseRestConfig(DefaultRestConfig.class)\npublic class APIRequestContextTests {\n    @Test\n    public void someAPITest(APIRequestContext request) {\n        request.get(\"https://api.coindesk.com/v1/bpi/currentprice.json\");\n    }\n}\n```\n\n`@UseBrowserConfig` annotation can be used either at the class level, method level.  \n`@UseRestConfig` annotation can be used either at the class level, method leve, or parameter level.\n\n## Running tests in parallel\n\n`playwright-junit` makes it easy to run tests in parallel. Each test will get an isolated Playwright environment. All\nyou have to do is enable parallel tests in junit. The easiest way to do this is to create a file in your classpath\ncalled `junit-platform.properties`. For example:\n`src/test/resources/junit-platform.properties` and enable parallel tests:\n\n```properties\njunit.jupiter.execution.parallel.enabled=true\njunit.jupiter.execution.parallel.mode.default=concurrent\njunit.jupiter.execution.parallel.mode.classes.default=concurrent\n```\n\nYou can read more about running junit tests in parallel\nin [their documentation](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution). With the\nabove configuration tests in the same class will be run in parallel.\n\n## Examples\n\nPlease take a look at the tests located int `src/test/java/io/github/uchagani/jp` for more information on how to create\nconfigs and create tests.\n\n## Advanced\n\nYou can override the config for a particular test method by adding the `@UseBrowserConfig` annotation over a test\nmethod:\n\n### Overriding config\n\n```java\n\n@UseBrowserConfig(DefaultConfig.class)\npublic class InjectBrowserTests {\n    @Test\n    public void createAChromeBrowser(Browser browser) {\n        //Browser is configured with the `DefaultConfig` specified at the class level\n    }\n\n    @Test\n    @UseBrowserConfig(OverrideConfig.class)\n    public void createAFirefoxBrowser(Browser browser) {\n        //For this test, use the browser configured in the `OverrideConfig` class\n    }\n}\n```\n\n### Testing multiple APIs in one test\n\n```java\n@Test\npublic void useDifferentConfigsInTheSameTest(@UseRestConfig(\n        SpecificRestConfig.class) APIRequestContext specificRequest, @UseRestConfig(\n        OverrideRestConfig.class) APIRequestContext overrideRequest) {\n    \n    assertThat(specificRequest).isNotNull();\n    assertThat(overrideRequest).isNotNull();\n    assertThat(specificRequest.get(\"/foo\").url()).contains(\"google.com/foo\");\n    assertThat(overrideRequest.get(\"/foo\").url()).contains(\"bing.com/foo\");\n}\n```\n\n\n## Requirements\n\n* Java 8+\n* Playwright 1.18.0+\n* JUnit 5.6+\n\n## Migrating from v1\n\nTo migrate to v2.x from v1.x, there are a couple of changes that you need to make:\n\n1.  Change `PlaywrightConfig` to `PlaywrightBrowserConfig`.\n2.  Change `@InjectPlaywright` to `@UseBrowserConfig`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuchagani%2Fjunit-playwright","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuchagani%2Fjunit-playwright","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuchagani%2Fjunit-playwright/lists"}