1
- package com .browserstack . run_local_test ;
1
+ package com .browserstack ;
2
2
3
3
import com .browserstack .local .Local ;
4
4
11
11
import java .io .FileReader ;
12
12
13
13
import io .appium .java_client .ios .IOSDriver ;
14
- import io .appium .java_client .ios .IOSElement ;
14
+ import io .appium .java_client .ios .options . XCUITestOptions ;
15
15
import org .json .simple .JSONArray ;
16
16
import org .json .simple .JSONObject ;
17
17
import org .json .simple .parser .JSONParser ;
18
18
19
19
import org .junit .runners .Parameterized ;
20
- import org .openqa .selenium .remote .DesiredCapabilities ;
21
20
22
21
import org .junit .After ;
23
22
import org .junit .Before ;
27
26
28
27
@ RunWith (Parameterized .class )
29
28
public class BrowserStackJUnitTest {
30
- public IOSDriver < IOSElement > driver ;
29
+ public IOSDriver driver ;
31
30
private Local local ;
32
31
33
32
private static JSONObject config ;
@@ -39,12 +38,14 @@ public class BrowserStackJUnitTest {
39
38
public static Iterable <? extends Object > data () throws Exception {
40
39
List <Integer > taskIDs = new ArrayList <Integer >();
41
40
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 ();
45
45
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
+ }
48
49
}
49
50
50
51
return taskIDs ;
@@ -54,47 +55,53 @@ public static Iterable<? extends Object> data() throws Exception {
54
55
public void setUp () throws Exception {
55
56
JSONArray envs = (JSONArray ) config .get ("environments" );
56
57
57
- DesiredCapabilities capabilities = new DesiredCapabilities ();
58
+ XCUITestOptions options = new XCUITestOptions ();
58
59
59
60
Map <String , String > envCapabilities = (Map <String , String >) envs .get (taskID );
60
61
Iterator it = envCapabilities .entrySet ().iterator ();
61
62
while (it .hasNext ()) {
62
63
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 ());
64
65
}
65
66
66
67
Map <String , String > commonCapabilities = (Map <String , String >) config .get ("capabilities" );
67
68
it = commonCapabilities .entrySet ().iterator ();
68
69
while (it .hasNext ()) {
69
70
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 );
72
77
}
73
78
}
74
79
80
+ JSONObject browserstackOptions = (JSONObject ) options .getCapability ("bstack:options" );
81
+
75
82
String username = System .getenv ("BROWSERSTACK_USERNAME" );
76
83
if (username == null ) {
77
- username = (String ) config .get ("username " );
84
+ username = (String ) browserstackOptions .get ("userName " );
78
85
}
79
86
80
87
String accessKey = System .getenv ("BROWSERSTACK_ACCESS_KEY" );
81
88
if (accessKey == null ) {
82
- accessKey = (String ) config .get ("access_key " );
89
+ accessKey = (String ) browserstackOptions .get ("accessKey " );
83
90
}
84
91
85
92
String app = System .getenv ("BROWSERSTACK_APP_ID" );
86
93
if (app != null && !app .isEmpty ()) {
87
- capabilities .setCapability ("app" , app );
94
+ options .setCapability ("app" , app );
88
95
}
89
96
90
- if (capabilities . getCapability ( "browserstack. local" ) != null && capabilities . getCapability ( "browserstack. local" ) == "true" ) {
97
+ if (browserstackOptions . get ( " local" ) != null && browserstackOptions . get ( " local"). toString ( ) == "true" ) {
91
98
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 );
95
102
}
96
103
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 );
98
105
}
99
106
100
107
@ After
0 commit comments