16
16
import org .testng .annotations .AfterMethod ;
17
17
import org .testng .annotations .BeforeMethod ;
18
18
19
-
20
19
public class BrowserStackTestNGTest {
21
20
public WebDriver driver ;
22
21
private Local l ;
23
22
24
- @ BeforeMethod (alwaysRun =true )
25
- @ org .testng .annotations .Parameters (value ={"config" , "environment" })
23
+ @ BeforeMethod (alwaysRun = true )
24
+ @ org .testng .annotations .Parameters (value = { "config" , "environment" })
25
+ @ SuppressWarnings ("unchecked" )
26
26
public void setUp (String config_file , String environment ) throws Exception {
27
27
JSONParser parser = new JSONParser ();
28
28
JSONObject config = (JSONObject ) parser .parse (new FileReader ("src/test/resources/conf/" + config_file ));
@@ -33,42 +33,45 @@ public void setUp(String config_file, String environment) throws Exception {
33
33
Map <String , String > envCapabilities = (Map <String , String >) envs .get (environment );
34
34
Iterator it = envCapabilities .entrySet ().iterator ();
35
35
while (it .hasNext ()) {
36
- Map .Entry pair = (Map .Entry )it .next ();
36
+ Map .Entry pair = (Map .Entry ) it .next ();
37
37
capabilities .setCapability (pair .getKey ().toString (), pair .getValue ().toString ());
38
38
}
39
-
39
+
40
40
Map <String , String > commonCapabilities = (Map <String , String >) config .get ("capabilities" );
41
41
it = commonCapabilities .entrySet ().iterator ();
42
42
while (it .hasNext ()) {
43
- Map .Entry pair = (Map .Entry )it .next ();
44
- if (capabilities .getCapability (pair .getKey ().toString ()) == null ){
43
+ Map .Entry pair = (Map .Entry ) it .next ();
44
+ if (capabilities .getCapability (pair .getKey ().toString ()) == null ) {
45
45
capabilities .setCapability (pair .getKey ().toString (), pair .getValue ().toString ());
46
46
}
47
47
}
48
48
49
49
String username = System .getenv ("BROWSERSTACK_USERNAME" );
50
- if (username == null ) {
50
+ if (username == null ) {
51
51
username = (String ) config .get ("user" );
52
52
}
53
53
54
54
String accessKey = System .getenv ("BROWSERSTACK_ACCESS_KEY" );
55
- if (accessKey == null ) {
55
+ if (accessKey == null ) {
56
56
accessKey = (String ) config .get ("key" );
57
57
}
58
58
59
- if (capabilities .getCapability ("browserstack.local" ) != null && capabilities .getCapability ("browserstack.local" ) == "true" ){
59
+ if (capabilities .getCapability ("browserstack.local" ) != null
60
+ && capabilities .getCapability ("browserstack.local" ) == "true" ) {
60
61
l = new Local ();
61
62
Map <String , String > options = new HashMap <String , String >();
62
63
options .put ("key" , accessKey );
63
64
l .start (options );
64
65
}
65
66
66
- driver = new RemoteWebDriver (new URL ("http://" +username +":" +accessKey +"@" +config .get ("server" )+"/wd/hub" ), capabilities );
67
+ driver = new RemoteWebDriver (
68
+ new URL ("http://" + username + ":" + accessKey + "@" + config .get ("server" ) + "/wd/hub" ), capabilities );
67
69
}
68
70
69
- @ AfterMethod (alwaysRun = true )
71
+ @ AfterMethod (alwaysRun = true )
70
72
public void tearDown () throws Exception {
71
73
driver .quit ();
72
- if (l != null ) l .stop ();
74
+ if (l != null )
75
+ l .stop ();
73
76
}
74
77
}
0 commit comments