From 1bc5d60d4b8f53f51b498ee1ae140f7e2e796d36 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:06:56 +0530 Subject: [PATCH 01/19] New Maven project --- .gitignore | 5 ++ README.md | 9 --- android/BrowserStackAndroid.java | 39 --------- android/LocalSampleAndroid.java | 72 ----------------- android/README.md | 18 ----- ios/BrowserStackIOS.java | 45 ----------- ios/LocalSampleIOS.java | 80 ------------------- ios/README.md | 18 ----- java-browserstack/.classpath | 38 +++++++++ java-browserstack/.project | 23 ++++++ java-browserstack/README.md | 70 ++++++++++++++++ java-browserstack/pom.xml | 64 +++++++++++++++ .../java/android/BrowserStackAndroid.java | 67 ++++++++++++++++ .../src/test/java/ios/BrowserStackiOS.java | 64 +++++++++++++++ 14 files changed, 331 insertions(+), 281 deletions(-) create mode 100644 .gitignore delete mode 100644 README.md delete mode 100644 android/BrowserStackAndroid.java delete mode 100644 android/LocalSampleAndroid.java delete mode 100644 android/README.md delete mode 100644 ios/BrowserStackIOS.java delete mode 100644 ios/LocalSampleIOS.java delete mode 100644 ios/README.md create mode 100644 java-browserstack/.classpath create mode 100644 java-browserstack/.project create mode 100644 java-browserstack/README.md create mode 100644 java-browserstack/pom.xml create mode 100644 java-browserstack/src/test/java/android/BrowserStackAndroid.java create mode 100644 java-browserstack/src/test/java/ios/BrowserStackiOS.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..871cd6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.png +target/ +local.log +.idea +*.iml diff --git a/README.md b/README.md deleted file mode 100644 index 446876b..0000000 --- a/README.md +++ /dev/null @@ -1,9 +0,0 @@ -App Automate Java Samples ---------------------- - -This repository contains code for Automated Native App tests using Appium in Java. Please feel free to clone the repo and use the example code. - -For frameworks integration with BrowserStack, refer to their individual repositories - - -- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) -- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack) \ No newline at end of file diff --git a/android/BrowserStackAndroid.java b/android/BrowserStackAndroid.java deleted file mode 100644 index 45eb56d..0000000 --- a/android/BrowserStackAndroid.java +++ /dev/null @@ -1,39 +0,0 @@ -import java.net.URL; -import java.util.List; -import java.net.MalformedURLException; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - -public class BrowserStackAndroid { - - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - public static void main(String args[]) throws MalformedURLException, InterruptedException { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("device", "Samsung Galaxy S7"); - capabilities.setCapability("app", "bs://"); - - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia"))); - searchElement.click(); - AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.id("org.wikipedia.alpha:id/search_src_text"))); - insertTextElement.sendKeys("BrowserStack"); - Thread.sleep(5000); - - List allProductsName = driver.findElementsByClassName("android.widget.TextView"); - assert(allProductsName.size() > 0); - - driver.quit(); - } -} diff --git a/android/LocalSampleAndroid.java b/android/LocalSampleAndroid.java deleted file mode 100644 index 28483d9..0000000 --- a/android/LocalSampleAndroid.java +++ /dev/null @@ -1,72 +0,0 @@ -import com.browserstack.local.Local; - -import java.net.URL; -import java.util.Map; -import java.util.List; -import java.util.HashMap; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - - -public class LocalSampleAndroid { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - - public static void main(String[] args) throws Exception { - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "Samsung Galaxy S7"); - capabilities.setCapability("app", "bs://"); - - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); - searchElement.click(); - AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView"))); - - AndroidElement testElement = null; - List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); - Thread.sleep(10); - for(AndroidElement textElement : allTextViewElements) { - if(textElement.getText().contains("The active connection is")) { - testElement = textElement; - } - } - - if(testElement == null) { - throw new Error("Cannot find the needed TextView element from app"); - } - String matchedString = testElement.getText(); - System.out.println(matchedString); - assert(matchedString.contains("The active connection is wifi")); - assert(matchedString.contains("Up and running")); - - driver.quit(); - - tearDownLocal(); - } -} diff --git a/android/README.md b/android/README.md deleted file mode 100644 index 76ca27c..0000000 --- a/android/README.md +++ /dev/null @@ -1,18 +0,0 @@ -## Running your tests -- Do remember to switch the USERNAME and ACCESS_KEY with your own browserstack credentials. -- Upload your Native App (.apk file) to BrowserStack servers using upload API: - - ``` - curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk" - ``` - -- If you do not have an .apk file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) -to the BrowserStack servers using the above API. -- Update the desired capability "app" with the App URL returned from the above API call - -For running LocalSample tests, you can download `browserstack-local-java.jar` from [here](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22browserstack-local-java%22). - -For frameworks integration with BrowserStack, refer to their individual repositories - - -- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) -- [TestNG](https://github.com/browserstack/testng-appium-app-browserstack) diff --git a/ios/BrowserStackIOS.java b/ios/BrowserStackIOS.java deleted file mode 100644 index 48b2799..0000000 --- a/ios/BrowserStackIOS.java +++ /dev/null @@ -1,45 +0,0 @@ -import java.net.URL; -import java.util.List; -import java.net.MalformedURLException; - -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - - -public class BrowserStackIOS { - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - public static void main(String args[]) throws MalformedURLException, InterruptedException { - DesiredCapabilities caps = new DesiredCapabilities(); - - caps.setCapability("device", "iPhone 7 Plus"); - caps.setCapability("app", "bs://"); - - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps); - - IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); - textButton.click(); - IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); - textInput.sendKeys("hello@browserstack.com"); - - Thread.sleep(5000); - - IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); - - if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) - assert(true); - else - assert(false); - - driver.quit(); - } -} diff --git a/ios/LocalSampleIOS.java b/ios/LocalSampleIOS.java deleted file mode 100644 index bb3f889..0000000 --- a/ios/LocalSampleIOS.java +++ /dev/null @@ -1,80 +0,0 @@ -import com.browserstack.local.Local; - -import java.net.URL; -import java.io.File; -import java.util.Map; -import java.util.HashMap; -import org.apache.commons.io.FileUtils; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; - - -public class LocalSampleIOS { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - - public static void main(String[] args) throws Exception { - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "iPhone 7"); - capabilities.setCapability("app", "bs://"); - - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); - testButton.click(); - - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver d) { - String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); - return result != null && result.length() > 0; - } - }); - IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); - - String resultString = resultElement.getText().toLowerCase(); - System.out.println(resultString); - if(resultString.contains("not working")) { - File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); - FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); - System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); - throw new Error("Unexpected BrowserStackLocal test result"); - } - - String expectedString = "Up and running"; - assert(resultString.contains(expectedString.toLowerCase())); - - driver.quit(); - - tearDownLocal(); - } -} diff --git a/ios/README.md b/ios/README.md deleted file mode 100644 index 91485a6..0000000 --- a/ios/README.md +++ /dev/null @@ -1,18 +0,0 @@ -## Running your tests -- Do remember to switch the USERNAME and ACCESS_KEY with your own browserstack credentials. -- Upload your Native App (.ipa file) to BrowserStack servers using upload API: - - ``` - curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.ipa" - ``` - -- If you do not have an .ipa file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa) -to the BrowserStack servers using the above API. -- Update the desired capability "app" with the App URL returned from the above API call - -For running LocalSample tests, you can download `browserstack-local-java.jar` from [here](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22browserstack-local-java%22). - -For frameworks integration with BrowserStack, refer to their individual repositories - - -- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) -- [TestNG](https://github.com/browserstack/testng-appium-app-browserstack) \ No newline at end of file diff --git a/java-browserstack/.classpath b/java-browserstack/.classpath new file mode 100644 index 0000000..90f81ed --- /dev/null +++ b/java-browserstack/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java-browserstack/.project b/java-browserstack/.project new file mode 100644 index 0000000..8b53c97 --- /dev/null +++ b/java-browserstack/.project @@ -0,0 +1,23 @@ + + + java-browserstack + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/java-browserstack/README.md b/java-browserstack/README.md new file mode 100644 index 0000000..cc19fde --- /dev/null +++ b/java-browserstack/README.md @@ -0,0 +1,70 @@ +# java-appium-app-browserstack + +This repository demonstrates how to run Appium Java tests on BrowserStack App Automate. + +## Setup + +### Requirements + +1. Java 8+ + +- If Java is not installed, follow these instructions: + - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable + - For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/) + +2. Eclipse IDE or IntelliJ IDEA + + - If not installed, download and install Eclipse IDE from [here](https://www.eclipse.org/downloads/) or IntelliJ IDEA from [here](https://www.jetbrains.com/idea/download/#section=windows) + +### Install the dependencies + +1. Import the project as an existing Maven project in your IDE + +2. Clean and build the imported project + +## Getting Started + +Getting Started with Appium tests in Java on BrowserStack couldn't be easier! + +### Upoad your Android or iOS App + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). + +### **Run first test :** + +Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` for iOS test + +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials + +- Replace `bs://` wkth the URL obtained from app upload step + +- Set the device and OS version + +- If you have uploaded your own app update the test case + +- Run `BrowserStackAndroid.java` for android test or `BrowserStackiOS.java` for iOS test + +For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) + +### **Use Local testing for apps that access resources hosted in development or testing environments :** + +Refer to our documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/local-testing) + +## Integration with other Java frameworks + +- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) +- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack) + +## Getting Help + +If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help). diff --git a/java-browserstack/pom.xml b/java-browserstack/pom.xml new file mode 100644 index 0000000..f738c84 --- /dev/null +++ b/java-browserstack/pom.xml @@ -0,0 +1,64 @@ + + 4.0.0 + com.browserstack + java-browserstack + 0.0.1-SNAPSHOT + java-browserstack + Java appium app browserstack + + + UTF-8 + 2.19.1 + + default + + + + + + commons-io + commons-io + 1.3.2 + + + org.seleniumhq.selenium + selenium-java + 3.141.59 + + + io.appium + java-client + 7.0.0 + + + com.browserstack + browserstack-local-java + 1.0.3 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroid.java b/java-browserstack/src/test/java/android/BrowserStackAndroid.java new file mode 100644 index 0000000..23b01e0 --- /dev/null +++ b/java-browserstack/src/test/java/android/BrowserStackAndroid.java @@ -0,0 +1,67 @@ +package android; + +import java.net.URL; +import java.util.List; +import java.util.function.Function; +import java.net.MalformedURLException; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.DesiredCapabilities; + +public class BrowserStackAndroid { + + public static void main(String[] args) throws MalformedURLException, InterruptedException { + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", "neerajkumar42"); + capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "Google Pixel 3"); + capabilities.setCapability("os_version", "9.0"); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java Android"); + capabilities.setCapability("name", "first_test"); + + + // 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"), capabilities); + + + // Test case for the BrowserStack sample Android app. + // If you have uploaded your app, update the test case here. + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable( + MobileBy.AccessibilityId("Search Wikipedia"))); + searchElement.click(); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable( + MobileBy.id("org.wikipedia.alpha:id/search_src_text"))); + insertTextElement.sendKeys("BrowserStack"); + Thread.sleep(5000); + List allProductsName = driver.findElementsByClassName( + "android.widget.TextView"); + assert(allProductsName.size() > 0); + + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + } + +} diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOS.java b/java-browserstack/src/test/java/ios/BrowserStackiOS.java new file mode 100644 index 0000000..d02d769 --- /dev/null +++ b/java-browserstack/src/test/java/ios/BrowserStackiOS.java @@ -0,0 +1,64 @@ +package ios; + +import java.net.URL; +import java.util.List; +import java.net.MalformedURLException; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; + +public class BrowserStackiOS { + + public static void main(String[] args) throws MalformedURLException, InterruptedException { + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", "neerajkumar42"); + capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://a2c4c0bd114ce9765af0988a632982cb42688b81"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "iPhone 11 Pro"); + capabilities.setCapability("os_version", "13"); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java iOS"); + capabilities.setCapability("name", "first_test"); + + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + IOSDriver driver = new IOSDriver( + new URL("http://hub-cloud.browserstack.com/wd/hub"), capabilities); + + + // Test case for the BrowserStack sample iOS app. + // If you have uploaded your app, update the test case here. + IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); + textButton.click(); + IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); + textInput.sendKeys("hello@browserstack.com"); + Thread.sleep(5000); + IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); + if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) + assert(true); + else + assert(false); + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + } + +} From ee602276253086b0dc074bb9a2ca59f3f2cba8d2 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:09:48 +0530 Subject: [PATCH 02/19] Adding .DS_Store and IDE Settings to Git Ignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 871cd6a..cd3e417 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ target/ local.log .idea *.iml +**/.DS_Store +**/.settings From 9e93054e41b0facd754c83ad7789af1668aea894 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:31:33 +0530 Subject: [PATCH 03/19] Adding Local script files --- java-browserstack/.classpath | 2 +- .../java/android/BrowserStackAndroid.java | 6 +- .../android/BrowserStackAndroidLocal.java | 78 +++++++++++++++++ .../src/test/java/ios/BrowserStackiOS.java | 6 +- .../test/java/ios/BrowserStackiOSLocal.java | 87 +++++++++++++++++++ 5 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java create mode 100644 java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java diff --git a/java-browserstack/.classpath b/java-browserstack/.classpath index 90f81ed..002ad57 100644 --- a/java-browserstack/.classpath +++ b/java-browserstack/.classpath @@ -24,7 +24,7 @@ - + diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroid.java b/java-browserstack/src/test/java/android/BrowserStackAndroid.java index 23b01e0..be1ac58 100644 --- a/java-browserstack/src/test/java/android/BrowserStackAndroid.java +++ b/java-browserstack/src/test/java/android/BrowserStackAndroid.java @@ -21,11 +21,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "neerajkumar42"); - capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); + capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); + capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing capabilities.setCapability("device", "Google Pixel 3"); diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java b/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java new file mode 100644 index 0000000..740273d --- /dev/null +++ b/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java @@ -0,0 +1,78 @@ +package android; + +import com.browserstack.local.Local; + +import java.net.URL; +import java.util.Map; +import java.util.List; +import java.util.HashMap; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; + +public class BrowserStackAndroidLocal { + + private static Local localInstance; + public static String accessKey = "BROWSERSTACK_USERNAME"; + public static String userName = "BROWSERSTACK_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + + + public static void main(String[] args) throws Exception { + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("browserstack.local", true); + capabilities.setCapability("device", "Samsung Galaxy S7"); + capabilities.setCapability("app", "bs://"); + + AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); + searchElement.click(); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView"))); + + AndroidElement testElement = null; + List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); + Thread.sleep(10); + for(AndroidElement textElement : allTextViewElements) { + if(textElement.getText().contains("The active connection is")) { + testElement = textElement; + } + } + + if(testElement == null) { + throw new Error("Cannot find the needed TextView element from app"); + } + String matchedString = testElement.getText(); + System.out.println(matchedString); + assert(matchedString.contains("The active connection is wifi")); + assert(matchedString.contains("Up and running")); + + driver.quit(); + + tearDownLocal(); + + } + +} diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOS.java b/java-browserstack/src/test/java/ios/BrowserStackiOS.java index d02d769..3f3b392 100644 --- a/java-browserstack/src/test/java/ios/BrowserStackiOS.java +++ b/java-browserstack/src/test/java/ios/BrowserStackiOS.java @@ -18,11 +18,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "neerajkumar42"); - capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); + capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://a2c4c0bd114ce9765af0988a632982cb42688b81"); + capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing capabilities.setCapability("device", "iPhone 11 Pro"); diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java b/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java new file mode 100644 index 0000000..ad9a04c --- /dev/null +++ b/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java @@ -0,0 +1,87 @@ +package ios; + +import com.browserstack.local.Local; + +import java.net.URL; +import java.io.File; +import java.util.Map; +import java.util.HashMap; +import org.apache.commons.io.FileUtils; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; + + +public class BrowserStackiOSLocal { + + private static Local localInstance; + public static String accessKey = "BROWSERSTACK_USERNAME"; + public static String userName = "BROWSERSTACK_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + + public static void main(String[] args) throws Exception { + + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("browserstack.local", true); + capabilities.setCapability("device", "iPhone 7"); + capabilities.setCapability("app", "bs://"); + + IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + + IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); + testButton.click(); + + WebDriverWait wait = new WebDriverWait(driver, 30); + wait.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver d) { + String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); + return result != null && result.length() > 0; + } + }); + IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); + + String resultString = resultElement.getText().toLowerCase(); + System.out.println(resultString); + if(resultString.contains("not working")) { + File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); + FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); + System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); + throw new Error("Unexpected BrowserStackLocal test result"); + } + + String expectedString = "Up and running"; + assert(resultString.contains(expectedString.toLowerCase())); + + driver.quit(); + + tearDownLocal(); + + } + +} From 70a6a4feb237404007f1d7bed0ba35e9222853d4 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:33:10 +0530 Subject: [PATCH 04/19] Update README.md --- java-browserstack/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java-browserstack/README.md b/java-browserstack/README.md index cc19fde..6090e28 100644 --- a/java-browserstack/README.md +++ b/java-browserstack/README.md @@ -18,15 +18,15 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Install the dependencies -1. Import the project as an existing Maven project in your IDE +1. Import the `java-browserstack` Maven project as an existing Maven project in your IDE -2. Clean and build the imported project +2. Clean and build the project ## Getting Started Getting Started with Appium tests in Java on BrowserStack couldn't be easier! -### Upoad your Android or iOS App +### Upload your Android or iOS App Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : From e4dde43cf4e42787ea9a1eae2b6880f129cf7cdc Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Mon, 31 Aug 2020 18:00:32 +0530 Subject: [PATCH 05/19] Updating readme. Removing .classpath from gitignore --- .gitignore | 1 + java-browserstack/.classpath | 38 ------------------------------------ java-browserstack/README.md | 4 +++- 3 files changed, 4 insertions(+), 39 deletions(-) delete mode 100644 java-browserstack/.classpath diff --git a/.gitignore b/.gitignore index cd3e417..ffcb8e2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ local.log *.iml **/.DS_Store **/.settings +java-browserstack/.classpath diff --git a/java-browserstack/.classpath b/java-browserstack/.classpath deleted file mode 100644 index 002ad57..0000000 --- a/java-browserstack/.classpath +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java-browserstack/README.md b/java-browserstack/README.md index 6090e28..63b4c79 100644 --- a/java-browserstack/README.md +++ b/java-browserstack/README.md @@ -18,7 +18,7 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Install the dependencies -1. Import the `java-browserstack` Maven project as an existing Maven project in your IDE +1. Import the `java-browserstack` Maven project as an "Existing Maven project" in your IDE 2. Clean and build the project @@ -54,6 +54,8 @@ Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` - Run `BrowserStackAndroid.java` for android test or `BrowserStackiOS.java` for iOS test +- - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) + For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) ### **Use Local testing for apps that access resources hosted in development or testing environments :** From b19e063a779f4ce73f06bfb0feb1738a3d058876 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 16:47:18 +0530 Subject: [PATCH 06/19] Updated pom to work from terminal --- java-browserstack/pom.xml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/java-browserstack/pom.xml b/java-browserstack/pom.xml index f738c84..4f29a62 100644 --- a/java-browserstack/pom.xml +++ b/java-browserstack/pom.xml @@ -60,5 +60,32 @@ + + + + first + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackAndroid + test + + + + + + + + \ No newline at end of file From 39afd53cf3adcee4f2dac94aae1cc76058cb6b84 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 16:56:39 +0530 Subject: [PATCH 07/19] Bringing all files to the main folder --- java-browserstack/README.md => README.md | 0 java-browserstack/pom.xml => pom.xml | 0 .../src => src}/test/java/android/BrowserStackAndroid.java | 6 +++--- .../test/java/android/BrowserStackAndroidLocal.java | 0 .../src => src}/test/java/ios/BrowserStackiOS.java | 0 .../src => src}/test/java/ios/BrowserStackiOSLocal.java | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename java-browserstack/README.md => README.md (100%) rename java-browserstack/pom.xml => pom.xml (100%) rename {java-browserstack/src => src}/test/java/android/BrowserStackAndroid.java (91%) rename {java-browserstack/src => src}/test/java/android/BrowserStackAndroidLocal.java (100%) rename {java-browserstack/src => src}/test/java/ios/BrowserStackiOS.java (100%) rename {java-browserstack/src => src}/test/java/ios/BrowserStackiOSLocal.java (100%) diff --git a/java-browserstack/README.md b/README.md similarity index 100% rename from java-browserstack/README.md rename to README.md diff --git a/java-browserstack/pom.xml b/pom.xml similarity index 100% rename from java-browserstack/pom.xml rename to pom.xml diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroid.java b/src/test/java/android/BrowserStackAndroid.java similarity index 91% rename from java-browserstack/src/test/java/android/BrowserStackAndroid.java rename to src/test/java/android/BrowserStackAndroid.java index be1ac58..23b01e0 100644 --- a/java-browserstack/src/test/java/android/BrowserStackAndroid.java +++ b/src/test/java/android/BrowserStackAndroid.java @@ -21,11 +21,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); - capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + capabilities.setCapability("browserstack.user", "neerajkumar42"); + capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); // Set URL of the application under test - capabilities.setCapability("app", "bs://"); + capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); // Specify device and os_version for testing capabilities.setCapability("device", "Google Pixel 3"); diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java b/src/test/java/android/BrowserStackAndroidLocal.java similarity index 100% rename from java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java rename to src/test/java/android/BrowserStackAndroidLocal.java diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOS.java b/src/test/java/ios/BrowserStackiOS.java similarity index 100% rename from java-browserstack/src/test/java/ios/BrowserStackiOS.java rename to src/test/java/ios/BrowserStackiOS.java diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java b/src/test/java/ios/BrowserStackiOSLocal.java similarity index 100% rename from java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java rename to src/test/java/ios/BrowserStackiOSLocal.java From 97b8d8b86ebcfda3ea5b6409ed5d1df92573605b Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 17:22:33 +0530 Subject: [PATCH 08/19] Adding mvn profiles for all the test scenarios --- .gitignore | 4 +- java-browserstack/.project | 23 -- pom.xml | 252 +++++++++++------- .../java/android/BrowserStackAndroid.java | 6 +- 4 files changed, 169 insertions(+), 116 deletions(-) delete mode 100644 java-browserstack/.project diff --git a/.gitignore b/.gitignore index ffcb8e2..cb0ef2d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ local.log *.iml **/.DS_Store **/.settings -java-browserstack/.classpath +.classpath +.project + diff --git a/java-browserstack/.project b/java-browserstack/.project deleted file mode 100644 index 8b53c97..0000000 --- a/java-browserstack/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - java-browserstack - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/pom.xml b/pom.xml index 4f29a62..b89a106 100644 --- a/pom.xml +++ b/pom.xml @@ -1,91 +1,165 @@ - - 4.0.0 - com.browserstack - java-browserstack - 0.0.1-SNAPSHOT - java-browserstack - Java appium app browserstack - - - UTF-8 - 2.19.1 - - default - - - - - - commons-io - commons-io - 1.3.2 - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - - - io.appium - java-client - 7.0.0 - - - com.browserstack - browserstack-local-java - 1.0.3 - - - com.googlecode.json-simple - json-simple - 1.1.1 - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - + + 4.0.0 + com.browserstack + java-browserstack + 0.0.1-SNAPSHOT + java-browserstack + Java appium app browserstack + + + UTF-8 + 2.19.1 + + default + + + + + + commons-io + commons-io + 1.3.2 + + + org.seleniumhq.selenium + selenium-java + 3.141.59 + + + io.appium + java-client + 7.0.0 + + + com.browserstack + browserstack-local-java + 1.0.3 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + + + android-first-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackAndroid + test + + + + + + + + + android-local-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackAndroidLocal + test + + + + + + + + + ios-first-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + ios.BrowserStackiOS + test + + + + + + + + + ios-local-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + ios.BrowserStackiOSLocal + test + + + + + + + + - - - first - - - - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - android.BrowserStackAndroid - test - - - - - - - - - \ No newline at end of file diff --git a/src/test/java/android/BrowserStackAndroid.java b/src/test/java/android/BrowserStackAndroid.java index 23b01e0..be1ac58 100644 --- a/src/test/java/android/BrowserStackAndroid.java +++ b/src/test/java/android/BrowserStackAndroid.java @@ -21,11 +21,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "neerajkumar42"); - capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); + capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); + capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing capabilities.setCapability("device", "Google Pixel 3"); From 399c10702b5f04c05ae39de4001207812d772351 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 17:41:53 +0530 Subject: [PATCH 09/19] Updated Readme --- README.md | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 63b4c79..090f912 100644 --- a/README.md +++ b/README.md @@ -12,15 +12,18 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable - For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/) -2. Eclipse IDE or IntelliJ IDEA +2. Maven - - If not installed, download and install Eclipse IDE from [here](https://www.eclipse.org/downloads/) or IntelliJ IDEA from [here](https://www.jetbrains.com/idea/download/#section=windows) + - If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi) + - For installation, follow the instructions [here](https://maven.apache.org/install.html) ### Install the dependencies -1. Import the `java-browserstack` Maven project as an "Existing Maven project" in your IDE +1. Run the following command in the project's base folder -2. Clean and build the project +```cmd +mvn clean install +``` ## Getting Started @@ -42,7 +45,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please ### **Run first test :** -Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` for iOS test +Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -52,9 +55,21 @@ Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` - If you have uploaded your own app update the test case -- Run `BrowserStackAndroid.java` for android test or `BrowserStackiOS.java` for iOS test +- To run the test, use the following command in the base directory : + + - For Android test, run + + ```cmd + mvn test -P android-first-test + ``` + + - For iOS test, run + + ```cmd + mvn test -P ios-first-test + ``` -- - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) From 788a1f87b0639d1c0ff3950f1c1d9f91848cb224 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 17:59:01 +0530 Subject: [PATCH 10/19] Removing selenium dependency. Typo fix in Readme --- README.md | 2 +- pom.xml | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 090f912..79fb59f 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStack - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials -- Replace `bs://` wkth the URL obtained from app upload step +- Replace `bs://` with the URL obtained from app upload step - Set the device and OS version diff --git a/pom.xml b/pom.xml index b89a106..838152f 100644 --- a/pom.xml +++ b/pom.xml @@ -22,11 +22,6 @@ commons-io 1.3.2 - - org.seleniumhq.selenium - selenium-java - 3.141.59 - io.appium java-client From eda63520d9eda02281c5d8f44f0730c481a3d354 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 02:03:42 +0530 Subject: [PATCH 11/19] Updating Local test for Android and iOS. --- .../android/BrowserStackAndroidLocal.java | 62 +++++++++++++------ src/test/java/ios/BrowserStackiOSLocal.java | 42 ++++++++++--- 2 files changed, 74 insertions(+), 30 deletions(-) diff --git a/src/test/java/android/BrowserStackAndroidLocal.java b/src/test/java/android/BrowserStackAndroidLocal.java index 740273d..deb092a 100644 --- a/src/test/java/android/BrowserStackAndroidLocal.java +++ b/src/test/java/android/BrowserStackAndroidLocal.java @@ -17,35 +17,55 @@ public class BrowserStackAndroidLocal { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - + private static Local localInstance; + public static String userName = "YOUR_USERNAME"; + public static String accessKey = "YOUR_ACCESS_KEY"; - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } public static void main(String[] args) throws Exception { - setupLocal(); + // Start the BrowserStack Local binary + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "Google Pixel 3"); + capabilities.setCapability("os_version", "9.0"); - DesiredCapabilities capabilities = new DesiredCapabilities(); + // Set the browserstack.local capability to true + capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "Samsung Galaxy S7"); - capabilities.setCapability("app", "bs://"); + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java Android Local"); + capabilities.setCapability("name", "local_test"); + - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + // 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"), capabilities); + // Test case for the BrowserStack sample Android Local app. + // If you have uploaded your app, update the test case here. AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); searchElement.click(); @@ -69,8 +89,10 @@ public static void main(String[] args) throws Exception { assert(matchedString.contains("The active connection is wifi")); assert(matchedString.contains("Up and running")); + // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); + // Stop the BrowserStack Local binary tearDownLocal(); } diff --git a/src/test/java/ios/BrowserStackiOSLocal.java b/src/test/java/ios/BrowserStackiOSLocal.java index ad9a04c..e992434 100644 --- a/src/test/java/ios/BrowserStackiOSLocal.java +++ b/src/test/java/ios/BrowserStackiOSLocal.java @@ -24,8 +24,8 @@ public class BrowserStackiOSLocal { private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; + public static String accessKey = "YOUR_USERNAME"; + public static String userName = "YOUR_ACCESS_KEY"; public static void setupLocal() throws Exception { @@ -41,17 +41,37 @@ public static void tearDownLocal() throws Exception { public static void main(String[] args) throws Exception { - + // Start the BrowserStack Local binary setupLocal(); DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "iPhone 7"); - capabilities.setCapability("app", "bs://"); - - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "iPhone 11 Pro"); + capabilities.setCapability("os_version", "13"); + + // Set the browserstack.local capability to true + capabilities.setCapability("browserstack.local", true); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java iOS Local"); + capabilities.setCapability("name", "local_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + IOSDriver driver = new IOSDriver( + new URL("http://hub.browserstack.com/wd/hub"), capabilities); + + // Test case for the BrowserStack sample iOS Local app. + // If you have uploaded your app, update the test case here. IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); testButton.click(); @@ -78,8 +98,10 @@ public Boolean apply(WebDriver d) { String expectedString = "Up and running"; assert(resultString.contains(expectedString.toLowerCase())); + // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); - + + // Stop the BrowserStack Local binary tearDownLocal(); } From f8ff5f5ec3ca30327cec0be3688e2b8e6f0b44ba Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 02:28:35 +0530 Subject: [PATCH 12/19] Updating Readme with Local test --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 79fb59f..c3c8922 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Install the dependencies -1. Run the following command in the project's base folder +To install the dependencies, run the following command in the project's base folder ```cmd mvn clean install @@ -29,7 +29,9 @@ mvn clean install Getting Started with Appium tests in Java on BrowserStack couldn't be easier! -### Upload your Android or iOS App +### Run your first test : + +**1. Upload your Android or iOS App** Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : @@ -43,9 +45,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). -### **Run first test :** - -Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory +**2. Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory :** - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -71,11 +71,50 @@ Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStack - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) -For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) +--- + +### Use Local testing for apps that access resources hosted in development or testing environments : + +**1. Upoad your Android or iOS App** + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). + +**2. Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory :** + +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials + +- Replace `bs://` with the URL obtained from app upload step + +- Set the device and OS version + +- If you have uploaded your own app update the test case + +- To run the test, use the following command in the base directory : + + - For Android test, run -### **Use Local testing for apps that access resources hosted in development or testing environments :** + ```cmd + mvn test -P android-local-test + ``` + + - For iOS test, run + + ```cmd + mvn test -P ios-local-test + ``` + +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) -Refer to our documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/local-testing) ## Integration with other Java frameworks From 9e698bcdc5b8e297f0abf9f1fb72f8f2606ae2fc Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 15:03:38 +0530 Subject: [PATCH 13/19] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c3c8922..2c7724a 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). -**2. Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory :** +**2. Configure and run your first test** + +Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -89,7 +91,9 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). -**2. Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory :** +**2. Configure and run your local test** + +Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials From 2673193260239d61a9add2a3729be0e12f9b621d Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 15:25:07 +0530 Subject: [PATCH 14/19] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2c7724a..7ffeca4 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ Open `BrowserStackAndroidLocal.java` file in the `android` directory or `Browser - Set the device and OS version +- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. + - If you have uploaded your own app update the test case - To run the test, use the following command in the base directory : From c14a7912de69cc2146236094ab0c637894bff4e7 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 26 Sep 2020 16:01:57 +0530 Subject: [PATCH 15/19] Updating class names according to QSG. Removing unwanted imports. --- pom.xml | 8 +++--- ...ckAndroid.java => BrowserStackSample.java} | 18 +++--------- ...ocal.java => BrowserStackSampleLocal.java} | 18 +++--------- ...rStackiOS.java => BrowserStackSample.java} | 16 +++-------- ...ocal.java => BrowserStackSampleLocal.java} | 28 +++++-------------- 5 files changed, 23 insertions(+), 65 deletions(-) rename src/test/java/android/{BrowserStackAndroid.java => BrowserStackSample.java} (81%) rename src/test/java/android/{BrowserStackAndroidLocal.java => BrowserStackSampleLocal.java} (88%) rename src/test/java/ios/{BrowserStackiOS.java => BrowserStackSample.java} (84%) rename src/test/java/ios/{BrowserStackiOSLocal.java => BrowserStackSampleLocal.java} (82%) diff --git a/pom.xml b/pom.xml index 838152f..74fc8bd 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ java - android.BrowserStackAndroid + android.BrowserStackSample test @@ -98,7 +98,7 @@ java - android.BrowserStackAndroidLocal + android.BrowserStackSampleLocal test @@ -122,7 +122,7 @@ java - ios.BrowserStackiOS + ios.BrowserStackSample test @@ -146,7 +146,7 @@ java - ios.BrowserStackiOSLocal + ios.BrowserStackSampleLocal test diff --git a/src/test/java/android/BrowserStackAndroid.java b/src/test/java/android/BrowserStackSample.java similarity index 81% rename from src/test/java/android/BrowserStackAndroid.java rename to src/test/java/android/BrowserStackSample.java index be1ac58..725150c 100644 --- a/src/test/java/android/BrowserStackAndroid.java +++ b/src/test/java/android/BrowserStackSample.java @@ -1,20 +1,10 @@ package android; -import java.net.URL; -import java.util.List; -import java.util.function.Function; -import java.net.MalformedURLException; +import java.net.*; import java.util.List; +import io.appium.java_client.*; import io.appium.java_client.android.*; +import org.openqa.selenium.support.ui.*; import org.openqa.selenium.remote.*; -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; - -public class BrowserStackAndroid { +public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { diff --git a/src/test/java/android/BrowserStackAndroidLocal.java b/src/test/java/android/BrowserStackSampleLocal.java similarity index 88% rename from src/test/java/android/BrowserStackAndroidLocal.java rename to src/test/java/android/BrowserStackSampleLocal.java index deb092a..cb6f71e 100644 --- a/src/test/java/android/BrowserStackAndroidLocal.java +++ b/src/test/java/android/BrowserStackSampleLocal.java @@ -1,21 +1,11 @@ package android; import com.browserstack.local.Local; +import java.net.URL; import java.util.*; +import io.appium.java_client.MobileBy; import io.appium.java_client.android.*; +import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; -import java.net.URL; -import java.util.Map; -import java.util.List; -import java.util.HashMap; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - -public class BrowserStackAndroidLocal { +public class BrowserStackSampleLocal { private static Local localInstance; public static String userName = "YOUR_USERNAME"; diff --git a/src/test/java/ios/BrowserStackiOS.java b/src/test/java/ios/BrowserStackSample.java similarity index 84% rename from src/test/java/ios/BrowserStackiOS.java rename to src/test/java/ios/BrowserStackSample.java index 3f3b392..dfb7a47 100644 --- a/src/test/java/ios/BrowserStackiOS.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -1,18 +1,10 @@ package ios; -import java.net.URL; -import java.util.List; -import java.net.MalformedURLException; +import java.net.*; +import org.openqa.selenium.remote.*; import org.openqa.selenium.support.ui.*; +import io.appium.java_client.MobileBy;import io.appium.java_client.ios.*; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - -public class BrowserStackiOS { +public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities capabilities = new DesiredCapabilities(); diff --git a/src/test/java/ios/BrowserStackiOSLocal.java b/src/test/java/ios/BrowserStackSampleLocal.java similarity index 82% rename from src/test/java/ios/BrowserStackiOSLocal.java rename to src/test/java/ios/BrowserStackSampleLocal.java index e992434..4a6daf4 100644 --- a/src/test/java/ios/BrowserStackiOSLocal.java +++ b/src/test/java/ios/BrowserStackSampleLocal.java @@ -1,31 +1,17 @@ package ios; import com.browserstack.local.Local; - -import java.net.URL; -import java.io.File; -import java.util.Map; -import java.util.HashMap; +import java.net.URL; import java.io.File; import java.util.*; import org.apache.commons.io.FileUtils; +import io.appium.java_client.MobileBy; import io.appium.java_client.ios.*; +import org.openqa.selenium.*; +import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; - - -public class BrowserStackiOSLocal { +public class BrowserStackSampleLocal { private static Local localInstance; - public static String accessKey = "YOUR_USERNAME"; - public static String userName = "YOUR_ACCESS_KEY"; + public static String userName = "YOUR_USERNAME"; + public static String accessKey = "YOUR_ACCESS_KEY"; public static void setupLocal() throws Exception { From d834fc4ff01f788d20543fc25cc23a99af1812b7 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 26 Sep 2020 16:04:09 +0530 Subject: [PATCH 16/19] Updating Readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7ffeca4..f955c5b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **2. Configure and run your first test** -Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory : +Open `BrowserStackSample.java` file in the `android` directory or `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -93,7 +93,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **2. Configure and run your local test** -Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory : +Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -101,7 +101,7 @@ Open `BrowserStackAndroidLocal.java` file in the `android` directory or `Browser - Set the device and OS version -- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. +- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. - If you have uploaded your own app update the test case From 3d232d6dc0b64dd82bf26f3d4883e0fa50bde82a Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Wed, 30 Sep 2020 10:17:45 +0530 Subject: [PATCH 17/19] Reverting to previous imports for android and ios sample tests --- src/test/java/android/BrowserStackSample.java | 17 ++++++++++++++--- src/test/java/ios/BrowserStackSample.java | 14 +++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index 725150c..e404a8a 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -1,8 +1,19 @@ package android; -import java.net.*; import java.util.List; -import io.appium.java_client.*; import io.appium.java_client.android.*; -import org.openqa.selenium.support.ui.*; import org.openqa.selenium.remote.*; +import java.net.URL; +import java.util.List; +import java.util.function.Function; +import java.net.MalformedURLException; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.DesiredCapabilities; + public class BrowserStackSample { diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index dfb7a47..79d5e9e 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -1,8 +1,16 @@ package ios; -import java.net.*; -import org.openqa.selenium.remote.*; import org.openqa.selenium.support.ui.*; -import io.appium.java_client.MobileBy;import io.appium.java_client.ios.*; +import java.net.URL; +import java.util.List; +import java.net.MalformedURLException; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; public class BrowserStackSample { From 60ecc209ef8398b9543806f3561f6f4ee8f650e3 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Thu, 1 Oct 2020 13:07:12 +0530 Subject: [PATCH 18/19] changing 'capabilities' to 'caps' --- src/test/java/android/BrowserStackSample.java | 20 +++++++++---------- src/test/java/ios/BrowserStackSample.java | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index e404a8a..4deea4f 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -19,29 +19,29 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { - DesiredCapabilities capabilities = new DesiredCapabilities(); + DesiredCapabilities caps = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); - capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://"); + caps.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("device", "Google Pixel 3"); - capabilities.setCapability("os_version", "9.0"); + caps.setCapability("device", "Google Pixel 3"); + caps.setCapability("os_version", "9.0"); // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "Java Android"); - capabilities.setCapability("name", "first_test"); + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "Java Android"); + caps.setCapability("name", "first_test"); // 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"), capabilities); + new URL("http://hub.browserstack.com/wd/hub"), caps); // Test case for the BrowserStack sample Android app. diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index 79d5e9e..841a807 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -15,29 +15,29 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { - DesiredCapabilities capabilities = new DesiredCapabilities(); + DesiredCapabilities caps = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); - capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://"); + caps.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("device", "iPhone 11 Pro"); - capabilities.setCapability("os_version", "13"); + caps.setCapability("device", "iPhone 11 Pro"); + caps.setCapability("os_version", "13"); // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "Java iOS"); - capabilities.setCapability("name", "first_test"); + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "Java iOS"); + caps.setCapability("name", "first_test"); // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above IOSDriver driver = new IOSDriver( - new URL("http://hub-cloud.browserstack.com/wd/hub"), capabilities); + new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); // Test case for the BrowserStack sample iOS app. From e7f7f02453d38b238f5082bdcea7f7b1de05212d Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Thu, 1 Oct 2020 18:54:01 +0530 Subject: [PATCH 19/19] Adding Access credentials URL for convenience. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f955c5b..c8321a1 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please Open `BrowserStackSample.java` file in the `android` directory or `ios` directory : -- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) - Replace `bs://` with the URL obtained from app upload step @@ -95,7 +95,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : -- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) - Replace `bs://` with the URL obtained from app upload step