Skip to content

Commit 5ee26e2

Browse files
authored
Merge branch 'trunk' into set-bidi-protocol-pref
2 parents 33571e0 + 666e225 commit 5ee26e2

File tree

6 files changed

+82
-48
lines changed

6 files changed

+82
-48
lines changed

java/test/org/openqa/selenium/bidi/input/DefaultWheelTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ void shouldScrollFromViewportByGivenAmount() {
146146
.pause(3000)
147147
.getSequences());
148148

149+
wait.until(driver -> driver.findElement(By.name("nested_scrolling_frame")).isDisplayed());
150+
149151
assertTrue(inViewport(footer));
150152
}
151153

java/test/org/openqa/selenium/bidi/network/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ java_selenium_test_suite(
77
srcs = glob(["*Test.java"]),
88
browsers = [
99
"firefox",
10+
"chrome",
1011
],
1112
tags = [
1213
"selenium-remote",

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

Lines changed: 73 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919

2020
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
2121
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
22+
import static org.junit.jupiter.api.Assertions.fail;
2223
import static org.openqa.selenium.testing.drivers.Browser.*;
2324

2425
import java.time.Duration;
2526
import java.time.temporal.ChronoUnit;
2627
import java.util.Collections;
2728
import java.util.concurrent.CountDownLatch;
2829
import java.util.concurrent.TimeUnit;
30+
import java.util.concurrent.atomic.AtomicInteger;
2931
import org.junit.jupiter.api.Disabled;
3032
import org.junit.jupiter.api.Test;
31-
import org.openqa.selenium.Alert;
3233
import org.openqa.selenium.By;
33-
import org.openqa.selenium.TimeoutException;
3434
import org.openqa.selenium.UsernameAndPassword;
3535
import org.openqa.selenium.WebDriverException;
3636
import org.openqa.selenium.WindowType;
3737
import org.openqa.selenium.bidi.BiDiException;
3838
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
39+
import org.openqa.selenium.bidi.browsingcontext.ReadinessState;
3940
import org.openqa.selenium.bidi.module.Network;
40-
import org.openqa.selenium.support.ui.ExpectedConditions;
4141
import org.openqa.selenium.testing.JupiterTestBase;
4242
import org.openqa.selenium.testing.NeedsFreshDriver;
4343
import org.openqa.selenium.testing.NotYetImplemented;
@@ -47,8 +47,6 @@ class NetworkCommandsTest extends JupiterTestBase {
4747

4848
@Test
4949
@NeedsFreshDriver
50-
@NotYetImplemented(EDGE)
51-
@NotYetImplemented(CHROME)
5250
void canAddIntercept() {
5351
try (Network network = new Network(driver)) {
5452
String intercept =
@@ -60,7 +58,6 @@ void canAddIntercept() {
6058
@Test
6159
@NeedsFreshDriver
6260
@NotYetImplemented(EDGE)
63-
@NotYetImplemented(CHROME)
6461
void canContinueRequest() throws InterruptedException {
6562
try (Network network = new Network(driver)) {
6663
String intercept =
@@ -84,17 +81,17 @@ void canContinueRequest() throws InterruptedException {
8481

8582
assertThat(intercept).isNotNull();
8683

87-
driver.get(appServer.whereIs("/bidi/logEntryAdded.html"));
84+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
8885

86+
browsingContext.navigate(
87+
appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
8988
boolean countdown = latch.await(5, TimeUnit.SECONDS);
9089
assertThat(countdown).isTrue();
9190
}
9291
}
9392

9493
@Test
9594
@NeedsFreshDriver
96-
@NotYetImplemented(EDGE)
97-
@NotYetImplemented(CHROME)
9895
void canContinueResponse() throws InterruptedException {
9996
try (Network network = new Network(driver)) {
10097
String intercept =
@@ -113,7 +110,10 @@ void canContinueResponse() throws InterruptedException {
113110

114111
assertThat(intercept).isNotNull();
115112

116-
driver.get(appServer.whereIs("/bidi/logEntryAdded.html"));
113+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
114+
115+
browsingContext.navigate(
116+
appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
117117

118118
boolean countdown = latch.await(5, TimeUnit.SECONDS);
119119
assertThat(countdown).isTrue();
@@ -122,8 +122,6 @@ void canContinueResponse() throws InterruptedException {
122122

123123
@Test
124124
@NeedsFreshDriver
125-
@NotYetImplemented(EDGE)
126-
@NotYetImplemented(CHROME)
127125
void canProvideResponse() throws InterruptedException {
128126
try (Network network = new Network(driver)) {
129127
String intercept =
@@ -141,7 +139,10 @@ void canProvideResponse() throws InterruptedException {
141139

142140
assertThat(intercept).isNotNull();
143141

144-
driver.get(appServer.whereIs("/bidi/logEntryAdded.html"));
142+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
143+
144+
browsingContext.navigate(
145+
appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
145146

146147
boolean countdown = latch.await(5, TimeUnit.SECONDS);
147148
assertThat(countdown).isTrue();
@@ -174,7 +175,10 @@ void canProvideResponseWithAllParameters() throws InterruptedException {
174175

175176
assertThat(intercept).isNotNull();
176177

177-
driver.get(appServer.whereIs("/bidi/logEntryAdded.html"));
178+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
179+
180+
browsingContext.navigate(
181+
appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
178182

179183
boolean countdown = latch.await(5, TimeUnit.SECONDS);
180184
assertThat(countdown).isTrue();
@@ -185,8 +189,6 @@ void canProvideResponseWithAllParameters() throws InterruptedException {
185189

186190
@Test
187191
@NeedsFreshDriver
188-
@NotYetImplemented(EDGE)
189-
@NotYetImplemented(CHROME)
190192
void canRemoveIntercept() {
191193
try (Network network = new Network(driver)) {
192194
String intercept =
@@ -199,8 +201,6 @@ void canRemoveIntercept() {
199201

200202
@Test
201203
@NeedsFreshDriver
202-
@NotYetImplemented(EDGE)
203-
@NotYetImplemented(CHROME)
204204
void canContinueWithAuthCredentials() {
205205
try (Network network = new Network(driver)) {
206206
network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
@@ -211,52 +211,79 @@ void canContinueWithAuthCredentials() {
211211
new UsernameAndPassword("test", "test")));
212212

213213
page = appServer.whereIs("basicAuth");
214-
driver.get(page);
214+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
215+
216+
browsingContext.navigate(page, ReadinessState.COMPLETE);
217+
215218
assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized");
216219
}
217220
}
218221

219222
@Test
220223
@NeedsFreshDriver
221-
@NotYetImplemented(EDGE)
222-
@NotYetImplemented(CHROME)
223224
void canContinueWithoutAuthCredentials() {
224225
try (Network network = new Network(driver)) {
225226
network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
226227
network.onAuthRequired(
227-
responseDetails ->
228-
// Does not handle the alert
229-
network.continueWithAuthNoCredentials(responseDetails.getRequest().getRequestId()));
228+
responseDetails -> {
229+
if (responseDetails.getRequest().getUrl().contains("basicAuth")) {
230+
network.continueWithAuthNoCredentials(responseDetails.getRequest().getRequestId());
231+
}
232+
});
230233
page = appServer.whereIs("basicAuth");
231-
driver.get(page);
232-
// This would fail if alert was handled
233-
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
234-
alert.dismiss();
234+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
235+
236+
try {
237+
browsingContext.navigate(page, ReadinessState.COMPLETE);
238+
fail("Exception should be thrown");
239+
} catch (Exception e) {
240+
assertThat(e).isInstanceOf(WebDriverException.class);
241+
}
235242
}
236243
}
237244

238245
@Test
239246
@NeedsFreshDriver
240-
@NotYetImplemented(EDGE)
241-
@NotYetImplemented(CHROME)
242-
void canCancelAuth() {
247+
void canCancelAuth() throws InterruptedException {
243248
try (Network network = new Network(driver)) {
244249
network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
245250
network.onAuthRequired(
246-
responseDetails ->
251+
responseDetails -> {
252+
if (responseDetails.getRequest().getUrl().contains("basicAuth")) {
247253
// Does not handle the alert
248-
network.cancelAuth(responseDetails.getRequest().getRequestId()));
254+
network.cancelAuth(responseDetails.getRequest().getRequestId());
255+
}
256+
});
257+
258+
AtomicInteger status = new AtomicInteger();
259+
CountDownLatch latch = new CountDownLatch(1);
260+
261+
network.onResponseCompleted(
262+
responseDetails -> {
263+
if (responseDetails.getRequest().getUrl().contains("basicAuth")) {
264+
status.set(responseDetails.getResponseData().getStatus());
265+
latch.countDown();
266+
}
267+
});
268+
249269
page = appServer.whereIs("basicAuth");
250-
driver.get(page);
251-
assertThatThrownBy(() -> wait.until(ExpectedConditions.alertIsPresent()))
252-
.isInstanceOf(TimeoutException.class);
270+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
271+
272+
try {
273+
browsingContext.navigate(page, ReadinessState.COMPLETE);
274+
} catch (Exception BiDiException) {
275+
// Ignore
276+
// Only Chromium browsers throw an error because the navigation did not complete as
277+
// expected.
278+
}
279+
280+
latch.await(10, TimeUnit.SECONDS);
281+
assertThat(status.get()).isEqualTo(401);
253282
}
254283
}
255284

256285
@Test
257286
@NeedsFreshDriver
258-
@NotYetImplemented(EDGE)
259-
@NotYetImplemented(CHROME)
260287
void canFailRequest() {
261288
try (Network network = new Network(driver)) {
262289
network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT));
@@ -265,7 +292,14 @@ void canFailRequest() {
265292
page = appServer.whereIs("basicAuth");
266293
driver.manage().timeouts().pageLoadTimeout(Duration.of(5, ChronoUnit.SECONDS));
267294

268-
assertThatThrownBy(() -> driver.get(page)).isInstanceOf(WebDriverException.class);
295+
assertThatThrownBy(
296+
() -> {
297+
BrowsingContext browsingContext =
298+
new BrowsingContext(driver, driver.getWindowHandle());
299+
browsingContext.navigate(
300+
appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
301+
})
302+
.isInstanceOf(WebDriverException.class);
269303
}
270304
}
271305

java/test/org/openqa/selenium/grid/router/BUILD.bazel

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LARGE_TESTS = [
1111
"StressTest.java",
1212
]
1313

14-
FIREFOX_CHROME_ONLY_LARGE_TESTS = [
14+
FIREFOX_CHROMIUM_ONLY_LARGE_TESTS = [
1515
"RemoteWebDriverBiDiTest.java",
1616
]
1717

@@ -78,12 +78,13 @@ java_selenium_test_suite(
7878
)
7979

8080
java_selenium_test_suite(
81-
name = "firefox-chrome-only-large-tests",
81+
name = "firefox-chromium-only-large-tests",
8282
size = "large",
83-
srcs = FIREFOX_CHROME_ONLY_LARGE_TESTS,
83+
srcs = FIREFOX_CHROMIUM_ONLY_LARGE_TESTS,
8484
browsers = [
8585
"firefox",
8686
"chrome",
87+
"edge",
8788
],
8889
deps = [
8990
":support",
@@ -107,7 +108,7 @@ java_test_suite(
107108
size = "medium",
108109
srcs = glob(
109110
["*Test.java"],
110-
exclude = LARGE_TESTS + FIREFOX_CHROME_ONLY_LARGE_TESTS,
111+
exclude = LARGE_TESTS + FIREFOX_CHROMIUM_ONLY_LARGE_TESTS,
111112
),
112113
tags = [
113114
"requires-network",

java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.openqa.selenium.remote.Augmenter;
5151
import org.openqa.selenium.remote.RemoteWebDriver;
5252
import org.openqa.selenium.testing.Ignore;
53-
import org.openqa.selenium.testing.NotYetImplemented;
5453
import org.openqa.selenium.testing.drivers.Browser;
5554

5655
class RemoteWebDriverBiDiTest {
@@ -84,7 +83,6 @@ void setup() {
8483
@Test
8584
@Ignore(IE)
8685
@Ignore(SAFARI)
87-
@NotYetImplemented(EDGE)
8886
void ensureBiDiSessionCreation() {
8987
try (BiDi biDi = ((HasBiDi) driver).getBiDi()) {
9088
BiDiSessionStatus status = biDi.getBidiSessionStatus();
@@ -96,7 +94,6 @@ void ensureBiDiSessionCreation() {
9694
@Test
9795
@Ignore(IE)
9896
@Ignore(SAFARI)
99-
@NotYetImplemented(EDGE)
10097
void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutException {
10198
driver = new Augmenter().augment(driver);
10299

@@ -124,7 +121,6 @@ void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutE
124121
@Test
125122
@Ignore(IE)
126123
@Ignore(SAFARI)
127-
@NotYetImplemented(EDGE)
128124
void canNavigateToUrl() {
129125
BrowsingContext browsingContext = new BrowsingContext(driver, WindowType.TAB);
130126

py/selenium/webdriver/remote/webdriver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def start_session(self, capabilities: dict) -> None:
354354
self.session_id = response.get("sessionId")
355355
self.caps = response.get("capabilities")
356356
except Exception:
357-
if self.service is not None:
357+
if hasattr(self, "service") and self.service is not None:
358358
self.service.stop()
359359
raise
360360

0 commit comments

Comments
 (0)