-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathBrowserStackSample.java
More file actions
76 lines (63 loc) · 2.81 KB
/
BrowserStackSample.java
File metadata and controls
76 lines (63 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package android;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class BrowserStackSample {
public static void main(String[] args)
throws MalformedURLException, InterruptedException {
UiAutomator2Options options = new UiAutomator2Options();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
// Set your access credentials
browserstackOptions.put("userName", "YOUR_USERNAME");
browserstackOptions.put("accessKey", "YOUR_ACCESS_KEY");
// Set other BrowserStack capabilities
browserstackOptions.put("appiumVersion", "1.22.0");
browserstackOptions.put("projectName", "First Java Project");
browserstackOptions.put("buildName", "browserstack-build-1");
browserstackOptions.put("sessionName", "BStack first_test");
// Passing browserstack capabilities inside bstack:options
options.setCapability("bstack:options", browserstackOptions);
// Set URL of the application under test
options.setCapability("app", "bs://<app-id>");
// Specify deviceName and platformName for testing
options.setCapability("deviceName", "Google Pixel 3");
options.setCapability("platformName", "android");
options.setCapability("platformVersion", "9.0");
// Initialise the remote Webdriver using BrowserStack remote URL
// and desired capabilities defined above
AndroidDriver driver = new AndroidDriver(
new URL("http://hub.browserstack.com/wd/hub"),
options);
// Test case for the BrowserStack sample Android app.
// If you have uploaded your app, update the test case here.
WebElement searchElement = (WebElement) new WebDriverWait(
driver,
Duration.ofSeconds(30))
.until(
ExpectedConditions.elementToBeClickable(
AppiumBy.accessibilityId("Search Wikipedia")));
searchElement.click();
WebElement insertTextElement = (WebElement) new WebDriverWait(
driver,
Duration.ofSeconds(30))
.until(
ExpectedConditions.elementToBeClickable(
AppiumBy.id("org.wikipedia.alpha:id/search_src_text")));
insertTextElement.sendKeys("BrowserStack");
Thread.sleep(5000);
List<WebElement> allProductsName = driver.findElements(
AppiumBy.className("android.widget.TextView"));
assert (allProductsName.size() > 0);
// Invoke driver.quit() after the test is done to indicate that the test is
// completed.
driver.quit();
}
}