2020@ Slf4j
2121public class WebBaseTest {
2222
23- protected static ThreadLocal <Page > page = new ThreadLocal <>();
23+ protected static final ThreadLocal <Page > PAGE = new ThreadLocal <>();
2424 private static final ThreadLocal <Playwright > PLAYWRIGHT = new ThreadLocal <>();
2525 private static BrowserManager browserManager ;
2626
@@ -33,9 +33,9 @@ public void setUp() {
3333 @ BeforeMethod (alwaysRun = true )
3434 public void init (Method method ) {
3535 PLAYWRIGHT .set (Playwright .create ());
36- page .set (browserManager .getBrowserPage (PLAYWRIGHT .get ()));
36+ PAGE .set (browserManager .getBrowserPage (PLAYWRIGHT .get ()));
3737 log .info ("Browser has been set." );
38- WebTestListeners .setPage (page .get ());
38+ WebTestListeners .setPage (PAGE .get ());
3939 if (isChromiumBrowser ()) {
4040 initializeCdpSession ();
4141 }
@@ -44,7 +44,7 @@ public void init(Method method) {
4444
4545 private void initializeCdpSession () {
4646 if (isChromiumBrowser ()) {
47- CdpUtils .initializeCdpSession (page .get ());
47+ CdpUtils .initializeCdpSession (PAGE .get ());
4848 CdpUtils .enableCdpSession ();
4949 CdpUtils .sendCommand (CdpCommands .NETWORK_ENABLE .getDescription ());
5050 CdpUtils .logErrorResponses ();
@@ -60,17 +60,17 @@ private void initializeCdpSession() {
6060 }
6161
6262 private void trackPerformanceMetrics (String methodName ) {
63- PerformanceUtils .evaluatePageLoadTime (page .get (), methodName );
64- PerformanceUtils .evaluateDomContentLoadTime (page .get (), methodName );
63+ PerformanceUtils .evaluatePageLoadTime (PAGE .get (), methodName );
64+ PerformanceUtils .evaluateDomContentLoadTime (PAGE .get (), methodName );
6565 }
6666
6767 @ AfterMethod (alwaysRun = true )
6868 public void destroy () {
6969 if (isChromiumBrowser ()) {
7070 CdpUtils .destroyCdpSession ();
7171 }
72- browserManager .destroyBrowserPage (page .get ());
73- page .remove ();
72+ browserManager .destroyBrowserPage (PAGE .get ());
73+ PAGE .remove ();
7474 Objects .requireNonNull (PLAYWRIGHT .get (), "Playwright is null!" );
7575 PLAYWRIGHT .get ().close ();
7676 PLAYWRIGHT .remove ();
0 commit comments