|
18 | 18 | package org.openqa.selenium.bidi.network;
|
19 | 19 |
|
20 | 20 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
| 21 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
21 | 22 | import static org.openqa.selenium.testing.Safely.safelyCall;
|
22 | 23 | import static org.openqa.selenium.testing.drivers.Browser.EDGE;
|
23 | 24 | import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
|
|
27 | 28 | import org.junit.jupiter.api.AfterEach;
|
28 | 29 | import org.junit.jupiter.api.BeforeEach;
|
29 | 30 | import org.junit.jupiter.api.Test;
|
| 31 | +import org.openqa.selenium.Alert; |
| 32 | +import org.openqa.selenium.By; |
| 33 | +import org.openqa.selenium.TimeoutException; |
| 34 | +import org.openqa.selenium.UsernameAndPassword; |
30 | 35 | import org.openqa.selenium.bidi.Network;
|
31 | 36 | import org.openqa.selenium.environment.webserver.AppServer;
|
32 | 37 | import org.openqa.selenium.environment.webserver.NettyAppServer;
|
| 38 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
33 | 39 | import org.openqa.selenium.testing.JupiterTestBase;
|
34 | 40 | import org.openqa.selenium.testing.NotYetImplemented;
|
35 | 41 |
|
36 | 42 | class NetworkCommandsTest extends JupiterTestBase {
|
| 43 | + private String page; |
37 | 44 | private AppServer server;
|
38 | 45 |
|
39 | 46 | @BeforeEach
|
@@ -70,6 +77,65 @@ void canRemoveIntercept() {
|
70 | 77 | }
|
71 | 78 | }
|
72 | 79 |
|
| 80 | + @Test |
| 81 | + @NotYetImplemented(SAFARI) |
| 82 | + @NotYetImplemented(IE) |
| 83 | + @NotYetImplemented(EDGE) |
| 84 | + @NotYetImplemented(FIREFOX) |
| 85 | + void canContinueWithAuthCredentials() { |
| 86 | + try (Network network = new Network(driver)) { |
| 87 | + network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED)); |
| 88 | + network.onAuthRequired( |
| 89 | + responseDetails -> |
| 90 | + network.continueWithAuth( |
| 91 | + responseDetails.getRequest().getRequestId(), |
| 92 | + new UsernameAndPassword("test", "test"))); |
| 93 | + |
| 94 | + page = server.whereIs("basicAuth"); |
| 95 | + driver.get(page); |
| 96 | + assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized"); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + @NotYetImplemented(SAFARI) |
| 102 | + @NotYetImplemented(IE) |
| 103 | + @NotYetImplemented(EDGE) |
| 104 | + @NotYetImplemented(FIREFOX) |
| 105 | + void canContinueWithoutAuthCredentials() { |
| 106 | + try (Network network = new Network(driver)) { |
| 107 | + network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED)); |
| 108 | + network.onAuthRequired( |
| 109 | + responseDetails -> |
| 110 | + // Does not handle the alert |
| 111 | + network.continueWithAuthNoCredentials(responseDetails.getRequest().getRequestId())); |
| 112 | + page = server.whereIs("basicAuth"); |
| 113 | + driver.get(page); |
| 114 | + // This would fail if alert was handled |
| 115 | + Alert alert = wait.until(ExpectedConditions.alertIsPresent()); |
| 116 | + alert.dismiss(); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + @NotYetImplemented(SAFARI) |
| 122 | + @NotYetImplemented(IE) |
| 123 | + @NotYetImplemented(EDGE) |
| 124 | + @NotYetImplemented(FIREFOX) |
| 125 | + void canCancelAuth() { |
| 126 | + try (Network network = new Network(driver)) { |
| 127 | + network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED)); |
| 128 | + network.onAuthRequired( |
| 129 | + responseDetails -> |
| 130 | + // Does not handle the alert |
| 131 | + network.cancelAuth(responseDetails.getRequest().getRequestId())); |
| 132 | + page = server.whereIs("basicAuth"); |
| 133 | + driver.get(page); |
| 134 | + assertThatThrownBy(() -> wait.until(ExpectedConditions.alertIsPresent())) |
| 135 | + .isInstanceOf(TimeoutException.class); |
| 136 | + } |
| 137 | + } |
| 138 | + |
73 | 139 | @AfterEach
|
74 | 140 | public void quitDriver() {
|
75 | 141 | if (driver != null) {
|
|
0 commit comments