|
1 | 1 | package com.serenitydojo.playwright; |
2 | 2 |
|
3 | | -import com.microsoft.playwright.Browser; |
4 | | -import com.microsoft.playwright.BrowserType; |
5 | | -import com.microsoft.playwright.Page; |
6 | | -import com.microsoft.playwright.Playwright; |
7 | | -import org.junit.jupiter.api.AfterEach; |
8 | | -import org.junit.jupiter.api.Assertions; |
9 | | -import org.junit.jupiter.api.BeforeEach; |
10 | | -import org.junit.jupiter.api.Test; |
| 3 | +import com.microsoft.playwright.*; |
| 4 | +import org.junit.jupiter.api.*; |
11 | 5 |
|
12 | 6 | import java.util.Arrays; |
13 | 7 |
|
14 | 8 | public class ASimplePlaywrightTest { |
15 | 9 |
|
16 | | - Playwright playwright; |
17 | | - Browser browser; |
| 10 | + private static Playwright playwright; |
| 11 | + private static Browser browser; |
| 12 | + private static BrowserContext browserContext; |
| 13 | + |
18 | 14 | Page page; |
19 | 15 |
|
20 | | - @BeforeEach |
21 | | - public void setUp() { |
| 16 | + @BeforeAll |
| 17 | + public static void setUpBrowser() { |
22 | 18 | playwright = Playwright.create(); |
23 | 19 | browser = playwright.chromium().launch( |
24 | 20 | new BrowserType.LaunchOptions() |
25 | | -// .setHeadless(false) |
| 21 | + .setHeadless(false) |
26 | 22 | .setArgs(Arrays.asList("--no-sandbox","--disable-extensions","--disable-gpu")) |
27 | 23 | ); |
28 | | - page = browser.newPage(); |
| 24 | + browserContext = browser.newContext(); |
| 25 | + } |
| 26 | + |
| 27 | + @BeforeEach |
| 28 | + public void setUp() { |
| 29 | + page = browserContext.newPage(); |
29 | 30 | } |
30 | 31 |
|
31 | | - @AfterEach |
32 | | - public void tearDown() { |
| 32 | + @AfterAll |
| 33 | + public static void tearDown() { |
33 | 34 | browser.close(); |
34 | 35 | playwright.close(); |
35 | 36 | } |
|
0 commit comments