Skip to content

Commit eda6352

Browse files
committed
Updating Local test for Android and iOS.
1 parent 788a1f8 commit eda6352

File tree

2 files changed

+74
-30
lines changed

2 files changed

+74
-30
lines changed

src/test/java/android/BrowserStackAndroidLocal.java

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,55 @@
1717

1818
public class BrowserStackAndroidLocal {
1919

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";
2423

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-
}
3524

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+
}
3631

32+
public static void tearDownLocal() throws Exception {
33+
localInstance.stop();
34+
}
3735

3836
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");
4052

41-
DesiredCapabilities capabilities = new DesiredCapabilities();
53+
// Set the browserstack.local capability to true
54+
capabilities.setCapability("browserstack.local", true);
4255

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+
4661

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);
4866

67+
// Test case for the BrowserStack sample Android Local app.
68+
// If you have uploaded your app, update the test case here.
4969
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
5070
ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action")));
5171
searchElement.click();
@@ -69,8 +89,10 @@ public static void main(String[] args) throws Exception {
6989
assert(matchedString.contains("The active connection is wifi"));
7090
assert(matchedString.contains("Up and running"));
7191

92+
// Invoke driver.quit() after the test is done to indicate that the test is completed.
7293
driver.quit();
7394

95+
// Stop the BrowserStack Local binary
7496
tearDownLocal();
7597

7698
}

src/test/java/ios/BrowserStackiOSLocal.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
public class BrowserStackiOSLocal {
2525

2626
private static Local localInstance;
27-
public static String accessKey = "BROWSERSTACK_USERNAME";
28-
public static String userName = "BROWSERSTACK_ACCESS_KEY";
27+
public static String accessKey = "YOUR_USERNAME";
28+
public static String userName = "YOUR_ACCESS_KEY";
2929

3030

3131
public static void setupLocal() throws Exception {
@@ -41,17 +41,37 @@ public static void tearDownLocal() throws Exception {
4141

4242

4343
public static void main(String[] args) throws Exception {
44-
44+
// Start the BrowserStack Local binary
4545
setupLocal();
4646

4747
DesiredCapabilities capabilities = new DesiredCapabilities();
4848

49-
capabilities.setCapability("browserstack.local", true);
50-
capabilities.setCapability("device", "iPhone 7");
51-
capabilities.setCapability("app", "bs://<hashed app-id>");
52-
53-
IOSDriver<IOSElement> driver = new IOSDriver<IOSElement>(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities);
54-
49+
// Set your access credentials
50+
capabilities.setCapability("browserstack.user", userName);
51+
capabilities.setCapability("browserstack.key", accessKey);
52+
53+
// Set URL of the application under test
54+
capabilities.setCapability("app", "bs://<app-id>");
55+
56+
// Specify device and os_version for testing
57+
capabilities.setCapability("device", "iPhone 11 Pro");
58+
capabilities.setCapability("os_version", "13");
59+
60+
// Set the browserstack.local capability to true
61+
capabilities.setCapability("browserstack.local", true);
62+
63+
// Set other BrowserStack capabilities
64+
capabilities.setCapability("project", "First Java Project");
65+
capabilities.setCapability("build", "Java iOS Local");
66+
capabilities.setCapability("name", "local_test");
67+
68+
// Initialise the remote Webdriver using BrowserStack remote URL
69+
// and desired capabilities defined above
70+
IOSDriver<IOSElement> driver = new IOSDriver<IOSElement>(
71+
new URL("http://hub.browserstack.com/wd/hub"), capabilities);
72+
73+
// Test case for the BrowserStack sample iOS Local app.
74+
// If you have uploaded your app, update the test case here.
5575
IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until(
5676
ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal")));
5777
testButton.click();
@@ -78,8 +98,10 @@ public Boolean apply(WebDriver d) {
7898
String expectedString = "Up and running";
7999
assert(resultString.contains(expectedString.toLowerCase()));
80100

101+
// Invoke driver.quit() after the test is done to indicate that the test is completed.
81102
driver.quit();
82-
103+
104+
// Stop the BrowserStack Local binary
83105
tearDownLocal();
84106

85107
}

0 commit comments

Comments
 (0)