11import com .browserstack .local .Local ;
22
33import java .net .URL ;
4- import java .net .MalformedURLException ;
4+ import java .util .HashMap ;
5+ import java .util .List ;
6+ import java .util .Map ;
57
6- import io .appium .java_client .AppiumDriver ;
78import io .appium .java_client .android .AndroidDriver ;
8- import io .appium .java_client .MobileElement ;
99
1010import org .openqa .selenium .By ;
11- import org .openqa .selenium .WebDriver ;
1211import org .openqa .selenium .WebElement ;
13- import org .openqa .selenium .remote .RemoteWebDriver ;
12+ import org .openqa .selenium .support .ui .ExpectedConditions ;
13+ import org .openqa .selenium .support .ui .WebDriverWait ;
1414import org .openqa .selenium .remote .DesiredCapabilities ;
1515
16+
1617public class LocalSample {
1718 private static Local localInstance ;
19+ public static String accessKey = "BROWSERSTACK_USERNAME" ;
20+ public static String userName = "BROWSERSTACK_ACCESS_KEY" ;
21+
1822
1923 public static void setupLocal () throws Exception {
2024 localInstance = new Local ();
@@ -34,10 +38,10 @@ public static void main(String[] args) throws Exception {
3438
3539 capabilities .setCapability ("browserstack.local" , true );
3640 capabilities .setCapability ("realMobile" , true );
37- capabilities .setCapability ("device" , "Samsung Galaxy S6 " );
38- capabilities .setCapability ("app" , "bs://3fc0a1f5a158e935ad806b97288f4b24e11ebcc4 " );
41+ capabilities .setCapability ("device" , "Samsung Galaxy S7 " );
42+ capabilities .setCapability ("app" , "bs://d561ad02f69d8a329e50e92471d170ed9916b671 " );
3943
40- AndroidDriver driver = new AndroidDriver (new URL ("http ://BROWSERSTACK_USERNAME:BROWSERSTACK_ACCESS_KEY @hub.browserstack.com/wd/hub" ), capabilities );
44+ AndroidDriver driver = new AndroidDriver (new URL ("https ://" + userName + ":" + accessKey + " @hub.browserstack.com/wd/hub" ), capabilities );
4145
4246 WebElement searchElement = new WebDriverWait (driver , 30 ).until (
4347 ExpectedConditions .elementToBeClickable (By .id ("com.example.android.basicnetworking:id/test_action" )));
@@ -56,15 +60,12 @@ public static void main(String[] args) throws Exception {
5660 }
5761
5862 if (testElement == null ) {
59- File scrFile = ((TakesScreenshot )driver ).getScreenshotAs (OutputType .FILE );
60- FileUtils .copyFile (scrFile , new File (System .getProperty ("user.dir" ) + "screenshot.png" ));
61- System .out .println ("Screenshot stored at " + System .getProperty ("user.dir" ) + "screenshot.png" );
6263 throw new Error ("Cannot find the needed TextView element from app" );
6364 }
6465 String matchedString = testElement .getText ();
6566 System .out .println (matchedString );
66- assertTrue (matchedString .contains ("The active connection is wifi" ));
67- assertTrue (matchedString .contains ("Up and running" ));
67+ assert (matchedString .contains ("The active connection is wifi" ));
68+ assert (matchedString .contains ("Up and running" ));
6869
6970 driver .quit ();
7071
0 commit comments