Skip to content

Commit 7773f7b

Browse files
committed
[java] fixed the NetworkInterceptor tests
1 parent 06ee06b commit 7773f7b

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

java/test/org/openqa/selenium/devtools/NetworkInterceptorRestTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.net.MalformedURLException;
2727
import java.net.URL;
28+
import java.util.Objects;
2829
import java.util.concurrent.atomic.AtomicBoolean;
2930
import org.junit.jupiter.api.AfterEach;
3031
import org.junit.jupiter.api.BeforeAll;
@@ -36,8 +37,8 @@
3637
import org.openqa.selenium.remote.http.HttpMethod;
3738
import org.openqa.selenium.remote.http.HttpResponse;
3839
import org.openqa.selenium.remote.http.Route;
39-
import org.openqa.selenium.testing.Ignore;
4040
import org.openqa.selenium.testing.JupiterTestBase;
41+
import org.openqa.selenium.testing.NoDriverBeforeTest;
4142
import org.openqa.selenium.testing.drivers.Browser;
4243
import org.openqa.selenium.testing.drivers.WebDriverBuilder;
4344

@@ -56,7 +57,7 @@ public static void shouldTestBeRunAtAll() {
5657

5758
@BeforeEach
5859
public void setup() {
59-
driver = new WebDriverBuilder().get();
60+
driver = new WebDriverBuilder().get(Objects.requireNonNull(Browser.detect()).getCapabilities());
6061

6162
assumeThat(driver).isInstanceOf(HasDevTools.class);
6263
assumeThat(isFirefoxVersionOlderThan(87, driver)).isFalse();
@@ -81,7 +82,7 @@ public void tearDown() {
8182
}
8283

8384
@Test
84-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally. Needs debugging.")
85+
@NoDriverBeforeTest
8586
void shouldInterceptPatchRequest() throws MalformedURLException {
8687
AtomicBoolean seen = new AtomicBoolean(false);
8788
interceptor =
@@ -118,7 +119,7 @@ void shouldInterceptPatchRequest() throws MalformedURLException {
118119
}
119120

120121
@Test
121-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally. Needs debugging.")
122+
@NoDriverBeforeTest
122123
void shouldInterceptPutRequest() throws MalformedURLException {
123124
AtomicBoolean seen = new AtomicBoolean(false);
124125
interceptor =
@@ -155,6 +156,7 @@ void shouldInterceptPutRequest() throws MalformedURLException {
155156
}
156157

157158
@Test
159+
@NoDriverBeforeTest
158160
void shouldInterceptPostRequest() throws MalformedURLException {
159161
AtomicBoolean seen = new AtomicBoolean(false);
160162
interceptor =
@@ -191,7 +193,7 @@ void shouldInterceptPostRequest() throws MalformedURLException {
191193
}
192194

193195
@Test
194-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally.")
196+
@NoDriverBeforeTest
195197
void shouldInterceptDeleteRequest() throws MalformedURLException {
196198
AtomicBoolean seen = new AtomicBoolean(false);
197199
interceptor =
@@ -228,7 +230,7 @@ void shouldInterceptDeleteRequest() throws MalformedURLException {
228230
}
229231

230232
@Test
231-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally.")
233+
@NoDriverBeforeTest
232234
void shouldInterceptGetRequest() throws MalformedURLException {
233235
AtomicBoolean seen = new AtomicBoolean(false);
234236
interceptor =

java/test/org/openqa/selenium/devtools/NetworkInterceptorTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.openqa.selenium.testing.TestUtilities.isFirefoxVersionOlderThan;
2828

2929
import com.google.common.net.MediaType;
30+
import java.util.Objects;
3031
import java.util.concurrent.atomic.AtomicBoolean;
3132
import org.junit.jupiter.api.AfterEach;
3233
import org.junit.jupiter.api.BeforeAll;
@@ -39,8 +40,8 @@
3940
import org.openqa.selenium.remote.http.Filter;
4041
import org.openqa.selenium.remote.http.HttpResponse;
4142
import org.openqa.selenium.remote.http.Route;
42-
import org.openqa.selenium.testing.Ignore;
4343
import org.openqa.selenium.testing.JupiterTestBase;
44+
import org.openqa.selenium.testing.NoDriverBeforeTest;
4445
import org.openqa.selenium.testing.drivers.Browser;
4546
import org.openqa.selenium.testing.drivers.WebDriverBuilder;
4647

@@ -59,7 +60,7 @@ public static void shouldTestBeRunAtAll() {
5960

6061
@BeforeEach
6162
public void setup() {
62-
driver = new WebDriverBuilder().get();
63+
driver = new WebDriverBuilder().get(Objects.requireNonNull(Browser.detect()).getCapabilities());
6364

6465
assumeThat(driver).isInstanceOf(HasDevTools.class);
6566
assumeThat(isFirefoxVersionOlderThan(87, driver)).isFalse();
@@ -96,7 +97,7 @@ public void tearDown() {
9697
}
9798

9899
@Test
99-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally. Needs debugging.")
100+
@NoDriverBeforeTest
100101
void shouldProceedAsNormalIfRequestIsNotIntercepted() {
101102
interceptor =
102103
new NetworkInterceptor(
@@ -110,7 +111,7 @@ void shouldProceedAsNormalIfRequestIsNotIntercepted() {
110111
}
111112

112113
@Test
113-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally. Needs debugging.")
114+
@NoDriverBeforeTest
114115
void shouldAllowTheInterceptorToChangeTheResponse() {
115116
interceptor =
116117
new NetworkInterceptor(
@@ -132,7 +133,7 @@ void shouldAllowTheInterceptorToChangeTheResponse() {
132133
}
133134

134135
@Test
135-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally. Needs debugging.")
136+
@NoDriverBeforeTest
136137
void shouldBeAbleToReturnAMagicResponseThatCausesTheOriginalRequestToProceed() {
137138
AtomicBoolean seen = new AtomicBoolean(false);
138139

@@ -156,6 +157,7 @@ void shouldBeAbleToReturnAMagicResponseThatCausesTheOriginalRequestToProceed() {
156157
}
157158

158159
@Test
160+
@NoDriverBeforeTest
159161
void shouldClearListenersWhenNetworkInterceptorIsClosed() {
160162
try (NetworkInterceptor interceptor =
161163
new NetworkInterceptor(
@@ -181,7 +183,7 @@ void shouldClearListenersWhenNetworkInterceptorIsClosed() {
181183
}
182184

183185
@Test
184-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally. Needs debugging.")
186+
@NoDriverBeforeTest
185187
void shouldBeAbleToInterceptAResponse() {
186188
try (NetworkInterceptor networkInterceptor =
187189
new NetworkInterceptor(
@@ -190,7 +192,7 @@ void shouldBeAbleToInterceptAResponse() {
190192
next ->
191193
req -> {
192194
HttpResponse res = next.execute(req);
193-
res.addHeader("Content-Type", MediaType.HTML_UTF_8.toString());
195+
res.setHeader("Content-Type", MediaType.HTML_UTF_8.toString());
194196
res.setContent(Contents.utf8String("Sausages"));
195197
return res;
196198
})) {
@@ -203,7 +205,7 @@ void shouldBeAbleToInterceptAResponse() {
203205
}
204206

205207
@Test
206-
@Ignore(gitHubActions = true, reason = "Fails in GH Actions but passes locally. Needs debugging.")
208+
@NoDriverBeforeTest
207209
void shouldHandleRedirects() {
208210
try (NetworkInterceptor networkInterceptor =
209211
new NetworkInterceptor(driver, (Filter) next -> next)) {

0 commit comments

Comments
 (0)