@@ -18,17 +18,7 @@ public static JSONObject getCombinedCapability(Map<String, String> envCapabiliti
1818 JSONObject capabilities = new JSONObject ();
1919 JSONObject commonCapabilities = (JSONObject ) config .get ("capabilities" );
2020 Iterator it = envCapabilities .entrySet ().iterator ();
21- while (it .hasNext ()) {
22- Map .Entry pair = (Map .Entry ) it .next ();
23- capabilities .put (pair .getKey ().toString (), pair .getValue ().toString ());
24- }
25- it = commonCapabilities .entrySet ().iterator ();
26- while (it .hasNext ()) {
27- Map .Entry pair = (Map .Entry ) it .next ();
28- if (capabilities .get (pair .getKey ().toString ()) == null ) {
29- capabilities .put (pair .getKey ().toString (), pair .getValue ().toString ());
30- }
31- }
21+
3222 String username = System .getenv ("BROWSERSTACK_USERNAME" );
3323 if (username == null ) {
3424 username = (String ) config .get ("user" );
@@ -38,8 +28,28 @@ public static JSONObject getCombinedCapability(Map<String, String> envCapabiliti
3828 if (accessKey == null ) {
3929 accessKey = (String ) config .get ("key" );
4030 }
41- capabilities .put ("browserstack.user" , username );
42- capabilities .put ("browserstack.key" , accessKey );
31+
32+ JSONObject bstackOptions = commonCapabilities .get ("bstack:options" ) != null ? (JSONObject ) commonCapabilities .get ("bstack:options" ) : new JSONObject ();
33+ bstackOptions .putIfAbsent ("userName" , username );
34+ bstackOptions .putIfAbsent ("accessKey" , accessKey );
35+ capabilities .put ("bstack:options" , bstackOptions );
36+
37+ while (it .hasNext ()) {
38+ Map .Entry pair = (Map .Entry ) it .next ();
39+ capabilities .put (pair .getKey ().toString (), pair .getValue ());
40+ }
41+
42+ it = commonCapabilities .entrySet ().iterator ();
43+ while (it .hasNext ()) {
44+ Map .Entry pair = (Map .Entry ) it .next ();
45+ if (capabilities .get (pair .getKey ().toString ()) == null ) {
46+ capabilities .put (pair .getKey ().toString (), pair .getValue ());
47+ } else if (pair .getKey ().toString ().equalsIgnoreCase ("bstack:options" )) {
48+ HashMap <String , String > bstackOptionsMap = (HashMap ) pair .getValue ();
49+ bstackOptionsMap .putAll ((HashMap ) capabilities .get ("bstack:options" ));
50+ capabilities .put (pair .getKey ().toString (), bstackOptionsMap );
51+ }
52+ }
4353 return capabilities ;
4454 }
4555
@@ -49,17 +59,18 @@ public static void setSessionStatus(WebDriver webDriver, String status, String r
4959 }
5060
5161 public static boolean isLocal (ManagedWebDriver managedWebDriver ) {
52- JSONObject platform = managedWebDriver .getPlatform ();
53- return platform .get ("browserstack. local" ) != null && platform .get ("browserstack. local" ).toString ().equalsIgnoreCase ("true" );
62+ JSONObject platform = ( JSONObject ) managedWebDriver .getPlatform (). get ( "bstack:options" );
63+ return platform .get ("local" ) != null && platform .get ("local" ).toString ().equalsIgnoreCase ("true" );
5464 }
5565
5666 public static void startLocal (Local local , ManagedWebDriver managedWebDriver ) {
5767 JSONParser parser = new JSONParser ();
5868 Map <String , String > options = new HashMap <>();
59- options .put ("key" , managedWebDriver .getPlatform ().get ("browserstack.key" ).toString ());
69+ JSONObject testConfig = (JSONObject ) managedWebDriver .getPlatform ().get ("bstack:options" );
70+ options .put ("key" , testConfig .get ("accessKey" ).toString ());
6071 String capabilitiesConfigFile = System .getProperty ("caps" , "src/test/resources/conf/local.conf.json" );
6172 try {
62- JSONObject testConfig = (JSONObject ) parser .parse (new FileReader (capabilitiesConfigFile ));
73+ testConfig = (JSONObject ) parser .parse (new FileReader (capabilitiesConfigFile ));
6374 if (testConfig .containsKey ("localOptions" )) {
6475 JSONObject localOptions = (JSONObject ) testConfig .get ("localOptions" );
6576 options .forEach (localOptions ::putIfAbsent );
0 commit comments