2222
2323import java .net .URI ;
2424import java .util .function .Predicate ;
25- import org .junit .jupiter .api .AfterEach ;
26- import org .junit .jupiter .api .BeforeEach ;
2725import org .junit .jupiter .api .Test ;
28- import org .openqa .selenium .environment .webserver .AppServer ;
29- import org .openqa .selenium .environment .webserver .NettyAppServer ;
3026import org .openqa .selenium .remote .RemoteWebDriver ;
3127import org .openqa .selenium .testing .Ignore ;
3228import org .openqa .selenium .testing .JupiterTestBase ;
29+ import org .openqa .selenium .testing .NeedsFreshDriver ;
3330import org .openqa .selenium .testing .drivers .Browser ;
3431
3532class WebNetworkTest extends JupiterTestBase {
3633
3734 private String page ;
38- private AppServer server ;
39-
40- @ BeforeEach
41- public void setUp () {
42- server = new NettyAppServer ();
43- server .start ();
44- }
45-
46- @ AfterEach
47- public void cleanUp () {
48- driver .quit ();
49- }
5035
5136 @ Test
37+ @ NeedsFreshDriver
5238 @ Ignore (Browser .CHROME )
5339 @ Ignore (Browser .EDGE )
5440 void canAddAuthenticationHandler () {
5541 ((RemoteWebDriver ) driver )
5642 .network ()
5743 .addAuthenticationHandler (new UsernameAndPassword ("test" , "test" ));
5844
59- page = server .whereIs ("basicAuth" );
45+ page = appServer .whereIs ("basicAuth" );
6046 driver .get (page );
6147
6248 assertThat (driver .findElement (By .tagName ("h1" )).getText ()).isEqualTo ("authorized" );
6349 }
6450
6551 @ Test
52+ @ NeedsFreshDriver
6653 @ Ignore (Browser .CHROME )
6754 @ Ignore (Browser .EDGE )
6855 void canAddAuthenticationHandlerWithFilter () {
@@ -72,13 +59,14 @@ void canAddAuthenticationHandlerWithFilter() {
7259 .network ()
7360 .addAuthenticationHandler (filter , new UsernameAndPassword ("test" , "test" ));
7461
75- page = server .whereIs ("basicAuth" );
62+ page = appServer .whereIs ("basicAuth" );
7663 driver .get (page );
7764
7865 assertThat (driver .findElement (By .tagName ("h1" )).getText ()).isEqualTo ("authorized" );
7966 }
8067
8168 @ Test
69+ @ NeedsFreshDriver
8270 @ Ignore (Browser .CHROME )
8371 @ Ignore (Browser .EDGE )
8472 void canAddMultipleAuthenticationHandlersWithFilter () {
@@ -92,13 +80,14 @@ void canAddMultipleAuthenticationHandlersWithFilter() {
9280 .addAuthenticationHandler (
9381 uri -> uri .getPath ().contains ("test" ), new UsernameAndPassword ("test1" , "test1" ));
9482
95- page = server .whereIs ("basicAuth" );
83+ page = appServer .whereIs ("basicAuth" );
9684 driver .get (page );
9785
9886 assertThat (driver .findElement (By .tagName ("h1" )).getText ()).isEqualTo ("authorized" );
9987 }
10088
10189 @ Test
90+ @ NeedsFreshDriver
10291 @ Ignore (Browser .CHROME )
10392 @ Ignore (Browser .EDGE )
10493 void canAddMultipleAuthenticationHandlersWithTheSameFilter () {
@@ -112,13 +101,14 @@ void canAddMultipleAuthenticationHandlersWithTheSameFilter() {
112101 .addAuthenticationHandler (
113102 uri -> uri .getPath ().contains ("basicAuth" ), new UsernameAndPassword ("test" , "test" ));
114103
115- page = server .whereIs ("basicAuth" );
104+ page = appServer .whereIs ("basicAuth" );
116105 driver .get (page );
117106
118107 assertThat (driver .findElement (By .tagName ("h1" )).getText ()).isEqualTo ("authorized" );
119108 }
120109
121110 @ Test
111+ @ NeedsFreshDriver
122112 @ Ignore (Browser .CHROME )
123113 @ Ignore (Browser .EDGE )
124114 void canRemoveAuthenticationHandler () {
@@ -128,26 +118,28 @@ void canRemoveAuthenticationHandler() {
128118 .addAuthenticationHandler (new UsernameAndPassword ("test" , "test" ));
129119
130120 ((RemoteWebDriver ) driver ).network ().removeAuthenticationHandler (id );
131- page = server .whereIs ("basicAuth" );
121+ page = appServer .whereIs ("basicAuth" );
132122 driver .get (page );
133123
134124 assertThatExceptionOfType (UnhandledAlertException .class )
135125 .isThrownBy (() -> driver .findElement (By .tagName ("h1" )));
136126 }
137127
138128 @ Test
129+ @ NeedsFreshDriver
139130 @ Ignore (Browser .CHROME )
140131 @ Ignore (Browser .EDGE )
141132 void canRemoveAuthenticationHandlerThatDoesNotExist () {
142133 ((RemoteWebDriver ) driver ).network ().removeAuthenticationHandler (5 );
143- page = server .whereIs ("basicAuth" );
134+ page = appServer .whereIs ("basicAuth" );
144135 driver .get (page );
145136
146137 assertThatExceptionOfType (UnhandledAlertException .class )
147138 .isThrownBy (() -> driver .findElement (By .tagName ("h1" )));
148139 }
149140
150141 @ Test
142+ @ NeedsFreshDriver
151143 @ Ignore (Browser .CHROME )
152144 @ Ignore (Browser .EDGE )
153145 void canClearAuthenticationHandlers () {
@@ -165,7 +157,7 @@ void canClearAuthenticationHandlers() {
165157 .addAuthenticationHandler (new UsernameAndPassword ("test1" , "test1" ));
166158
167159 ((RemoteWebDriver ) driver ).network ().clearAuthenticationHandlers ();
168- page = server .whereIs ("basicAuth" );
160+ page = appServer .whereIs ("basicAuth" );
169161 driver .get (page );
170162
171163 assertThatExceptionOfType (UnhandledAlertException .class )
0 commit comments