Skip to content

Commit cfeccd0

Browse files
authored
Merge ca99cd1 into 3bfd6c4
2 parents 3bfd6c4 + ca99cd1 commit cfeccd0

File tree

12 files changed

+474
-118
lines changed

12 files changed

+474
-118
lines changed

java/src/org/openqa/selenium/bidi/HasBiDi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import java.util.Optional;
2121

2222
public interface HasBiDi {
23+
Optional<BiDi> maybeGetBiDi();
24+
2325
default BiDi getBiDi() {
2426
return maybeGetBiDi()
2527
.orElseThrow(() -> new BiDiException("Unable to create a BiDi connection"));
2628
}
27-
28-
Optional<BiDi> maybeGetBiDi();
2929
}

java/src/org/openqa/selenium/bidi/browsingcontext/ReadinessState.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,39 @@
1818
package org.openqa.selenium.bidi.browsingcontext;
1919

2020
public enum ReadinessState {
21-
NONE("none"),
22-
INTERACTIVE("interactive"),
23-
COMPLETE("complete");
21+
// Mapping the page load strategy values used in BiDi To Classic
22+
// Refer: https://w3c.github.io/webdriver-bidi/#type-browsingContext-ReadinessState
23+
// Refer: https://www.w3.org/TR/webdriver2/#navigation
24+
NONE("none", "none"),
25+
INTERACTIVE("interactive", "eager"),
26+
COMPLETE("complete", "normal");
2427

25-
private final String text;
28+
private final String readinessState;
2629

27-
ReadinessState(String text) {
28-
this.text = text;
30+
private final String pageLoadStrategy;
31+
32+
ReadinessState(String readinessState, String pageLoadStrategy) {
33+
this.readinessState = readinessState;
34+
this.pageLoadStrategy = pageLoadStrategy;
35+
}
36+
37+
public String getPageLoadStrategy() {
38+
return pageLoadStrategy;
39+
}
40+
41+
public static ReadinessState getReadinessState(String pageLoadStrategy) {
42+
if (pageLoadStrategy != null) {
43+
for (ReadinessState b : ReadinessState.values()) {
44+
if (pageLoadStrategy.equalsIgnoreCase(b.pageLoadStrategy)) {
45+
return b;
46+
}
47+
}
48+
}
49+
return null;
2950
}
3051

3152
@Override
3253
public String toString() {
33-
return String.valueOf(text);
54+
return String.valueOf(readinessState);
3455
}
3556
}

java/src/org/openqa/selenium/chromium/ChromiumDriver.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.openqa.selenium.remote.Browser.OPERA;
2323

2424
import java.net.URI;
25-
import java.net.URISyntaxException;
2625
import java.util.HashMap;
2726
import java.util.List;
2827
import java.util.Map;
@@ -42,9 +41,6 @@
4241
import org.openqa.selenium.ScriptKey;
4342
import org.openqa.selenium.WebDriver;
4443
import org.openqa.selenium.WebDriverException;
45-
import org.openqa.selenium.bidi.BiDi;
46-
import org.openqa.selenium.bidi.BiDiException;
47-
import org.openqa.selenium.bidi.HasBiDi;
4844
import org.openqa.selenium.devtools.CdpEndpointFinder;
4945
import org.openqa.selenium.devtools.CdpInfo;
5046
import org.openqa.selenium.devtools.CdpVersionFinder;
@@ -67,7 +63,6 @@
6763
import org.openqa.selenium.remote.RemoteWebDriver;
6864
import org.openqa.selenium.remote.html5.RemoteLocationContext;
6965
import org.openqa.selenium.remote.html5.RemoteWebStorage;
70-
import org.openqa.selenium.remote.http.ClientConfig;
7166
import org.openqa.selenium.remote.http.ConnectionFailedException;
7267
import org.openqa.selenium.remote.http.HttpClient;
7368
import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;
@@ -78,7 +73,6 @@
7873
*/
7974
public class ChromiumDriver extends RemoteWebDriver
8075
implements HasAuthentication,
81-
HasBiDi,
8276
HasCasting,
8377
HasCdp,
8478
HasDevTools,
@@ -103,8 +97,6 @@ public class ChromiumDriver extends RemoteWebDriver
10397
private final HasLaunchApp launch;
10498
private Optional<Connection> connection;
10599
private final Optional<DevTools> devTools;
106-
private final Optional<URI> biDiUri;
107-
private final Optional<BiDi> biDi;
108100
protected HasCasting casting;
109101
protected HasCdp cdp;
110102
private final Map<Integer, ScriptKey> scriptKeys = new HashMap<>();
@@ -123,22 +115,6 @@ protected ChromiumDriver(
123115
HttpClient.Factory factory = HttpClient.Factory.createDefault();
124116
Capabilities originalCapabilities = super.getCapabilities();
125117

126-
Optional<String> webSocketUrl =
127-
Optional.ofNullable((String) originalCapabilities.getCapability("webSocketUrl"));
128-
129-
this.biDiUri =
130-
webSocketUrl.map(
131-
uri -> {
132-
try {
133-
return new URI(uri);
134-
} catch (URISyntaxException e) {
135-
LOG.warning(e.getMessage());
136-
}
137-
return null;
138-
});
139-
140-
this.biDi = createBiDi(biDiUri);
141-
142118
Optional<URI> reportedUri =
143119
CdpEndpointFinder.getReportedUri(capabilityKey, originalCapabilities);
144120
Optional<HttpClient> client =
@@ -346,30 +322,6 @@ public Optional<DevTools> maybeGetDevTools() {
346322
return devTools;
347323
}
348324

349-
private Optional<BiDi> createBiDi(Optional<URI> biDiUri) {
350-
if (!biDiUri.isPresent()) {
351-
return Optional.empty();
352-
}
353-
354-
URI wsUri =
355-
biDiUri.orElseThrow(
356-
() -> new BiDiException("This version of Chromium driver does not support BiDi"));
357-
358-
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
359-
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
360-
HttpClient wsClient = clientFactory.createClient(wsConfig);
361-
362-
org.openqa.selenium.bidi.Connection biDiConnection =
363-
new org.openqa.selenium.bidi.Connection(wsClient, wsUri.toString());
364-
365-
return Optional.of(new BiDi(biDiConnection));
366-
}
367-
368-
@Override
369-
public Optional<BiDi> maybeGetBiDi() {
370-
return biDi;
371-
}
372-
373325
@Override
374326
public List<Map<String, String>> getCastSinks() {
375327
return casting.getCastSinks();

java/src/org/openqa/selenium/firefox/FirefoxDriver.java

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.openqa.selenium.remote.CapabilityType.PROXY;
2121

2222
import java.net.URI;
23-
import java.net.URISyntaxException;
2423
import java.nio.file.Path;
2524
import java.util.Map;
2625
import java.util.Optional;
@@ -36,9 +35,6 @@
3635
import org.openqa.selenium.PersistentCapabilities;
3736
import org.openqa.selenium.Proxy;
3837
import org.openqa.selenium.WebDriverException;
39-
import org.openqa.selenium.bidi.BiDi;
40-
import org.openqa.selenium.bidi.BiDiException;
41-
import org.openqa.selenium.bidi.HasBiDi;
4238
import org.openqa.selenium.devtools.CdpEndpointFinder;
4339
import org.openqa.selenium.devtools.CdpInfo;
4440
import org.openqa.selenium.devtools.CdpVersionFinder;
@@ -79,7 +75,7 @@
7975
* </pre>
8076
*/
8177
public class FirefoxDriver extends RemoteWebDriver
82-
implements WebStorage, HasExtensions, HasFullPageScreenshot, HasContext, HasDevTools, HasBiDi {
78+
implements WebStorage, HasExtensions, HasFullPageScreenshot, HasContext, HasDevTools {
8379

8480
private static final Logger LOG = Logger.getLogger(FirefoxDriver.class.getName());
8581
private final Capabilities capabilities;
@@ -88,10 +84,8 @@ public class FirefoxDriver extends RemoteWebDriver
8884
private final HasFullPageScreenshot fullPageScreenshot;
8985
private final HasContext context;
9086
private final Optional<URI> cdpUri;
91-
private final Optional<URI> biDiUri;
9287
private Connection connection;
9388
private DevTools devTools;
94-
private Optional<BiDi> biDi;
9589

9690
/**
9791
* Creates a new FirefoxDriver using the {@link GeckoDriverService#createDefaultService)} server
@@ -189,22 +183,6 @@ private FirefoxDriver(
189183
e);
190184
}
191185

192-
Optional<String> webSocketUrl =
193-
Optional.ofNullable((String) capabilities.getCapability("webSocketUrl"));
194-
195-
this.biDiUri =
196-
webSocketUrl.map(
197-
uri -> {
198-
try {
199-
return new URI(uri);
200-
} catch (URISyntaxException e) {
201-
LOG.warning(e.getMessage());
202-
}
203-
return null;
204-
});
205-
206-
this.biDi = createBiDi(biDiUri);
207-
208186
this.cdpUri = cdpUri;
209187
this.capabilities =
210188
cdpUri
@@ -353,41 +331,6 @@ public DevTools getDevTools() {
353331
.orElseThrow(() -> new DevToolsException("Unable to initialize CDP connection"));
354332
}
355333

356-
private Optional<BiDi> createBiDi(Optional<URI> biDiUri) {
357-
if (!biDiUri.isPresent()) {
358-
return Optional.empty();
359-
}
360-
361-
URI wsUri =
362-
biDiUri.orElseThrow(
363-
() ->
364-
new BiDiException("This version of Firefox or geckodriver does not support BiDi"));
365-
366-
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
367-
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
368-
HttpClient wsClient = clientFactory.createClient(wsConfig);
369-
370-
org.openqa.selenium.bidi.Connection biDiConnection =
371-
new org.openqa.selenium.bidi.Connection(wsClient, wsUri.toString());
372-
373-
return Optional.of(new BiDi(biDiConnection));
374-
}
375-
376-
@Override
377-
public Optional<BiDi> maybeGetBiDi() {
378-
return biDi;
379-
}
380-
381-
@Override
382-
public BiDi getBiDi() {
383-
if (!biDiUri.isPresent()) {
384-
throw new BiDiException("This version of Firefox or geckodriver does not support Bidi");
385-
}
386-
387-
return maybeGetBiDi()
388-
.orElseThrow(() -> new BiDiException("Unable to initialize Bidi connection"));
389-
}
390-
391334
@Override
392335
public void quit() {
393336
super.quit();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.remote;
19+
20+
import java.io.IOException;
21+
22+
public class BiDiCommandExecutor implements CommandExecutor {
23+
24+
private final RemoteWebDriver driver;
25+
private final BiDiCommandMapper commandMapper;
26+
27+
public BiDiCommandExecutor(RemoteWebDriver driver) {
28+
this.driver = driver;
29+
commandMapper = new BiDiCommandMapper(driver);
30+
}
31+
32+
@Override
33+
public Response execute(Command command) throws IOException {
34+
return commandMapper.map(command).apply(command, driver);
35+
}
36+
}

0 commit comments

Comments
 (0)