1- package com .browserstack . run_local_test ;
1+ package com .browserstack ;
22
33import com .browserstack .local .Local ;
44
1111import java .io .FileReader ;
1212
1313import io .appium .java_client .ios .IOSDriver ;
14- import io .appium .java_client .ios .IOSElement ;
14+ import io .appium .java_client .ios .options . XCUITestOptions ;
1515import org .json .simple .JSONArray ;
1616import org .json .simple .JSONObject ;
1717import org .json .simple .parser .JSONParser ;
1818
1919import org .junit .runners .Parameterized ;
20- import org .openqa .selenium .remote .DesiredCapabilities ;
2120
2221import org .junit .After ;
2322import org .junit .Before ;
2726
2827@ RunWith (Parameterized .class )
2928public class BrowserStackJUnitTest {
30- public IOSDriver < IOSElement > driver ;
29+ public IOSDriver driver ;
3130 private Local local ;
3231
3332 private static JSONObject config ;
@@ -39,12 +38,14 @@ public class BrowserStackJUnitTest {
3938 public static Iterable <? extends Object > data () throws Exception {
4039 List <Integer > taskIDs = new ArrayList <Integer >();
4140
42- JSONParser parser = new JSONParser ();
43- config = (JSONObject ) parser .parse (new FileReader ("src/test/resources/com/browserstack/run_local_test/local.conf.json" ));
44- int envs = ((JSONArray ) config .get ("environments" )).size ();
41+ if (System .getProperty ("config" ) != null ) {
42+ JSONParser parser = new JSONParser ();
43+ config = (JSONObject ) parser .parse (new FileReader ("src/test/resources/com/browserstack/" + System .getProperty ("config" )));
44+ int envs = ((JSONArray ) config .get ("environments" )).size ();
4545
46- for (int i = 0 ; i < envs ; i ++) {
47- taskIDs .add (i );
46+ for (int i = 0 ; i < envs ; i ++) {
47+ taskIDs .add (i );
48+ }
4849 }
4950
5051 return taskIDs ;
@@ -54,47 +55,53 @@ public static Iterable<? extends Object> data() throws Exception {
5455 public void setUp () throws Exception {
5556 JSONArray envs = (JSONArray ) config .get ("environments" );
5657
57- DesiredCapabilities capabilities = new DesiredCapabilities ();
58+ XCUITestOptions options = new XCUITestOptions ();
5859
5960 Map <String , String > envCapabilities = (Map <String , String >) envs .get (taskID );
6061 Iterator it = envCapabilities .entrySet ().iterator ();
6162 while (it .hasNext ()) {
6263 Map .Entry pair = (Map .Entry ) it .next ();
63- capabilities .setCapability (pair .getKey ().toString (), pair .getValue ().toString ());
64+ options .setCapability (pair .getKey ().toString (), pair .getValue ().toString ());
6465 }
6566
6667 Map <String , String > commonCapabilities = (Map <String , String >) config .get ("capabilities" );
6768 it = commonCapabilities .entrySet ().iterator ();
6869 while (it .hasNext ()) {
6970 Map .Entry pair = (Map .Entry ) it .next ();
70- if (capabilities .getCapability (pair .getKey ().toString ()) == null ) {
71- capabilities .setCapability (pair .getKey ().toString (), pair .getValue ().toString ());
71+ if (options .getCapability (pair .getKey ().toString ()) == null ) {
72+ options .setCapability (pair .getKey ().toString (), pair .getValue ());
73+ }else if (pair .getKey ().toString ().equalsIgnoreCase ("bstack:options" )){
74+ HashMap bstackOptionsMap = (HashMap ) pair .getValue ();
75+ bstackOptionsMap .putAll ((HashMap ) options .getCapability ("bstack:options" ));
76+ options .setCapability (pair .getKey ().toString (), bstackOptionsMap );
7277 }
7378 }
7479
80+ JSONObject browserstackOptions = (JSONObject ) options .getCapability ("bstack:options" );
81+
7582 String username = System .getenv ("BROWSERSTACK_USERNAME" );
7683 if (username == null ) {
77- username = (String ) config .get ("username " );
84+ username = (String ) browserstackOptions .get ("userName " );
7885 }
7986
8087 String accessKey = System .getenv ("BROWSERSTACK_ACCESS_KEY" );
8188 if (accessKey == null ) {
82- accessKey = (String ) config .get ("access_key " );
89+ accessKey = (String ) browserstackOptions .get ("accessKey " );
8390 }
8491
8592 String app = System .getenv ("BROWSERSTACK_APP_ID" );
8693 if (app != null && !app .isEmpty ()) {
87- capabilities .setCapability ("app" , app );
94+ options .setCapability ("app" , app );
8895 }
8996
90- if (capabilities . getCapability ( "browserstack. local" ) != null && capabilities . getCapability ( "browserstack. local" ) == "true" ) {
97+ if (browserstackOptions . get ( " local" ) != null && browserstackOptions . get ( " local"). toString ( ) == "true" ) {
9198 local = new Local ();
92- Map <String , String > options = new HashMap <String , String >();
93- options .put ("key" , accessKey );
94- local .start (options );
99+ Map <String , String > LocalOptions = new HashMap <String , String >();
100+ LocalOptions .put ("key" , accessKey );
101+ local .start (LocalOptions );
95102 }
96103
97- driver = new IOSDriver (new URL ("http://" + username + ":" + accessKey + "@" + config .get ("server" ) + "/wd/hub" ), capabilities );
104+ driver = new IOSDriver (new URL ("http://" + config .get ("server" )+ "/wd/hub" ), options );
98105 }
99106
100107 @ After
0 commit comments