File tree Expand file tree Collapse file tree 2 files changed +38
-13
lines changed
java/src/org/openqa/selenium Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Original file line number Diff line number Diff line change @@ -44,18 +44,31 @@ public Class<HasBiDi> getDescribedInterface() {
44
44
45
45
@ Override
46
46
public HasBiDi getImplementation (Capabilities caps , ExecuteMethod executeMethod ) {
47
+ return new HasBiDi () {
48
+ private volatile Optional <BiDi > biDi ;
47
49
48
- URI wsUri = getBiDiUrl (caps ).orElseThrow (() -> new BiDiException ("BiDi not supported" ));
50
+ @ Override
51
+ public Optional <BiDi > maybeGetBiDi () {
52
+ if (biDi == null ) {
53
+ synchronized (this ) {
54
+ if (biDi == null ) {
55
+ URI wsUri = getBiDiUrl (caps ).orElseThrow (() -> new BiDiException ("BiDi not supported" ));
49
56
50
- HttpClient .Factory clientFactory = HttpClient .Factory .createDefault ();
51
- ClientConfig wsConfig = ClientConfig .defaultConfig ().baseUri (wsUri );
52
- HttpClient wsClient = clientFactory .createClient (wsConfig );
53
- Connection connection = new Connection (wsClient , wsUri .toString ());
57
+ HttpClient .Factory clientFactory = HttpClient .Factory .createDefault ();
58
+ ClientConfig wsConfig = ClientConfig .defaultConfig ().baseUri (wsUri );
59
+ HttpClient wsClient = clientFactory .createClient (wsConfig );
60
+ Connection connection = new Connection (wsClient , wsUri .toString ());
54
61
55
- return () -> Optional .of (new BiDi (connection ));
62
+ biDi = Optional .of (new BiDi (connection ));
63
+ }
64
+ }
65
+ }
66
+ return biDi ;
67
+ }
68
+ };
56
69
}
57
70
58
- private Optional <URI > getBiDiUrl (Capabilities caps ) {
71
+ private static Optional <URI > getBiDiUrl (Capabilities caps ) {
59
72
Object biDiCapability = caps .getCapability ("webSocketUrl" );
60
73
Optional <String > webSocketUrl = Optional .ofNullable ((String ) biDiCapability );
61
74
Original file line number Diff line number Diff line change @@ -42,14 +42,26 @@ public Class<HasDevTools> getDescribedInterface() {
42
42
43
43
@ Override
44
44
public HasDevTools getImplementation (Capabilities caps , ExecuteMethod executeMethod ) {
45
- Object cdpVersion = caps . getCapability ( "se:cdpVersion" );
46
- String version = cdpVersion instanceof String ? ( String ) cdpVersion : caps . getBrowserVersion () ;
45
+ return new HasDevTools () {
46
+ private volatile Optional < DevTools > devTools ;
47
47
48
- CdpInfo info = new CdpVersionFinder ().match (version ).orElseGet (NoOpCdpInfo ::new );
49
- Optional <DevTools > devTools =
50
- SeleniumCdpConnection .create (caps ).map (conn -> new DevTools (info ::getDomains , conn ));
48
+ @ Override
49
+ public Optional <DevTools > maybeGetDevTools () {
50
+ if (devTools == null ) {
51
+ synchronized (this ) {
52
+ if (devTools == null ) {
53
+ Object cdpVersion = caps .getCapability ("se:cdpVersion" );
54
+ String version =
55
+ cdpVersion instanceof String ? (String ) cdpVersion : caps .getBrowserVersion ();
51
56
52
- return () -> devTools ;
57
+ CdpInfo info = new CdpVersionFinder ().match (version ).orElseGet (NoOpCdpInfo ::new );
58
+ this .devTools = SeleniumCdpConnection .create (caps ).map (conn -> new DevTools (info ::getDomains , conn ));
59
+ }
60
+ }
61
+ }
62
+ return devTools ;
63
+ }
64
+ };
53
65
}
54
66
55
67
private String getCdpUrl (Capabilities caps ) {
You can’t perform that action at this time.
0 commit comments