38
38
39
39
public class DefaultDriverSessions implements DriverSessions {
40
40
41
- private static final Logger log = Logger .getLogger (DefaultDriverSessions .class .getName ());
41
+ private static final Logger LOG = Logger .getLogger (DefaultDriverSessions .class .getName ());
42
42
43
43
private final DriverFactory factory ;
44
44
@@ -67,6 +67,15 @@ public DefaultDriverSessions() {
67
67
this (Platform .getCurrent (), new DefaultDriverFactory ());
68
68
}
69
69
70
+ public DefaultDriverSessions (DriverFactory factory ) {
71
+ this (Platform .getCurrent (), factory );
72
+ }
73
+
74
+ /**
75
+ * @deprecated Use DefaultDriverSessions(DriverFactory factory) constructor
76
+ * and register all drivers to the factory
77
+ */
78
+ @ Deprecated
70
79
public DefaultDriverSessions (
71
80
DriverFactory factory , Map <Capabilities , Class <? extends WebDriver >> drivers ) {
72
81
this .factory = factory ;
@@ -95,12 +104,26 @@ private void registerServiceLoaders(Platform current) {
95
104
96
105
private void registerDriverProvider (Platform current , DriverProvider provider ) {
97
106
Capabilities caps = provider .getProvidedCapabilities ();
98
- if (caps .getPlatform () == null || caps .getPlatform () == Platform .ANY || current .is (caps .getPlatform ())) {
99
- factory .registerDriverProvider (caps , provider );
100
- } else {
101
- log .info ("Driver provider " + provider + " registration is skipped: registration capabilities "
102
- + caps .toString () + " does not match with current platform: " + current .toString ());
107
+ if (!platformMatches (current , caps )) {
108
+ LOG .info (String .format (
109
+ "Driver provider %s registration is skipped:%n"
110
+ + "registration capabilities %s does not match the current platform %s" ,
111
+ provider , caps , current ));
112
+ return ;
103
113
}
114
+
115
+ factory .registerDriverProvider (caps , provider );
116
+ }
117
+
118
+ private boolean platformMatches (Platform current , Capabilities caps ) {
119
+ return caps .getPlatform () == null
120
+ || caps .getPlatform () == Platform .ANY
121
+ || current .is (caps .getPlatform ());
122
+ }
123
+
124
+ public void registerDriver (Capabilities capabilities , Class <? extends WebDriver > implementation ) {
125
+ factory .registerDriverProvider (
126
+ capabilities , new DefaultDriverProvider (capabilities , implementation ));
104
127
}
105
128
106
129
public SessionId newSession (Capabilities desiredCapabilities ) throws Exception {
@@ -123,10 +146,6 @@ public void deleteSession(SessionId sessionId) {
123
146
}
124
147
}
125
148
126
- public void registerDriver (Capabilities capabilities , Class <? extends WebDriver > implementation ) {
127
- factory .registerDriver (capabilities , implementation );
128
- }
129
-
130
149
public Set <SessionId > getSessions () {
131
150
return Collections .unmodifiableSet (sessionIdToDriver .keySet ());
132
151
}
0 commit comments