17
17
18
18
public class BrowserStackAndroidLocal {
19
19
20
- private static Local localInstance ;
21
- public static String accessKey = "BROWSERSTACK_USERNAME" ;
22
- public static String userName = "BROWSERSTACK_ACCESS_KEY" ;
23
-
20
+ private static Local localInstance ;
21
+ public static String userName = "YOUR_USERNAME" ;
22
+ public static String accessKey = "YOUR_ACCESS_KEY" ;
24
23
25
- public static void setupLocal () throws Exception {
26
- localInstance = new Local ();
27
- Map <String , String > options = new HashMap <String , String >();
28
- options .put ("key" , accessKey );
29
- localInstance .start (options );
30
- }
31
-
32
- public static void tearDownLocal () throws Exception {
33
- localInstance .stop ();
34
- }
35
24
25
+ public static void setupLocal () throws Exception {
26
+ localInstance = new Local ();
27
+ Map <String , String > options = new HashMap <String , String >();
28
+ options .put ("key" , accessKey );
29
+ localInstance .start (options );
30
+ }
36
31
32
+ public static void tearDownLocal () throws Exception {
33
+ localInstance .stop ();
34
+ }
37
35
38
36
public static void main (String [] args ) throws Exception {
39
- setupLocal ();
37
+ // Start the BrowserStack Local binary
38
+ setupLocal ();
39
+
40
+ DesiredCapabilities capabilities = new DesiredCapabilities ();
41
+
42
+ // Set your access credentials
43
+ capabilities .setCapability ("browserstack.user" , userName );
44
+ capabilities .setCapability ("browserstack.key" , accessKey );
45
+
46
+ // Set URL of the application under test
47
+ capabilities .setCapability ("app" , "bs://<app-id>" );
48
+
49
+ // Specify device and os_version for testing
50
+ capabilities .setCapability ("device" , "Google Pixel 3" );
51
+ capabilities .setCapability ("os_version" , "9.0" );
40
52
41
- DesiredCapabilities capabilities = new DesiredCapabilities ();
53
+ // Set the browserstack.local capability to true
54
+ capabilities .setCapability ("browserstack.local" , true );
42
55
43
- capabilities .setCapability ("browserstack.local" , true );
44
- capabilities .setCapability ("device" , "Samsung Galaxy S7" );
45
- capabilities .setCapability ("app" , "bs://<hashed app-id>" );
56
+ // Set other BrowserStack capabilities
57
+ capabilities .setCapability ("project" , "First Java Project" );
58
+ capabilities .setCapability ("build" , "Java Android Local" );
59
+ capabilities .setCapability ("name" , "local_test" );
60
+
46
61
47
- AndroidDriver <AndroidElement > driver = new AndroidDriver <AndroidElement >(new URL ("https://" +userName +":" +accessKey +"@hub.browserstack.com/wd/hub" ), capabilities );
62
+ // Initialise the remote Webdriver using BrowserStack remote URL
63
+ // and desired capabilities defined above
64
+ AndroidDriver <AndroidElement > driver = new AndroidDriver <AndroidElement >(
65
+ new URL ("http://hub.browserstack.com/wd/hub" ), capabilities );
48
66
67
+ // Test case for the BrowserStack sample Android Local app.
68
+ // If you have uploaded your app, update the test case here.
49
69
AndroidElement searchElement = (AndroidElement ) new WebDriverWait (driver , 30 ).until (
50
70
ExpectedConditions .elementToBeClickable (MobileBy .id ("com.example.android.basicnetworking:id/test_action" )));
51
71
searchElement .click ();
@@ -69,8 +89,10 @@ public static void main(String[] args) throws Exception {
69
89
assert (matchedString .contains ("The active connection is wifi" ));
70
90
assert (matchedString .contains ("Up and running" ));
71
91
92
+ // Invoke driver.quit() after the test is done to indicate that the test is completed.
72
93
driver .quit ();
73
94
95
+ // Stop the BrowserStack Local binary
74
96
tearDownLocal ();
75
97
76
98
}
0 commit comments