@@ -67,7 +67,7 @@ public class DriverServiceSessionFactory implements SessionFactory {
67
67
private final Predicate <Capabilities > predicate ;
68
68
private final DriverService .Builder <?, ?> builder ;
69
69
private final Capabilities stereotype ;
70
- private final BrowserOptionsMutator browserOptionsMutator ;
70
+ private final SessionCapabilitiesMutator sessionCapabilitiesMutator ;
71
71
72
72
public DriverServiceSessionFactory (
73
73
Tracer tracer ,
@@ -80,7 +80,7 @@ public DriverServiceSessionFactory(
80
80
this .stereotype = ImmutableCapabilities .copyOf (Require .nonNull ("Stereotype" , stereotype ));
81
81
this .predicate = Require .nonNull ("Accepted capabilities predicate" , predicate );
82
82
this .builder = Require .nonNull ("Driver service builder" , builder );
83
- this .browserOptionsMutator = new BrowserOptionsMutator (this .stereotype );
83
+ this .sessionCapabilitiesMutator = new SessionCapabilitiesMutator (this .stereotype );
84
84
}
85
85
86
86
@ Override
@@ -101,7 +101,8 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
101
101
102
102
try (Span span = tracer .getCurrentContext ().createSpan ("driver_service_factory.apply" )) {
103
103
104
- Capabilities capabilities = browserOptionsMutator .apply (sessionRequest .getDesiredCapabilities ());
104
+ Capabilities capabilities = sessionCapabilitiesMutator
105
+ .apply (sessionRequest .getDesiredCapabilities ());
105
106
106
107
Optional <Platform > platformName = Optional .ofNullable (capabilities .getPlatformName ());
107
108
if (platformName .isPresent ()) {
@@ -142,14 +143,13 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
142
143
attributeMap .put (AttributeKey .DRIVER_RESPONSE .getKey (),
143
144
EventAttribute .setValue (response .toString ()));
144
145
145
- // TODO: This is a nasty hack. Try and make it elegant.
146
-
147
146
Capabilities caps = new ImmutableCapabilities ((Map <?, ?>) response .getValue ());
148
147
if (platformName .isPresent ()) {
149
148
caps = setInitialPlatform (caps , platformName .get ());
150
149
}
151
150
152
151
caps = readDevToolsEndpointAndVersion (caps );
152
+ caps = readVncEndpoint (capabilities , caps );
153
153
154
154
span .addEvent ("Driver service created session" , attributeMap );
155
155
return Either .right (
@@ -214,6 +214,7 @@ public DevToolsInfo(URI cdpEndpoint, String version) {
214
214
.filter (Optional ::isPresent )
215
215
.map (Optional ::get )
216
216
.findFirst ();
217
+
217
218
if (maybeInfo .isPresent ()) {
218
219
DevToolsInfo info = maybeInfo .get ();
219
220
return new PersistentCapabilities (caps )
@@ -223,6 +224,17 @@ public DevToolsInfo(URI cdpEndpoint, String version) {
223
224
return caps ;
224
225
}
225
226
227
+ private Capabilities readVncEndpoint (Capabilities requestedCaps , Capabilities returnedCaps ) {
228
+ String seVncEnabledCap = "se:vncEnabled" ;
229
+ String seVncEnabled = String .valueOf (requestedCaps .getCapability (seVncEnabledCap ));
230
+ if (Boolean .parseBoolean (seVncEnabled )) {
231
+ returnedCaps = new PersistentCapabilities (returnedCaps )
232
+ .setCapability ("se:vncLocalAddress" , "ws://localhost:7900/websockify" )
233
+ .setCapability (seVncEnabledCap , true );
234
+ }
235
+ return returnedCaps ;
236
+ }
237
+
226
238
// We set the platform to ANY before sending the caps to the driver because some drivers will
227
239
// reject session requests when they cannot parse the platform.
228
240
private Capabilities generalizePlatform (Capabilities caps ) {
0 commit comments