Skip to content

Commit db6123e

Browse files
committed
add tests for setCacheBehavior
1 parent c83de44 commit db6123e

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

java/test/org/openqa/selenium/bidi/network/NetworkCommandsTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.time.Duration;
2525
import java.time.temporal.ChronoUnit;
26+
import java.util.Collections;
2627
import java.util.concurrent.CountDownLatch;
2728
import java.util.concurrent.TimeUnit;
2829
import org.junit.jupiter.api.Disabled;
@@ -32,6 +33,9 @@
3233
import org.openqa.selenium.TimeoutException;
3334
import org.openqa.selenium.UsernameAndPassword;
3435
import org.openqa.selenium.WebDriverException;
36+
import org.openqa.selenium.WindowType;
37+
import org.openqa.selenium.bidi.BiDiException;
38+
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
3539
import org.openqa.selenium.bidi.module.Network;
3640
import org.openqa.selenium.support.ui.ExpectedConditions;
3741
import org.openqa.selenium.testing.JupiterTestBase;
@@ -264,4 +268,61 @@ void canFailRequest() {
264268
assertThatThrownBy(() -> driver.get(page)).isInstanceOf(WebDriverException.class);
265269
}
266270
}
271+
272+
@Test
273+
@NeedsFreshDriver
274+
void canSetCacheBehaviorToBypass() {
275+
try (Network network = new Network(driver)) {
276+
page = appServer.whereIs("basicAuth");
277+
278+
BrowsingContext context = new BrowsingContext(driver, WindowType.TAB);
279+
String contextId = context.getId();
280+
281+
network.setCacheBehavior(
282+
new SetCacheBehaviorParameters(
283+
CacheBehavior.BYPASS, Collections.singletonList(contextId)));
284+
}
285+
}
286+
287+
@Test
288+
@NeedsFreshDriver
289+
void canSetCacheBehaviorToDefault() {
290+
try (Network network = new Network(driver)) {
291+
page = appServer.whereIs("basicAuth");
292+
293+
BrowsingContext context = new BrowsingContext(driver, WindowType.TAB);
294+
String contextId = context.getId();
295+
296+
network.setCacheBehavior(
297+
new SetCacheBehaviorParameters(
298+
CacheBehavior.DEFAULT, Collections.singletonList(contextId)));
299+
}
300+
}
301+
302+
@Test
303+
@NeedsFreshDriver
304+
void canSetCacheBehaviorWithNoContextId() {
305+
try (Network network = new Network(driver)) {
306+
page = appServer.whereIs("basicAuth");
307+
308+
network.setCacheBehavior(new SetCacheBehaviorParameters(CacheBehavior.BYPASS));
309+
network.setCacheBehavior(new SetCacheBehaviorParameters(CacheBehavior.DEFAULT));
310+
}
311+
}
312+
313+
@Test
314+
@NeedsFreshDriver
315+
void throwsExceptionForInvalidContext() {
316+
try (Network network = new Network(driver)) {
317+
page = appServer.whereIs("basicAuth");
318+
319+
assertThatThrownBy(
320+
() ->
321+
network.setCacheBehavior(
322+
new SetCacheBehaviorParameters(
323+
CacheBehavior.DEFAULT, Collections.singletonList("invalid-context"))))
324+
.isInstanceOf(BiDiException.class)
325+
.hasMessageContaining("no such frame");
326+
}
327+
}
267328
}

0 commit comments

Comments
 (0)