|
16 | 16 |
|
17 | 17 | package com.microsoft.playwright.junit; |
18 | 18 |
|
| 19 | +import com.microsoft.playwright.Browser; |
19 | 20 | import com.microsoft.playwright.junit.impl.*; |
20 | 21 | import org.junit.jupiter.api.extension.ExtendWith; |
21 | 22 |
|
|
24 | 25 | import java.lang.annotation.RetentionPolicy; |
25 | 26 | import java.lang.annotation.Target; |
26 | 27 |
|
| 28 | +/** |
| 29 | + * <strong>NOTE:</strong> this API is experimental and is subject to changes. |
| 30 | + * |
| 31 | + * Use {@code @UsePlaywright} annotation to automatically manage Playwright objects |
| 32 | + * used in your test. Custom configuration can be provided by implementing |
| 33 | + * {@link OptionsFactory} and passing the class as a parameter. |
| 34 | + * |
| 35 | + * <p> When a test class is annotated with {@code @UsePlaywright} each test method can |
| 36 | + * use any of the following arguments that will be automatically created at run time: |
| 37 | + * <ul> |
| 38 | + * <li> {@link com.microsoft.playwright.Page Page page}</li> |
| 39 | + * <li> {@link com.microsoft.playwright.BrowserContext BrowserContext context}</li> |
| 40 | + * <li> {@link com.microsoft.playwright.Browser Browser browser}</li> |
| 41 | + * <li> {@link com.microsoft.playwright.APIRequestContext APIRequestContext request}</li> |
| 42 | + * <li> {@link com.microsoft.playwright.Playwright Playwright playwright}</li> |
| 43 | + * </ul> |
| 44 | + * {@code Page} and {@code BrowserContext} are created before each test and closed |
| 45 | + * after the test has finished. {@code Browser} and {@code Playwright} are reused |
| 46 | + * between tests for better efficiency. |
| 47 | + * |
| 48 | + * <p> An example of using {@code @UsePlaywright} annotation: |
| 49 | + * <pre>{@code |
| 50 | + * import com.microsoft.playwright.Browser; |
| 51 | + * import com.microsoft.playwright.BrowserContext; |
| 52 | + * import com.microsoft.playwright.Page; |
| 53 | + * import org.junit.jupiter.api.Test; |
| 54 | + * |
| 55 | + * import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; |
| 56 | + * import static org.junit.jupiter.api.Assertions.assertEquals; |
| 57 | + * import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 58 | + * |
| 59 | + * @UsePlaywright |
| 60 | + * public class TestExample { |
| 61 | + * @Test |
| 62 | + * void shouldProvidePage(Page page) { |
| 63 | + * page.navigate("https://playwright.dev"); |
| 64 | + * assertThat(page).hasURL("https://playwright.dev/"); |
| 65 | + * } |
| 66 | + * |
| 67 | + * @Test |
| 68 | + * void shouldResolvePlaywrightObjects(Page page, BrowserContext context, Browser browser) { |
| 69 | + * assertEquals(context, page.context()); |
| 70 | + * assertEquals(browser, context.browser()); |
| 71 | + * assertNotNull(browser.version()); |
| 72 | + * } |
| 73 | + * } |
| 74 | + * }</pre> |
| 75 | + * |
| 76 | + * <p> For more details and usage examples see our |
| 77 | + * <a href="https://playwright.dev/java/docs/junit">JUnit guide</a>. |
| 78 | + */ |
27 | 79 | @ExtendWith({OptionsExtension.class, PlaywrightExtension.class, BrowserExtension.class, BrowserContextExtension.class, |
28 | 80 | PageExtension.class, APIRequestContextExtension.class}) |
29 | 81 | @Retention(RetentionPolicy.RUNTIME) |
|
0 commit comments