28
28
import org .openqa .selenium .firefox .FirefoxOptions ;
29
29
import org .openqa .selenium .remote .BrowserType ;
30
30
import org .openqa .selenium .remote .CapabilityType ;
31
- import org .openqa .selenium .safari .SafariDriver ;
32
31
import org .openqa .selenium .safari .SafariOptions ;
33
32
34
33
import java .util .HashMap ;
@@ -38,8 +37,9 @@ public class DefaultCapabilityMatcherTest {
38
37
39
38
private DefaultCapabilityMatcher matcher = new DefaultCapabilityMatcher ();
40
39
40
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
41
41
@ Test
42
- public void smokeTest () {
42
+ public void smokeTestWithDeprecatedPlatformCapability () {
43
43
Map <String , Object > firefox = ImmutableMap .of (
44
44
CapabilityType .BROWSER_NAME , "B" ,
45
45
CapabilityType .PLATFORM , "XP" );
@@ -73,7 +73,42 @@ public void smokeTest() {
73
73
}
74
74
75
75
@ Test
76
- public void genericPlatformMatchingTest () {
76
+ public void smokeTest () {
77
+ Map <String , Object > firefox = ImmutableMap .of (
78
+ CapabilityType .BROWSER_NAME , "B" ,
79
+ CapabilityType .PLATFORM_NAME , "XP" );
80
+ Map <String , Object > tl = new HashMap <String , Object >() {{
81
+ put (CapabilityType .APPLICATION_NAME , "A" );
82
+ put (CapabilityType .VERSION , null );
83
+ }};
84
+
85
+ Map <String , Object > firefox2 = ImmutableMap .of (
86
+ CapabilityType .BROWSER_NAME , "B" ,
87
+ CapabilityType .PLATFORM_NAME , "win7" ,
88
+ CapabilityType .VERSION , "3.6" );
89
+ Map <String , Object > tl2 = ImmutableMap .of (
90
+ CapabilityType .APPLICATION_NAME , "A" ,
91
+ CapabilityType .VERSION , "8.5.100.7" );
92
+
93
+ assertTrue (matcher .matches (tl , tl ));
94
+ assertFalse (matcher .matches (tl , tl2 ));
95
+ assertTrue (matcher .matches (tl2 , tl ));
96
+ assertTrue (matcher .matches (tl2 , tl2 ));
97
+
98
+ assertTrue (matcher .matches (firefox , firefox ));
99
+ assertFalse (matcher .matches (firefox , firefox2 ));
100
+ assertFalse (matcher .matches (firefox2 , firefox ));
101
+ assertTrue (matcher .matches (firefox2 , firefox2 ));
102
+
103
+ assertFalse (matcher .matches (tl , null ));
104
+ assertFalse (matcher .matches (null , null ));
105
+ assertFalse (matcher .matches (tl , firefox ));
106
+ assertFalse (matcher .matches (firefox , tl2 ));
107
+ }
108
+
109
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
110
+ @ Test
111
+ public void genericPlatformMatchingTestWithDeprecatedPlatformCapability () {
77
112
Map <String , Object > requested = ImmutableMap .of (CapabilityType .PLATFORM , Platform .WINDOWS );
78
113
79
114
assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM , "WINDOWS" ), requested ));
@@ -85,7 +120,20 @@ public void genericPlatformMatchingTest() {
85
120
}
86
121
87
122
@ Test
88
- public void specificPlatformMatchingTest () {
123
+ public void genericPlatformMatchingTest () {
124
+ Map <String , Object > requested = ImmutableMap .of (CapabilityType .PLATFORM_NAME , Platform .WINDOWS );
125
+
126
+ assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "WINDOWS" ), requested ));
127
+ assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "xp" ), requested ));
128
+ assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "windows VISTA" ), requested ));
129
+ assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "windows 7" ), requested ));
130
+
131
+ assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "linux" ), requested ));
132
+ }
133
+
134
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
135
+ @ Test
136
+ public void specificPlatformMatchingTestWithDeprecatedPlatformCapability () {
89
137
Map <String , Object > requested = ImmutableMap .of (CapabilityType .PLATFORM , Platform .XP );
90
138
91
139
assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM , "xp" ), requested ));
@@ -98,7 +146,21 @@ public void specificPlatformMatchingTest() {
98
146
}
99
147
100
148
@ Test
101
- public void unknownPlatformMatchingTest () {
149
+ public void specificPlatformMatchingTest () {
150
+ Map <String , Object > requested = ImmutableMap .of (CapabilityType .PLATFORM_NAME , Platform .XP );
151
+
152
+ assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "xp" ), requested ));
153
+
154
+ assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "WINDOWS" ), requested ));
155
+ assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "windows VISTA" ), requested ));
156
+ assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "windows 7" ), requested ));
157
+
158
+ assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "linux" ), requested ));
159
+ }
160
+
161
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
162
+ @ Test
163
+ public void unknownPlatformMatchingTestWithDeprecatedPlatformCapability () {
102
164
Map <String , Object > requested = ImmutableMap .of (CapabilityType .PLATFORM , "ms-dos" );
103
165
104
166
assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM , "ms-dos" ), requested ));
@@ -107,6 +169,16 @@ public void unknownPlatformMatchingTest() {
107
169
assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM , "PS/2" ), requested ));
108
170
}
109
171
172
+ @ Test
173
+ public void unknownPlatformMatchingTest () {
174
+ Map <String , Object > requested = ImmutableMap .of (CapabilityType .PLATFORM_NAME , "ms-dos" );
175
+
176
+ assertTrue (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "ms-dos" ), requested ));
177
+
178
+ assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "windows" ), requested ));
179
+ assertFalse (matcher .matches (ImmutableMap .of (CapabilityType .PLATFORM_NAME , "PS/2" ), requested ));
180
+ }
181
+
110
182
@ Test
111
183
public void canAddAttributeMatcher () {
112
184
matcher .addToConsider ("my:capability" );
@@ -115,8 +187,9 @@ public void canAddAttributeMatcher() {
115
187
assertFalse (matcher .matches (ImmutableMap .of ("my:capability" , "milk" ), requested ));
116
188
}
117
189
190
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
118
191
@ Test
119
- public void nullEmptyValues () {
192
+ public void nullEmptyValuesWithDeprecatedPlatformCapability () {
120
193
Map <String , Object > requested = new HashMap <>();
121
194
requested .put (CapabilityType .BROWSER_NAME , BrowserType .FIREFOX );
122
195
requested .put (CapabilityType .PLATFORM , null );
@@ -130,6 +203,21 @@ public void nullEmptyValues() {
130
203
assertTrue (matcher .matches (node , requested ));
131
204
}
132
205
206
+ @ Test
207
+ public void nullEmptyValues () {
208
+ Map <String , Object > requested = new HashMap <>();
209
+ requested .put (CapabilityType .BROWSER_NAME , BrowserType .FIREFOX );
210
+ requested .put (CapabilityType .PLATFORM_NAME , null );
211
+ requested .put (CapabilityType .VERSION , "" );
212
+
213
+ Map <String , Object > node = new HashMap <>();
214
+ node .put (CapabilityType .BROWSER_NAME , BrowserType .FIREFOX );
215
+ node .put (CapabilityType .PLATFORM_NAME , Platform .LINUX );
216
+ node .put (CapabilityType .VERSION , "3.6" );
217
+
218
+ assertTrue (matcher .matches (node , requested ));
219
+ }
220
+
133
221
@ Test
134
222
public void versionTests () {
135
223
DefaultCapabilityMatcher matcher = new DefaultCapabilityMatcher ();
@@ -183,8 +271,9 @@ public void shouldMatchMarionetteFirefoxDriverOnly() {
183
271
assertTrue (matcher .matches (mNode , requested ));
184
272
}
185
273
274
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
186
275
@ Test
187
- public void shouldMatchSafariTechnologyPreviewOnly () {
276
+ public void shouldMatchSafariTechnologyPreviewOnlyWithDeprecatedPlatformCapability () {
188
277
Map <String , Object > requested = new SafariOptions ().setUseTechnologyPreview (true ).asMap ();
189
278
190
279
Map <String , Object > tpNode = new HashMap <>();
@@ -201,7 +290,25 @@ public void shouldMatchSafariTechnologyPreviewOnly() {
201
290
}
202
291
203
292
@ Test
204
- public void shouldMatchRegularSafariOnly () {
293
+ public void shouldMatchSafariTechnologyPreviewOnly () {
294
+ Map <String , Object > requested = new SafariOptions ().setUseTechnologyPreview (true ).asMap ();
295
+
296
+ Map <String , Object > tpNode = new HashMap <>();
297
+ tpNode .put (CapabilityType .BROWSER_NAME , BrowserType .SAFARI );
298
+ tpNode .put (CapabilityType .PLATFORM_NAME , Platform .MAC );
299
+ tpNode .put ("technologyPreview" , true );
300
+
301
+ Map <String , Object > regularNode = new HashMap <>();
302
+ regularNode .put (CapabilityType .BROWSER_NAME , BrowserType .SAFARI );
303
+ regularNode .put (CapabilityType .PLATFORM_NAME , Platform .MAC );
304
+
305
+ assertTrue (matcher .matches (tpNode , requested ));
306
+ assertFalse (matcher .matches (regularNode , requested ));
307
+ }
308
+
309
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
310
+ @ Test
311
+ public void shouldMatchRegularSafariOnlyWithDeprecatedPlatformCapability () {
205
312
Map <String , Object > requested = new SafariOptions ().asMap ();
206
313
207
314
Map <String , Object > tpNode = new HashMap <>();
@@ -217,4 +324,47 @@ public void shouldMatchRegularSafariOnly() {
217
324
assertTrue (matcher .matches (regularNode , requested ));
218
325
}
219
326
327
+ @ Test
328
+ public void shouldMatchRegularSafariOnly () {
329
+ Map <String , Object > requested = new SafariOptions ().asMap ();
330
+
331
+ Map <String , Object > tpNode = new HashMap <>();
332
+ tpNode .put (CapabilityType .BROWSER_NAME , BrowserType .SAFARI );
333
+ tpNode .put (CapabilityType .PLATFORM_NAME , Platform .MAC );
334
+ tpNode .put ("technologyPreview" , true );
335
+
336
+ Map <String , Object > regularNode = new HashMap <>();
337
+ regularNode .put (CapabilityType .BROWSER_NAME , BrowserType .SAFARI );
338
+ regularNode .put (CapabilityType .PLATFORM_NAME , Platform .MAC );
339
+
340
+ assertFalse (matcher .matches (tpNode , requested ));
341
+ assertTrue (matcher .matches (regularNode , requested ));
342
+ }
343
+
344
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
345
+ @ Test
346
+ public void shouldMatchWhenRequestedHasDeprecatedPlatformCapability () {
347
+ Map <String , Object > requested = new FirefoxOptions ().asMap ();
348
+ requested .put (CapabilityType .PLATFORM , Platform .ANY );
349
+
350
+ Map <String , Object > node = new HashMap <>();
351
+ node .put (CapabilityType .BROWSER_NAME , BrowserType .FIREFOX );
352
+ node .put (CapabilityType .PLATFORM_NAME , Platform .LINUX );
353
+
354
+ assertTrue (matcher .matches (node , requested ));
355
+ }
356
+
357
+ // TODO remove test when CapabilityType.PLATFORM is removed from code base
358
+ @ Test
359
+ public void shouldMatchWhenNodeHasDeprecatedPlatformCapability () {
360
+ Map <String , Object > requested = new FirefoxOptions ().asMap ();
361
+ requested .put (CapabilityType .PLATFORM_NAME , Platform .ANY );
362
+
363
+ Map <String , Object > node = new HashMap <>();
364
+ node .put (CapabilityType .BROWSER_NAME , BrowserType .FIREFOX );
365
+ node .put (CapabilityType .PLATFORM , Platform .LINUX );
366
+
367
+ assertTrue (matcher .matches (node , requested ));
368
+ }
369
+
220
370
}
0 commit comments