24
24
import java .nio .file .Path ;
25
25
import java .util .Map ;
26
26
import java .util .Optional ;
27
- import java .util .logging .Level ;
28
27
import java .util .logging .Logger ;
29
28
import java .util .stream .Collectors ;
30
29
import java .util .stream .Stream ;
33
32
import org .openqa .selenium .ImmutableCapabilities ;
34
33
import org .openqa .selenium .MutableCapabilities ;
35
34
import org .openqa .selenium .OutputType ;
36
- import org .openqa .selenium .PersistentCapabilities ;
37
35
import org .openqa .selenium .Proxy ;
38
36
import org .openqa .selenium .WebDriverException ;
39
37
import org .openqa .selenium .bidi .BiDi ;
40
38
import org .openqa .selenium .bidi .BiDiException ;
41
39
import org .openqa .selenium .bidi .HasBiDi ;
42
- import org .openqa .selenium .devtools .CdpEndpointFinder ;
43
- import org .openqa .selenium .devtools .CdpInfo ;
44
- import org .openqa .selenium .devtools .CdpVersionFinder ;
45
- import org .openqa .selenium .devtools .Connection ;
46
- import org .openqa .selenium .devtools .DevTools ;
47
- import org .openqa .selenium .devtools .DevToolsException ;
48
- import org .openqa .selenium .devtools .HasDevTools ;
49
- import org .openqa .selenium .devtools .noop .NoOpCdpInfo ;
50
40
import org .openqa .selenium .html5 .LocalStorage ;
51
41
import org .openqa .selenium .html5 .SessionStorage ;
52
42
import org .openqa .selenium .html5 .WebStorage ;
78
68
* </pre>
79
69
*/
80
70
public class FirefoxDriver extends RemoteWebDriver
81
- implements WebStorage , HasExtensions , HasFullPageScreenshot , HasContext , HasDevTools , HasBiDi {
71
+ implements WebStorage , HasExtensions , HasFullPageScreenshot , HasContext , HasBiDi {
82
72
83
73
private static final Logger LOG = Logger .getLogger (FirefoxDriver .class .getName ());
84
74
private final Capabilities capabilities ;
85
75
private final RemoteWebStorage webStorage ;
86
76
private final HasExtensions extensions ;
87
77
private final HasFullPageScreenshot fullPageScreenshot ;
88
78
private final HasContext context ;
89
- private final Optional <URI > cdpUri ;
90
79
private final Optional <URI > biDiUri ;
91
- private Connection connection ;
92
- private DevTools devTools ;
93
80
private final Optional <BiDi > biDi ;
94
81
95
82
/**
@@ -160,41 +147,6 @@ private FirefoxDriver(
160
147
context = new AddHasContext ().getImplementation (getCapabilities (), getExecuteMethod ());
161
148
162
149
Capabilities capabilities = super .getCapabilities ();
163
- HttpClient .Factory factory = HttpClient .Factory .createDefault ();
164
-
165
- Optional <URI > reportedUri =
166
- CdpEndpointFinder .getReportedUri ("moz:debuggerAddress" , capabilities );
167
-
168
- if (reportedUri .isPresent () && !capabilities .is ("webSocketUrl" )) {
169
- LOG .warning (
170
- "CDP support for Firefox is deprecated and will be removed in future versions. "
171
- + "Please switch to WebDriver BiDi." );
172
- }
173
-
174
- Optional <HttpClient > client =
175
- reportedUri .map (uri -> CdpEndpointFinder .getHttpClient (factory , uri ));
176
- Optional <URI > cdpUri ;
177
-
178
- try {
179
- cdpUri = client .flatMap (CdpEndpointFinder ::getCdpEndPoint );
180
- } catch (Exception e ) {
181
- try {
182
- client .ifPresent (HttpClient ::close );
183
- } catch (Exception ex ) {
184
- e .addSuppressed (ex );
185
- }
186
- throw e ;
187
- }
188
-
189
- try {
190
- client .ifPresent (HttpClient ::close );
191
- } catch (Exception e ) {
192
- LOG .log (
193
- Level .FINE ,
194
- "failed to close the http client used to check the reported CDP endpoint: "
195
- + reportedUri .get (),
196
- e );
197
- }
198
150
199
151
Optional <String > webSocketUrl =
200
152
Optional .ofNullable ((String ) capabilities .getCapability ("webSocketUrl" ));
@@ -212,16 +164,7 @@ private FirefoxDriver(
212
164
213
165
this .biDi = createBiDi (biDiUri );
214
166
215
- this .cdpUri = cdpUri ;
216
- this .capabilities =
217
- cdpUri
218
- .map (
219
- uri ->
220
- new ImmutableCapabilities (
221
- new PersistentCapabilities (capabilities )
222
- .setCapability ("se:cdp" , uri .toString ())
223
- .setCapability ("se:cdpVersion" , "85.0" )))
224
- .orElse (new ImmutableCapabilities (capabilities ));
167
+ this .capabilities = new ImmutableCapabilities (capabilities );
225
168
}
226
169
227
170
@ Beta
@@ -315,51 +258,6 @@ public void setContext(FirefoxCommandContext commandContext) {
315
258
context .setContext (commandContext );
316
259
}
317
260
318
- /**
319
- * @deprecated Use W3C-compliant BiDi protocol. Use {{@link #maybeGetBiDi()}}
320
- */
321
- @ Deprecated
322
- @ Override
323
- public Optional <DevTools > maybeGetDevTools () {
324
- if (devTools != null ) {
325
- return Optional .of (devTools );
326
- }
327
-
328
- if (!cdpUri .isPresent ()) {
329
- return Optional .empty ();
330
- }
331
-
332
- URI wsUri =
333
- cdpUri .orElseThrow (
334
- () ->
335
- new DevToolsException (
336
- "This version of Firefox or geckodriver does not support CDP" ));
337
- HttpClient .Factory clientFactory = HttpClient .Factory .createDefault ();
338
-
339
- ClientConfig wsConfig = ClientConfig .defaultConfig ().baseUri (wsUri );
340
- HttpClient wsClient = clientFactory .createClient (wsConfig );
341
-
342
- connection = new Connection (wsClient , wsUri .toString ());
343
- CdpInfo cdpInfo = new CdpVersionFinder ().match ("85.0" ).orElseGet (NoOpCdpInfo ::new );
344
- devTools = new DevTools (cdpInfo ::getDomains , connection );
345
-
346
- return Optional .of (devTools );
347
- }
348
-
349
- /**
350
- * @deprecated Use W3C-compliant BiDi protocol. Use {{@link #getBiDi()}}
351
- */
352
- @ Deprecated
353
- @ Override
354
- public DevTools getDevTools () {
355
- if (!cdpUri .isPresent ()) {
356
- throw new DevToolsException ("This version of Firefox or geckodriver does not support CDP" );
357
- }
358
-
359
- return maybeGetDevTools ()
360
- .orElseThrow (() -> new DevToolsException ("Unable to initialize CDP connection" ));
361
- }
362
-
363
261
private Optional <BiDi > createBiDi (Optional <URI > biDiUri ) {
364
262
if (biDiUri .isEmpty ()) {
365
263
return Optional .empty ();
0 commit comments