@@ -46,6 +46,11 @@ type seleniumGridScalerMetadata struct {
46
46
TargetValue int64
47
47
}
48
48
49
+ type Platform struct {
50
+ name string
51
+ family * Platform
52
+ }
53
+
49
54
type SeleniumResponse struct {
50
55
Data Data `json:"data"`
51
56
}
@@ -350,9 +355,8 @@ func checkRequestCapabilitiesMatch(request map[string]interface{}, browserName s
350
355
(_browserVersion != "" && strings .HasPrefix (browserVersion , _browserVersion ))
351
356
352
357
// Check if platformName matches
353
- _platformName := getPlatformName (request )
354
- platformNameMatch := (_platformName == "" || strings .EqualFold ("any" , _platformName ) || strings .EqualFold (platformName , _platformName )) &&
355
- (platformName == "" || platformName == "any" || strings .EqualFold (platformName , _platformName ))
358
+ platformNameMatch := strings .EqualFold (GetPlatform (platformName ).name , GetPlatform (getPlatformName (request )).name ) ||
359
+ isSameFamily (GetPlatform (platformName ), GetPlatform (getPlatformName (request )))
356
360
357
361
return browserNameMatch && browserVersionMatch && platformNameMatch && managedDownloadsEnabled (capabilities , request ) && extensionCapabilitiesMatch (request , capabilities )
358
362
}
@@ -371,9 +375,8 @@ func checkStereotypeCapabilitiesMatch(capability map[string]interface{}, browser
371
375
(_browserVersion != "" && strings .HasPrefix (browserVersion , _browserVersion ))
372
376
373
377
// Check if platformName matches
374
- _platformVersion := getPlatformName (capability )
375
- platformNameMatch := (_platformVersion == "" || strings .EqualFold ("any" , _platformVersion ) || strings .EqualFold (platformName , _platformVersion )) &&
376
- (platformName == "" || platformName == "any" || strings .EqualFold (platformName , _platformVersion ))
378
+ platformNameMatch := strings .EqualFold (GetPlatform (platformName ).name , GetPlatform (getPlatformName (capability )).name ) ||
379
+ isSameFamily (GetPlatform (platformName ), GetPlatform (getPlatformName (capability )))
377
380
378
381
return browserNameMatch && browserVersionMatch && platformNameMatch && managedDownloadsEnabled (capabilities , capability ) && extensionCapabilitiesMatch (capability , capabilities )
379
382
}
@@ -489,3 +492,107 @@ func getCountFromSeleniumResponse(b []byte, browserName string, browserVersion s
489
492
490
493
return int64 (len (newRequestNodes )), onGoingSessions , nil
491
494
}
495
+
496
+ // Mapping of platform name enum used in the Selenium Grid core
497
+ // https://github.com/SeleniumHQ/selenium/blob/trunk/java/src/org/openqa/selenium/Platform.java
498
+ var (
499
+ Windows = Platform {"windows" , nil }
500
+ XP = Platform {"Windows XP" , & Windows }
501
+ Vista = Platform {"Windows Vista" , & Windows }
502
+ Win7 = Platform {"Windows 7" , & Windows }
503
+ Win8 = Platform {"Windows 8" , & Windows }
504
+ Win8_1 = Platform {"Windows 8.1" , & Windows }
505
+ Win10 = Platform {"Windows 10" , & Windows }
506
+ Win11 = Platform {"Windows 11" , & Windows }
507
+ Mac = Platform {"mac" , nil }
508
+ SnowLeopard = Platform {"OS X 10.6" , & Mac }
509
+ MountainLion = Platform {"OS X 10.8" , & Mac }
510
+ Mavericks = Platform {"OS X 10.9" , & Mac }
511
+ Yosemite = Platform {"OS X 10.10" , & Mac }
512
+ ElCapitan = Platform {"OS X 10.11" , & Mac }
513
+ Sierra = Platform {"macOS 10.12" , & Mac }
514
+ HighSierra = Platform {"macOS 10.13" , & Mac }
515
+ Mojave = Platform {"macOS 10.14" , & Mac }
516
+ Catalina = Platform {"macOS 10.15" , & Mac }
517
+ BigSur = Platform {"macOS 11.0" , & Mac }
518
+ Monterey = Platform {"macOS 12.0" , & Mac }
519
+ Ventura = Platform {"macOS 13.0" , & Mac }
520
+ Sonoma = Platform {"macOS 14.0" , & Mac }
521
+ Sequoia = Platform {"macOS 15.0" , & Mac }
522
+ Unix = Platform {"unix" , nil }
523
+ Linux = Platform {"linux" , & Unix }
524
+ Bsd = Platform {"bsd" , & Unix }
525
+ Solaris = Platform {"solaris" , & Unix }
526
+ Android = Platform {"android" , nil }
527
+ IOS = Platform {"iOS" , nil }
528
+ Any = Platform {"any" , nil }
529
+ )
530
+
531
+ func isSameFamily (p1 , p2 Platform ) bool {
532
+ return p1 .family != nil && p2 .family != nil && p1 .family == p2 .family
533
+ }
534
+
535
+ func GetPlatform (input string ) Platform {
536
+ switch strings .ToLower (input ) {
537
+ case "windows" :
538
+ return Windows
539
+ case "windows server 2003" , "xp" , "winnt" , "windows_nt" , "windows nt" :
540
+ return XP
541
+ case "windows server 2008" , "windows vista" :
542
+ return Vista
543
+ case "windows 7" , "win7" :
544
+ return Win7
545
+ case "windows server 2012" , "windows 8" , "win8" :
546
+ return Win8
547
+ case "windows 8.1" , "win8.1" :
548
+ return Win8_1
549
+ case "windows 10" , "win10" :
550
+ return Win10
551
+ case "windows 11" , "win11" :
552
+ return Win11
553
+ case "mac" , "darwin" , "macos" , "mac os x" , "os x" :
554
+ return Mac
555
+ case "os x 10.6" , "macos 10.6" , "snow leopard" :
556
+ return SnowLeopard
557
+ case "os x 10.8" , "macos 10.8" , "mountain lion" :
558
+ return MountainLion
559
+ case "os x 10.9" , "macos 10.9" , "mavericks" :
560
+ return Mavericks
561
+ case "os x 10.10" , "macos 10.10" , "yosemite" :
562
+ return Yosemite
563
+ case "os x 10.11" , "macos 10.11" , "el capitan" :
564
+ return ElCapitan
565
+ case "os x 10.12" , "macos 10.12" , "sierra" :
566
+ return Sierra
567
+ case "os x 10.13" , "macos 10.13" , "high sierra" :
568
+ return HighSierra
569
+ case "os x 10.14" , "macos 10.14" , "mojave" :
570
+ return Mojave
571
+ case "os x 10.15" , "macos 10.15" , "catalina" :
572
+ return Catalina
573
+ case "os x 11.0" , "macos 11.0" , "big sur" :
574
+ return BigSur
575
+ case "os x 12.0" , "macos 12.0" , "monterey" :
576
+ return Monterey
577
+ case "os x 13.0" , "macos 13.0" , "ventura" :
578
+ return Ventura
579
+ case "os x 14.0" , "macos 14.0" , "sonoma" :
580
+ return Sonoma
581
+ case "os x 15.0" , "macos 15.0" , "sequoia" :
582
+ return Sequoia
583
+ case "linux" :
584
+ return Linux
585
+ case "bsd" :
586
+ return Bsd
587
+ case "solaris" :
588
+ return Solaris
589
+ case "android" , "dalvik" :
590
+ return Android
591
+ case "ios" :
592
+ return IOS
593
+ case "any" , "" :
594
+ return Any
595
+ default :
596
+ return Platform {strings .ToLower (input ), nil }
597
+ }
598
+ }
0 commit comments