|
21 | 21 | import static com.google.common.net.MediaType.JSON_UTF_8;
|
22 | 22 | import static java.net.HttpURLConnection.HTTP_OK;
|
23 | 23 | import static java.nio.charset.StandardCharsets.UTF_8;
|
24 |
| -import static org.openqa.selenium.remote.BrowserType.CHROME; |
25 |
| -import static org.openqa.selenium.remote.BrowserType.EDGE; |
26 |
| -import static org.openqa.selenium.remote.BrowserType.FIREFOX; |
27 |
| -import static org.openqa.selenium.remote.BrowserType.IE; |
28 |
| -import static org.openqa.selenium.remote.BrowserType.SAFARI; |
29 | 24 | import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
|
30 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.chrome; |
31 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.edge; |
32 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.firefox; |
33 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.htmlUnit; |
34 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.internetExplorer; |
35 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.opera; |
36 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.operaBlink; |
37 |
| -import static org.openqa.selenium.remote.DesiredCapabilities.safari; |
38 |
| -import static org.openqa.selenium.remote.Dialect.OSS; |
39 |
| -import static org.openqa.selenium.remote.Dialect.W3C; |
40 | 25 |
|
41 | 26 | import com.google.common.base.Charsets;
|
42 |
| -import com.google.common.collect.ImmutableList; |
43 | 27 | import com.google.common.collect.ImmutableMap;
|
44 |
| -import com.google.common.collect.ImmutableSet; |
45 | 28 | import com.google.common.net.MediaType;
|
46 | 29 | import com.google.gson.stream.JsonReader;
|
47 | 30 | import com.google.gson.stream.JsonToken;
|
48 | 31 |
|
49 | 32 | import org.openqa.selenium.SessionNotCreatedException;
|
50 | 33 | import org.openqa.selenium.remote.BeanToJsonConverter;
|
51 |
| -import org.openqa.selenium.remote.Dialect; |
52 | 34 | import org.openqa.selenium.remote.http.HttpRequest;
|
53 | 35 | import org.openqa.selenium.remote.http.HttpResponse;
|
54 | 36 |
|
|
65 | 47 | import java.util.LinkedList;
|
66 | 48 | import java.util.List;
|
67 | 49 | import java.util.Map;
|
68 |
| -import java.util.Objects; |
69 |
| -import java.util.logging.Level; |
70 |
| -import java.util.logging.Logger; |
71 |
| -import java.util.stream.Collectors; |
72 | 50 |
|
73 | 51 | class BeginSession implements CommandHandler {
|
74 | 52 |
|
75 |
| - private final static Logger LOG = Logger.getLogger(BeginSession.class.getName()); |
76 |
| - |
77 | 53 | private final ActiveSessionFactory sessionFactory;
|
78 | 54 | private final ActiveSessions allSessions;
|
79 | 55 |
|
@@ -247,100 +223,4 @@ private Map<String, Object> sparseCapabilities(JsonReader json) throws IOExcepti
|
247 | 223 | return caps;
|
248 | 224 | }
|
249 | 225 |
|
250 |
| - public static class ActiveSessionFactory { |
251 |
| - private final Map<String, SessionFactory> factories; |
252 |
| - |
253 |
| - public ActiveSessionFactory(DriverSessions legacySessions) { |
254 |
| - this.factories = ImmutableMap.<String, SessionFactory>builder() |
255 |
| - .put(chrome().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.chrome.ChromeDriverService")) |
256 |
| - .put(edge().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.edge.EdgeDriverService")) |
257 |
| - .put(firefox().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.firefox.GeckoDriverService")) |
258 |
| - .put(htmlUnit().getBrowserName(), new InMemorySession.Factory(legacySessions)) |
259 |
| - .put(internetExplorer().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.ie.InternetExplorerDriverService")) |
260 |
| - .put(opera().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.ie.OperaDriverService")) |
261 |
| - .put(operaBlink().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.ie.OperaDriverService")) |
262 |
| - .put(safari().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.ie.OperaDriverService")) |
263 |
| - .build(); |
264 |
| - } |
265 |
| - |
266 |
| - |
267 |
| - public ActiveSession createSession( |
268 |
| - Path rawCapabilitiesBlob, |
269 |
| - Map<String, Object> ossKeys, |
270 |
| - Map<String, Object> alwaysMatch, |
271 |
| - List<Map<String, Object>> firstMatch) { |
272 |
| - List<SessionFactory> browserGenerators = determineBrowser( |
273 |
| - ossKeys, |
274 |
| - alwaysMatch, |
275 |
| - firstMatch); |
276 |
| - |
277 |
| - ImmutableSet.Builder<Dialect> downstreamDialects = ImmutableSet.builder(); |
278 |
| - // Favour OSS for now |
279 |
| - if (!ossKeys.isEmpty()) { |
280 |
| - downstreamDialects.add(OSS); |
281 |
| - } |
282 |
| - if (!alwaysMatch.isEmpty() || !firstMatch.isEmpty()) { |
283 |
| - downstreamDialects.add(W3C); |
284 |
| - } |
285 |
| - |
286 |
| - return browserGenerators.stream() |
287 |
| - .map(func -> { |
288 |
| - try { |
289 |
| - return func.apply(rawCapabilitiesBlob, downstreamDialects.build()); |
290 |
| - } catch (Exception e) { |
291 |
| - LOG.log(Level.INFO, "Unable to start session.", e); |
292 |
| - } |
293 |
| - return null; |
294 |
| - }) |
295 |
| - .filter(Objects::nonNull) |
296 |
| - .findFirst() |
297 |
| - .orElseThrow(() -> new SessionNotCreatedException("Unable to create a new session")); |
298 |
| - } |
299 |
| - |
300 |
| - private List<SessionFactory> determineBrowser( |
301 |
| - Map<String, Object> ossKeys, |
302 |
| - Map<String, Object> alwaysMatchKeys, |
303 |
| - List<Map<String, Object>> firstMatchKeys) { |
304 |
| - List<Map<String, Object>> allCapabilities = firstMatchKeys.stream() |
305 |
| - // remove null keys |
306 |
| - .map(caps -> ImmutableMap.<String, Object>builder().putAll(caps).putAll(alwaysMatchKeys).build()) |
307 |
| - .collect(Collectors.toList()); |
308 |
| - allCapabilities.add(ossKeys); |
309 |
| - |
310 |
| - // Can we figure out the browser from any of these? |
311 |
| - ImmutableList.Builder<SessionFactory> builder = ImmutableList.builder(); |
312 |
| - for (Map<String, Object> caps : allCapabilities) { |
313 |
| - caps.entrySet().stream() |
314 |
| - .map(entry -> guessBrowserName(entry.getKey(), entry.getValue())) |
315 |
| - .filter(factories.keySet()::contains) |
316 |
| - .map(factories::get) |
317 |
| - .findFirst() |
318 |
| - .ifPresent(builder::add); |
319 |
| - } |
320 |
| - |
321 |
| - return builder.build(); |
322 |
| - } |
323 |
| - |
324 |
| - private String guessBrowserName(String capabilityKey, Object value) { |
325 |
| - if (BROWSER_NAME.equals(capabilityKey)) { |
326 |
| - return (String) value; |
327 |
| - } |
328 |
| - if ("chromeOptions".equals(capabilityKey)) { |
329 |
| - return CHROME; |
330 |
| - } |
331 |
| - if ("edgeOptions".equals(capabilityKey)) { |
332 |
| - return EDGE; |
333 |
| - } |
334 |
| - if (capabilityKey.startsWith("moz:")) { |
335 |
| - return FIREFOX; |
336 |
| - } |
337 |
| - if (capabilityKey.startsWith("safari.")) { |
338 |
| - return SAFARI; |
339 |
| - } |
340 |
| - if ("se:ieOptions".equals(capabilityKey)) { |
341 |
| - return IE; |
342 |
| - } |
343 |
| - return null; |
344 |
| - } |
345 |
| - } |
346 | 226 | }
|
0 commit comments