|
16 | 16 | public class BrowserStackSample { |
17 | 17 |
|
18 | 18 | public static void main(String[] args) throws MalformedURLException, InterruptedException { |
19 | | - DesiredCapabilities caps = new DesiredCapabilities(); |
20 | | - |
21 | | - // Set your access credentials |
22 | | - caps.setCapability("browserstack.user", "YOUR_USERNAME"); |
23 | | - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); |
| 19 | + |
| 20 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 21 | + |
| 22 | + // Set your access credentials |
| 23 | + caps.setCapability("browserstack.user", "YOUR_USERNAME"); |
| 24 | + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); |
24 | 25 |
|
25 | 26 | // Set URL of the application under test |
26 | 27 | caps.setCapability("app", "bs://<app-id>"); |
27 | | - |
28 | | - // Specify device and os_version for testing |
29 | | - caps.setCapability("device", "iPhone 11 Pro"); |
30 | | - caps.setCapability("os_version", "13"); |
31 | 28 |
|
32 | | - // Set other BrowserStack capabilities |
33 | | - caps.setCapability("project", "First Java Project"); |
34 | | - caps.setCapability("build", "browserstack-build-1"); |
35 | | - caps.setCapability("name", "first_test"); |
36 | | - |
37 | | - |
38 | | - // Initialise the remote Webdriver using BrowserStack remote URL |
39 | | - // and desired capabilities defined above |
| 29 | + // Specify device and os_version for testing |
| 30 | + caps.setCapability("deviceName", "iPhone 11 Pro"); |
| 31 | + caps.setCapability("platformName", "ios"); |
| 32 | + caps.setCapability("platformVersion", "13"); |
| 33 | + |
| 34 | + // Set other BrowserStack capabilities |
| 35 | + caps.setCapability("project", "First Java Project"); |
| 36 | + caps.setCapability("build", "browserstack-build-1"); |
| 37 | + caps.setCapability("name", "first_test"); |
| 38 | + |
| 39 | + // Initialise the remote Webdriver using BrowserStack remote URL |
| 40 | + // and desired capabilities defined above |
40 | 41 | RemoteWebDriver driver = new RemoteWebDriver( |
41 | | - new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); |
| 42 | + new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); |
42 | 43 |
|
43 | | - |
44 | 44 | // Test case for the BrowserStack sample iOS app. |
45 | 45 | // If you have uploaded your app, update the test case here. |
46 | 46 | WebElement textButton = (WebElement) new WebDriverWait(driver, 30).until( |
47 | 47 | ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Button"))); |
48 | 48 | textButton.click(); |
| 49 | + |
49 | 50 | WebElement textInput = (WebElement) new WebDriverWait(driver, 30).until( |
50 | 51 | ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); |
51 | 52 | textInput.sendKeys("hello@browserstack.com"); |
52 | 53 | Thread.sleep(5000); |
| 54 | + |
53 | 55 | WebElement textOutput = (WebElement) new WebDriverWait(driver, 30).until( |
54 | 56 | ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); |
55 | 57 | if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) |
56 | 58 | assert(true); |
57 | 59 | else |
58 | 60 | assert(false); |
59 | | - |
| 61 | + |
60 | 62 | // Invoke driver.quit() after the test is done to indicate that the test is completed. |
61 | 63 | driver.quit(); |
62 | | - |
63 | | - } |
64 | | - |
| 64 | + } |
65 | 65 | } |
0 commit comments