1
1
package com .browserstack ;
2
- import com .browserstack .local .Local ;
3
2
4
- import java .io .File ;
5
3
import java .io .FileReader ;
6
- import java .io .IOException ;
7
- import java .io .InputStream ;
8
4
import java .net .URL ;
9
5
import java .util .HashMap ;
10
- import java .util .Map ;
11
- import java .util .ArrayList ;
12
- import java .util .List ;
13
6
import java .util .Iterator ;
7
+ import java .util .Map ;
8
+
9
+ import com .browserstack .local .Local ;
10
+
14
11
import org .json .simple .JSONObject ;
15
- import org .json .simple .JSONArray ;
16
12
import org .json .simple .parser .JSONParser ;
17
-
18
13
import org .openqa .selenium .WebDriver ;
19
- import org .openqa .selenium .remote .RemoteWebDriver ;
20
14
import org .openqa .selenium .remote .DesiredCapabilities ;
21
-
22
- import org .testng .annotations .BeforeMethod ;
15
+ import org .openqa .selenium .remote .RemoteWebDriver ;
23
16
import org .testng .annotations .AfterMethod ;
24
- import org .testng .annotations .Test ;
25
- import org .testng .annotations .Parameters ;
26
- import org .testng .annotations .DataProvider ;
27
- import org .testng .annotations .Factory ;
28
- import org .testng .Assert ;
29
-
17
+ import org .testng .annotations .BeforeMethod ;
30
18
31
19
public class BrowserStackTestNGTest {
32
20
public WebDriver driver ;
33
21
private Local l ;
34
22
35
- @ BeforeMethod (alwaysRun =true )
36
- @ org .testng .annotations .Parameters (value ={"config" , "environment" })
23
+ @ BeforeMethod (alwaysRun = true )
24
+ @ org .testng .annotations .Parameters (value = { "config" , "environment" })
25
+ @ SuppressWarnings ("unchecked" )
37
26
public void setUp (String config_file , String environment ) throws Exception {
38
27
JSONParser parser = new JSONParser ();
39
28
JSONObject config = (JSONObject ) parser .parse (new FileReader ("src/test/resources/conf/" + config_file ));
@@ -44,42 +33,46 @@ public void setUp(String config_file, String environment) throws Exception {
44
33
Map <String , String > envCapabilities = (Map <String , String >) envs .get (environment );
45
34
Iterator it = envCapabilities .entrySet ().iterator ();
46
35
while (it .hasNext ()) {
47
- Map .Entry pair = (Map .Entry )it .next ();
36
+ Map .Entry pair = (Map .Entry ) it .next ();
48
37
capabilities .setCapability (pair .getKey ().toString (), pair .getValue ().toString ());
49
38
}
50
-
39
+
51
40
Map <String , String > commonCapabilities = (Map <String , String >) config .get ("capabilities" );
52
41
it = commonCapabilities .entrySet ().iterator ();
53
42
while (it .hasNext ()) {
54
- Map .Entry pair = (Map .Entry )it .next ();
55
- if (capabilities .getCapability (pair .getKey ().toString ()) == null ){
43
+ Map .Entry pair = (Map .Entry ) it .next ();
44
+ if (capabilities .getCapability (pair .getKey ().toString ()) == null ) {
56
45
capabilities .setCapability (pair .getKey ().toString (), pair .getValue ().toString ());
57
46
}
58
47
}
59
48
60
49
String username = System .getenv ("BROWSERSTACK_USERNAME" );
61
- if (username == null ) {
50
+ if (username == null ) {
62
51
username = (String ) config .get ("user" );
63
52
}
64
53
65
54
String accessKey = System .getenv ("BROWSERSTACK_ACCESS_KEY" );
66
- if (accessKey == null ) {
55
+ if (accessKey == null ) {
67
56
accessKey = (String ) config .get ("key" );
68
57
}
69
58
70
- if (capabilities .getCapability ("browserstack.local" ) != null && capabilities .getCapability ("browserstack.local" ) == "true" ){
59
+ if (capabilities .getCapability ("browserstack.local" ) != null
60
+ && capabilities .getCapability ("browserstack.local" ) == "true" ) {
71
61
l = new Local ();
72
62
Map <String , String > options = new HashMap <String , String >();
73
63
options .put ("key" , accessKey );
74
64
l .start (options );
75
65
}
76
66
77
- 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 );
78
69
}
79
70
80
- @ AfterMethod (alwaysRun = true )
71
+ @ AfterMethod (alwaysRun = true )
81
72
public void tearDown () throws Exception {
82
73
driver .quit ();
83
- if (l != null ) l .stop ();
74
+ if (l != null ) {
75
+ l .stop ();
76
+ }
84
77
}
85
78
}
0 commit comments