2828import java .util .concurrent .atomic .AtomicReference ;
2929import java .util .function .Consumer ;
3030import org .assertj .core .api .Assertions ;
31- import org .junit .jupiter .api .AfterEach ;
32- import org .junit .jupiter .api .BeforeEach ;
3331import org .junit .jupiter .api .Test ;
3432import org .openqa .selenium .bidi .log .ConsoleLogEntry ;
3533import org .openqa .selenium .bidi .log .JavascriptLogEntry ;
3634import org .openqa .selenium .bidi .log .LogLevel ;
37- import org .openqa .selenium .environment .webserver .AppServer ;
38- import org .openqa .selenium .environment .webserver .NettyAppServer ;
3935import org .openqa .selenium .remote .DomMutation ;
4036import org .openqa .selenium .remote .RemoteWebDriver ;
4137import org .openqa .selenium .support .ui .WebDriverWait ;
4238import org .openqa .selenium .testing .JupiterTestBase ;
39+ import org .openqa .selenium .testing .NeedsFreshDriver ;
4340
4441class WebScriptTest extends JupiterTestBase {
4542
4643 String page ;
47- private AppServer server ;
48-
49- @ BeforeEach
50- public void setUp () {
51- server = new NettyAppServer ();
52- server .start ();
53- }
54-
55- @ AfterEach
56- public void cleanUp () {
57- driver .quit ();
58- }
5944
6045 @ Test
46+ @ NeedsFreshDriver
6147 void canAddConsoleMessageHandler ()
6248 throws ExecutionException , InterruptedException , TimeoutException {
6349 CompletableFuture <ConsoleLogEntry > future = new CompletableFuture <>();
6450
6551 long id = ((RemoteWebDriver ) driver ).script ().addConsoleMessageHandler (future ::complete );
6652
67- page = server .whereIs ("/bidi/logEntryAdded.html" );
53+ page = appServer .whereIs ("/bidi/logEntryAdded.html" );
6854 driver .get (page );
6955 driver .findElement (By .id ("consoleLog" )).click ();
7056
@@ -81,6 +67,7 @@ void canAddConsoleMessageHandler()
8167 }
8268
8369 @ Test
70+ @ NeedsFreshDriver
8471 void canRemoveConsoleMessageHandler ()
8572 throws ExecutionException , InterruptedException , TimeoutException {
8673 CompletableFuture <ConsoleLogEntry > future1 = new CompletableFuture <>();
@@ -96,7 +83,7 @@ void canRemoveConsoleMessageHandler()
9683 // Removing the second consumer, so it will no longer get the console message.
9784 ((RemoteWebDriver ) driver ).script ().removeConsoleMessageHandler (id2 );
9885
99- page = server .whereIs ("/bidi/logEntryAdded.html" );
86+ page = appServer .whereIs ("/bidi/logEntryAdded.html" );
10087 driver .get (page );
10188 driver .findElement (By .id ("consoleLog" )).click ();
10289
@@ -113,12 +100,13 @@ void canRemoveConsoleMessageHandler()
113100 }
114101
115102 @ Test
103+ @ NeedsFreshDriver
116104 void canAddJsErrorHandler () throws ExecutionException , InterruptedException , TimeoutException {
117105 CompletableFuture <JavascriptLogEntry > future = new CompletableFuture <>();
118106
119107 long id = ((RemoteWebDriver ) driver ).script ().addJavaScriptErrorHandler (future ::complete );
120108
121- page = server .whereIs ("/bidi/logEntryAdded.html" );
109+ page = appServer .whereIs ("/bidi/logEntryAdded.html" );
122110 driver .get (page );
123111 driver .findElement (By .id ("jsException" )).click ();
124112
@@ -132,6 +120,7 @@ void canAddJsErrorHandler() throws ExecutionException, InterruptedException, Tim
132120 }
133121
134122 @ Test
123+ @ NeedsFreshDriver
135124 void canRemoveJsErrorHandler () throws ExecutionException , InterruptedException , TimeoutException {
136125 CompletableFuture <JavascriptLogEntry > future1 = new CompletableFuture <>();
137126 CompletableFuture <JavascriptLogEntry > future2 = new CompletableFuture <>();
@@ -146,7 +135,7 @@ void canRemoveJsErrorHandler() throws ExecutionException, InterruptedException,
146135 // Removing the second consumer, so it will no longer get the JS error.
147136 ((RemoteWebDriver ) driver ).script ().removeJavaScriptErrorHandler (id2 );
148137
149- page = server .whereIs ("/bidi/logEntryAdded.html" );
138+ page = appServer .whereIs ("/bidi/logEntryAdded.html" );
150139 driver .get (page );
151140 driver .findElement (By .id ("jsException" )).click ();
152141
@@ -166,6 +155,7 @@ void canRemoveJsErrorHandler() throws ExecutionException, InterruptedException,
166155 }
167156
168157 @ Test
158+ @ NeedsFreshDriver
169159 void canAddMultipleHandlers () throws ExecutionException , InterruptedException , TimeoutException {
170160 CompletableFuture <JavascriptLogEntry > future1 = new CompletableFuture <>();
171161 CompletableFuture <JavascriptLogEntry > future2 = new CompletableFuture <>();
@@ -177,7 +167,7 @@ void canAddMultipleHandlers() throws ExecutionException, InterruptedException, T
177167 long id1 = ((RemoteWebDriver ) driver ).script ().addJavaScriptErrorHandler (consumer1 );
178168 long id2 = ((RemoteWebDriver ) driver ).script ().addJavaScriptErrorHandler (consumer2 );
179169
180- page = server .whereIs ("/bidi/logEntryAdded.html" );
170+ page = appServer .whereIs ("/bidi/logEntryAdded.html" );
181171 driver .get (page );
182172 driver .findElement (By .id ("jsException" )).click ();
183173
@@ -193,6 +183,7 @@ void canAddMultipleHandlers() throws ExecutionException, InterruptedException, T
193183 }
194184
195185 @ Test
186+ @ NeedsFreshDriver
196187 void canAddDomMutationHandler () throws InterruptedException {
197188 AtomicReference <DomMutation > seen = new AtomicReference <>();
198189 CountDownLatch latch = new CountDownLatch (1 );
@@ -220,6 +211,7 @@ void canAddDomMutationHandler() throws InterruptedException {
220211 }
221212
222213 @ Test
214+ @ NeedsFreshDriver
223215 void canRemoveDomMutationHandler () throws InterruptedException {
224216 AtomicReference <DomMutation > seen = new AtomicReference <>();
225217 CountDownLatch latch = new CountDownLatch (1 );
@@ -247,14 +239,15 @@ void canRemoveDomMutationHandler() throws InterruptedException {
247239 }
248240
249241 @ Test
242+ @ NeedsFreshDriver
250243 void canPinScript () throws ExecutionException , InterruptedException , TimeoutException {
251244 CompletableFuture <ConsoleLogEntry > future = new CompletableFuture <>();
252245
253246 ((RemoteWebDriver ) driver ).script ().pin ("() => { console.log('Hello!'); }" );
254247
255248 long id = ((RemoteWebDriver ) driver ).script ().addConsoleMessageHandler (future ::complete );
256249
257- page = server .whereIs ("/bidi/logEntryAdded.html" );
250+ page = appServer .whereIs ("/bidi/logEntryAdded.html" );
258251 driver .get (page );
259252
260253 ConsoleLogEntry logEntry = future .get (5 , TimeUnit .SECONDS );
@@ -265,6 +258,7 @@ void canPinScript() throws ExecutionException, InterruptedException, TimeoutExce
265258 }
266259
267260 @ Test
261+ @ NeedsFreshDriver
268262 void canUnpinScript () throws ExecutionException , InterruptedException , TimeoutException {
269263 CountDownLatch latch = new CountDownLatch (2 );
270264
@@ -276,7 +270,7 @@ void canUnpinScript() throws ExecutionException, InterruptedException, TimeoutEx
276270 .script ()
277271 .addConsoleMessageHandler (consoleLogEntry -> latch .countDown ());
278272
279- page = server .whereIs ("/bidi/logEntryAdded.html" );
273+ page = appServer .whereIs ("/bidi/logEntryAdded.html" );
280274
281275 driver .get (page );
282276
0 commit comments