55import java .util .function .Function ;
66import java .net .MalformedURLException ;
77
8- import org .openqa .selenium .support .ui .ExpectedConditions ;
9- import org .openqa .selenium .support .ui .WebDriverWait ;
10- import org .openqa .selenium .remote .DesiredCapabilities ;
11-
128import io .appium .java_client .AppiumBy ;
139import org .openqa .selenium .WebDriver ;
1410import org .openqa .selenium .WebElement ;
1511import org .openqa .selenium .remote .RemoteWebDriver ;
1612
13+ import org .openqa .selenium .support .ui .ExpectedConditions ;
14+ import org .openqa .selenium .support .ui .WebDriverWait ;
15+ import org .openqa .selenium .remote .DesiredCapabilities ;
1716
1817public class BrowserStackSample {
1918
@@ -23,43 +22,41 @@ public static void main(String[] args) throws MalformedURLException, Interrupted
2322
2423 // Set your access credentials
2524 caps .setCapability ("browserstack.user" , "YOUR_USERNAME" );
26- caps .setCapability ("browserstack.key" , "YOUR_ACCESS_KEY" );
25+ caps .setCapability ("browserstack.key" , "YOUR_ACCESS_KEY" );
2726
2827 // Set URL of the application under test
2928 caps .setCapability ("app" , "bs://<app-id>" );
3029
31- // Specify device and os_version for testing
32- caps .setCapability ("device" , "Google Pixel 3" );
33- caps .setCapability ("os_version" , "9.0" );
30+ // Specify deviceName and platformName for testing
31+ caps .setCapability ("deviceName" , "Google Pixel 3" );
32+ caps .setCapability ("platformName" , "android" );
33+ caps .setCapability ("platformVersion" , "9.0" );
3434
3535 // Set other BrowserStack capabilities
3636 caps .setCapability ("project" , "First Java Project" );
3737 caps .setCapability ("build" , "browserstack-build-1" );
3838 caps .setCapability ("name" , "first_test" );
3939
40-
4140 // Initialise the remote Webdriver using BrowserStack remote URL
4241 // and desired capabilities defined above
43- RemoteWebDriver driver = new RemoteWebDriver (
44- new URL ("http://hub.browserstack.com/wd/hub" ), caps );
45-
42+ RemoteWebDriver driver = new RemoteWebDriver (new URL ("http://hub.browserstack.com/wd/hub" ), caps );
4643
4744 // Test case for the BrowserStack sample Android app.
4845 // If you have uploaded your app, update the test case here.
4946 WebElement searchElement = (WebElement ) new WebDriverWait (driver , 30 ).until (
5047 ExpectedConditions .elementToBeClickable (
5148 AppiumBy .accessibilityId ("Search Wikipedia" )));
5249 searchElement .click ();
50+
5351 WebElement insertTextElement = (WebElement ) new WebDriverWait (driver , 30 ).until (
5452 ExpectedConditions .elementToBeClickable (
5553 AppiumBy .id ("org.wikipedia.alpha:id/search_src_text" )));
5654 insertTextElement .sendKeys ("BrowserStack" );
5755 Thread .sleep (5000 );
56+
5857 List <WebElement > allProductsName = driver .findElements (AppiumBy .className ("android.widget.TextView" ));
59-
6058 assert (allProductsName .size () > 0 );
6159
62-
6360 // Invoke driver.quit() after the test is done to indicate that the test is completed.
6461 driver .quit ();
6562
0 commit comments