Skip to content

Commit ed45d7a

Browse files
committed
Ensure providers exist for new ActiveSessionFactory
1 parent d284f34 commit ed45d7a

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

java/server/src/org/openqa/selenium/remote/server/ActiveSessionFactory.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,31 @@ public class ActiveSessionFactory {
4444
private final Map<String, SessionFactory> factories;
4545

4646
public ActiveSessionFactory() {
47+
Map<String, ServicedSession.Factory> servicedFactories = ImmutableMap.<String, String>builder()
48+
.put(chrome().getBrowserName(), "org.openqa.selenium.chrome.ChromeDriverService")
49+
.put(edge().getBrowserName(), "org.openqa.selenium.edge.EdgeDriverService")
50+
.put(firefox().getBrowserName(), "org.openqa.selenium.firefox.GeckoDriverService")
51+
.put(internetExplorer().getBrowserName(), "org.openqa.selenium.ie.InternetExplorerDriverService")
52+
.put(opera().getBrowserName(), "org.openqa.selenium.opera.OperaDriverService")
53+
.put(operaBlink().getBrowserName(), "org.openqa.selenium.ie.OperaDriverService")
54+
.put(phantomjs().getBrowserName(), "org.openqa.selenium.phantomjs.PhantomJSDriverService")
55+
.put(safari().getBrowserName(), "org.openqa.selenium.safari.SafariDriverService")
56+
.build()
57+
.entrySet().stream()
58+
.filter(e -> {
59+
try {
60+
Class.forName(e.getValue());
61+
return true;
62+
} catch (ClassNotFoundException cnfe) {
63+
return false;
64+
}
65+
})
66+
.collect(Collectors.toMap(
67+
Map.Entry::getKey,
68+
e -> new ServicedSession.Factory(e.getValue())));
69+
4770
this.factories = ImmutableMap.<String, SessionFactory>builder()
48-
.put(chrome().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.chrome.ChromeDriverService"))
49-
.put(edge().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.edge.EdgeDriverService"))
50-
.put(firefox().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.firefox.GeckoDriverService"))
51-
.put(internetExplorer().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.ie.InternetExplorerDriverService"))
52-
.put(opera().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.opera.OperaDriverService"))
53-
.put(operaBlink().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.ie.OperaDriverService"))
54-
.put(phantomjs().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.phantomjs.PhantomJSDriverService"))
55-
.put(safari().getBrowserName(), new ServicedSession.Factory("org.openqa.selenium.safari.SafariDriverService"))
71+
.putAll(servicedFactories)
5672
// We put htmlunit last because the factories will always succeed. Which is nice, but tricky.
5773
.put(htmlUnit().getBrowserName(), new InMemorySession.Factory(new DefaultDriverFactory(Platform.getCurrent())))
5874
.build();

0 commit comments

Comments
 (0)