diff --git a/README.md b/README.md index ef3660d..073360d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,179 @@ -| [Using Java 7 client with MJSONWP protocol](./java_7) | [Using Java 8 client with w3c protocol](./java_8) | -|------------------------------------------------------ | ------------------------------------------------- | \ No newline at end of file +# java-appium-app-browserstack (BrowserStack SDK) + +This repository demonstrates how to run Appium Java tests on [BrowserStack App Automate](https://app-automate.browserstack.com) using the **BrowserStack SDK**. All device, credential, and build configuration is managed via `browserstack.yml` — no hardcoded capabilities in test code. + +## Setup + +### Requirements + +1. **Java 8+** + - For Windows, download the latest version from [here](https://java.com/en/download/) and run the installer. + - For Mac and Linux, run `java -version` to check your version. Download a different version from [here](https://java.com/en/download/) if needed. + +2. **Maven** + - Download Maven from [here](https://maven.apache.org/download.cgi). + - Follow the installation instructions [here](https://maven.apache.org/install.html). + +### Install the dependencies + +Navigate to the `java_8` directory and run: + +```sh +cd java_8/ +mvn clean install +``` + +--- + +## Getting Started + +### Step 1 — Upload your App to BrowserStack + +Upload your Android (`.apk` / `.aab`) or iOS (`.ipa`) app to BrowserStack using the REST API: + +```sh +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ + -X POST "https://api-cloud.browserstack.com/app-automate/upload" \ + -F "file=@/path/to/your/app" +``` + +Note the `app_url` value (e.g. `bs://xxxxxxx`) returned in the response — you'll need it in the next step. + +> **Don't have an app?** Use the BrowserStack sample apps: +> - [Sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) +> - [Sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa) + +--- + +### Step 2 — Configure `browserstack.yml` + +Open `java_8/browserstack.yml` and set your credentials, app, and target devices. + +```yaml +# ===================== +# BrowserStack Credentials +# ===================== +# Either set values directly here, or export as environment variables: +# export BROWSERSTACK_USERNAME=your_username +# export BROWSERSTACK_ACCESS_KEY=your_access_key +userName: YOUR_USERNAME +accessKey: YOUR_ACCESS_KEY + +# ===================== +# Reporting +# ===================== +projectName: First Java Project +buildName: browserstack-build-1 +buildIdentifier: '#${BUILD_NUMBER}' + +# ===================== +# App under test +# ===================== +app: bs:// # Replace with the app_url from Step 1 + +# ===================== +# Target devices +# ===================== +platforms: + - deviceName: + platformVersion: + platformName: + +parallelsPerPlatform: 1 + +# ===================== +# Local Testing (optional) +# ===================== +browserstackLocal: # Set to true for local/internal environment tests +``` + +--- + +### Step 3 — Run your tests + +Make sure you are inside the `java_8/` directory before running any of the following commands. + +#### Run Android sample test + +```sh +mvn test -P android-first-test +``` + +#### Run iOS sample test + +```sh +mvn test -P ios-first-test +``` + +#### Run Android local test + +```sh +mvn test -P android-local-test +``` + +#### Run iOS local test + +```sh +mvn test -P ios-local-test +``` + +--- + + +## Local Testing + +Local Testing lets you test apps that access resources on your internal or staging environments. + +To enable it, set the following in `browserstack.yml`: + +```yaml +browserstackLocal: true +``` + +The SDK will automatically start and stop the BrowserStack Local tunnel — no manual binary setup needed. Then run the local test profile: + +```sh +# Android +mvn test -P android-local-test + +# iOS +mvn test -P ios-local-test +``` + +> **Note for macOS users:** If you encounter Apple permission issues with the Local binary, go to: +> `System Preferences → Security & Privacy → General → Allow app` + +--- + +## Notes on java-client 8.x + +This module uses `io.appium:java-client:8.x`. Key differences from 7.x: + +- Use `AppiumBy` instead of the deprecated `MobileBy`. +- `MobileElement`, `IOSElement`, `AndroidElement` are removed — use `WebElement` instead. +- `WebDriverWait` requires a `Duration` argument: + ```java + // java-client 7.x + new WebDriverWait(driver, 30) + + // java-client 8.x + new WebDriverWait(driver, Duration.ofSeconds(30)) + ``` + +See the full [v7 to v8 migration guide](https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md#mobileelement) for details. + +--- + +## View Test Results + +After running your tests, visit the [App Automate Dashboard](https://app-automate.browserstack.com/dashboard) to see: +- Test status (pass/fail) +- Video recordings +- Device logs +- Network logs + +--- + +## Getting Help + +If you run into any issues, check the [BrowserStack Support page](https://www.browserstack.com/support/app-automate) or [contact us](https://www.browserstack.com/contact#technical-support). \ No newline at end of file diff --git a/java_7/README.md b/java_7/README.md deleted file mode 100644 index 91d90d7..0000000 --- a/java_7/README.md +++ /dev/null @@ -1,135 +0,0 @@ -| Using Java 7 client with MJSONWP protocol | [Using Java 8 client with w3c protocol](../java_8) | -|------------------------------------------ | -------------------------------------------------- | - -# java-appium-app-browserstack - -This repository demonstrates how to run Appium Java tests on BrowserStack App Automate. - -## Setup - -### Requirements - -1. Java 8+ (JDK) - -- 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. Maven - - - 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 - -To install the dependencies, run the following command in the project's base folder - -```cmd -mvn clean install -``` - -## Getting Started - -Getting Started with Appium tests in Java on BrowserStack couldn't be easier! - -### 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 : - -``` -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). - -**2. Configure and run your first test** - -Open `BrowserStackSample.java` file in the `android` directory or `ios` directory : - -- 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 - -- 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 - - ```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) - ---- - -### 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. Configure and run your local test** - -Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : - -- 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 - -- 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 : - - - For Android test, run - - ```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) - - -## 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_7/pom.xml b/java_7/pom.xml deleted file mode 100644 index 74fc8bd..0000000 --- a/java_7/pom.xml +++ /dev/null @@ -1,160 +0,0 @@ - - 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 - - - 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.BrowserStackSample - test - - - - - - - - - android-local-test - - - - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - android.BrowserStackSampleLocal - test - - - - - - - - - ios-first-test - - - - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - ios.BrowserStackSample - test - - - - - - - - - ios-local-test - - - - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - ios.BrowserStackSampleLocal - test - - - - - - - - - - \ No newline at end of file diff --git a/java_7/src/test/java/android/BrowserStackSample.java b/java_7/src/test/java/android/BrowserStackSample.java deleted file mode 100644 index 136ee81..0000000 --- a/java_7/src/test/java/android/BrowserStackSample.java +++ /dev/null @@ -1,68 +0,0 @@ -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 BrowserStackSample { - - public static void main(String[] args) throws MalformedURLException, InterruptedException { - - DesiredCapabilities caps = new DesiredCapabilities(); - - // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); - - // Set URL of the application under test - caps.setCapability("app", "bs://"); - - // Specify device and os_version for testing - caps.setCapability("device", "Google Pixel 3"); - caps.setCapability("os_version", "9.0"); - - // Set other BrowserStack capabilities - caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "browserstack-build-1"); - 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"), caps); - - - // 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_7/src/test/java/android/BrowserStackSampleLocal.java b/java_7/src/test/java/android/BrowserStackSampleLocal.java deleted file mode 100644 index 0854db1..0000000 --- a/java_7/src/test/java/android/BrowserStackSampleLocal.java +++ /dev/null @@ -1,90 +0,0 @@ -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.*; - -public class BrowserStackSampleLocal { - - 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 main(String[] args) throws Exception { - // 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"); - - // 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", "browserstack-build-1"); - capabilities.setCapability("name", "local_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 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(); - 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")); - - // 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/java_7/src/test/java/ios/BrowserStackSample.java b/java_7/src/test/java/ios/BrowserStackSample.java deleted file mode 100644 index ce5ab08..0000000 --- a/java_7/src/test/java/ios/BrowserStackSample.java +++ /dev/null @@ -1,64 +0,0 @@ -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 BrowserStackSample { - - public static void main(String[] args) throws MalformedURLException, InterruptedException { - DesiredCapabilities caps = new DesiredCapabilities(); - - // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); - - // Set URL of the application under test - caps.setCapability("app", "bs://"); - - // Specify device and os_version for testing - caps.setCapability("device", "iPhone 12"); - caps.setCapability("os_version", "13"); - - // Set other BrowserStack capabilities - caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "browserstack-build-1"); - 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"), caps); - - - // 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(); - - } - -} diff --git a/java_7/src/test/java/ios/BrowserStackSampleLocal.java b/java_7/src/test/java/ios/BrowserStackSampleLocal.java deleted file mode 100644 index a4af409..0000000 --- a/java_7/src/test/java/ios/BrowserStackSampleLocal.java +++ /dev/null @@ -1,95 +0,0 @@ -package ios; - -import com.browserstack.local.Local; -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.*; - -public class BrowserStackSampleLocal { - - 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 main(String[] args) throws Exception { - // 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", "iPhone 12"); - 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", "browserstack-build-1"); - 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(); - - 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())); - - // 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/java_8/browserstack.yml b/java_8/browserstack.yml new file mode 100644 index 0000000..c442c23 --- /dev/null +++ b/java_8/browserstack.yml @@ -0,0 +1,48 @@ +userName: BROWSERSTACK_USERNAME # or set env var BROWSERSTACK_USERNAME +accessKey: BROWSERSTACK_ACCESS_KEY + +projectName: First Java Project +buildName: browserstack-build-1 +buildIdentifier: '#${BUILD_NUMBER}' + +app: bs:// # path or bs:// + + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) +platforms: + - deviceName: Google Pixel 9 + platformVersion: 15.0 + platformName: android + - deviceName: Google Pixel 7 + platformVersion: 13.0 + platformName: android + +# for ios +# platforms: +# - deviceName: iPhone 14 +# platformVersion: 16.0 +# platformName: ios +# - deviceName: iPhone 13 +# platformVersion: 15.0 +# platformName: ios + +parallelsPerPlatform: 1 + +browserstackLocal: false +#browserStackLocalOptions: +#Options to be passed to BrowserStack local in-case of advanced configurations +# localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. +# forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. +# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) \ No newline at end of file diff --git a/java_8/pom.xml b/java_8/pom.xml index 730b734..f3fb36e 100644 --- a/java_8/pom.xml +++ b/java_8/pom.xml @@ -10,12 +10,12 @@ UTF-8 - 2.19.1 + 3.0.0-M5 default + LATEST - commons-io @@ -37,15 +37,17 @@ json-simple 1.1.1 + + + com.browserstack + browserstack-java-sdk + ${browserstack-java-sdk.version} + compile + - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - org.apache.maven.plugins maven-compiler-plugin @@ -55,6 +57,28 @@ 1.8 + + + maven-dependency-plugin + + + getClasspathFilenames + + properties + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + + @@ -64,21 +88,17 @@ - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - android.BrowserStackSample - test - - - + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + **/android/BrowserStackSample.java + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + @@ -88,21 +108,17 @@ - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - android.BrowserStackSampleLocal - test - - - + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + **/android/BrowserStackSampleLocal.java + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + @@ -112,21 +128,17 @@ - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - ios.BrowserStackSample - test - - - + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + **/ios/BrowserStackSample.java + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + @@ -136,21 +148,17 @@ - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - ios.BrowserStackSampleLocal - test - - - + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + **/ios/BrowserStackSampleLocal.java + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + diff --git a/java_8/src/test/java/android/BrowserStackSample.java b/java_8/src/test/java/android/BrowserStackSample.java index c923568..372300e 100644 --- a/java_8/src/test/java/android/BrowserStackSample.java +++ b/java_8/src/test/java/android/BrowserStackSample.java @@ -19,29 +19,8 @@ public static void main(String[] args) DesiredCapabilities caps = new DesiredCapabilities(); HashMap browserstackOptions = new HashMap(); - // 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", "first_test"); - - // Passing browserstack capabilities inside bstack:options - caps.setCapability("bstack:options", browserstackOptions); - - // Set URL of the application under test - caps.setCapability("app", "bs://"); - - // Specify deviceName and platformName for testing - caps.setCapability("deviceName", "Google Pixel 3"); - caps.setCapability("platformName", "android"); - caps.setCapability("platformVersion", "9.0"); - // Initialise the remote Webdriver using BrowserStack remote URL - // and desired capabilities defined above + // sdk injects desired capabilities AndroidDriver driver = new AndroidDriver( new URL("http://hub.browserstack.com/wd/hub"), caps diff --git a/java_8/src/test/java/android/BrowserStackSampleLocal.java b/java_8/src/test/java/android/BrowserStackSampleLocal.java index e765543..6463f9f 100644 --- a/java_8/src/test/java/android/BrowserStackSampleLocal.java +++ b/java_8/src/test/java/android/BrowserStackSampleLocal.java @@ -1,6 +1,5 @@ package android; -import com.browserstack.local.Local; import io.appium.java_client.AppiumBy; import io.appium.java_client.android.AndroidDriver; import java.net.URL; @@ -12,55 +11,10 @@ public class BrowserStackSampleLocal { - 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); - options.put("local", "true"); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - public static void main(String[] args) throws Exception { - // Start the BrowserStack Local binary - setupLocal(); DesiredCapabilities capabilities = new DesiredCapabilities(); - HashMap browserstackOptions = new HashMap(); - - // Set your access credentials - browserstackOptions.put("userName", userName); - browserstackOptions.put("accessKey", accessKey); - - // 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", "local_test"); - - // Set the browserstack.local capability to true - browserstackOptions.put("local", "true"); - - // Passing browserstack capabilities inside bstack:options - capabilities.setCapability("bstack:options", browserstackOptions); - - // Set URL of the application under test - capabilities.setCapability("app", "bs://"); - - // Specify device and os_version for testing - capabilities.setCapability("deviceName", "Google Pixel 3"); - capabilities.setCapability("platformName", "android"); - capabilities.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"), capabilities @@ -108,7 +62,5 @@ public static void main(String[] args) throws Exception { // 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/java_8/src/test/java/ios/BrowserStackSample.java b/java_8/src/test/java/ios/BrowserStackSample.java index 09d2013..53382c6 100644 --- a/java_8/src/test/java/ios/BrowserStackSample.java +++ b/java_8/src/test/java/ios/BrowserStackSample.java @@ -16,31 +16,9 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities caps = new DesiredCapabilities(); - HashMap browserstackOptions = new HashMap(); - - // 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", "first_test"); - - // Passing browserstack capabilities inside bstack:options - caps.setCapability("bstack:options", browserstackOptions); - - // Set URL of the application under test - caps.setCapability("app", "bs://"); - - // Specify device and os_version for testing - caps.setCapability("deviceName", "iPhone 12"); - caps.setCapability("platformName", "ios"); - caps.setCapability("platformVersion", "13"); - + // Initialise the remote Webdriver using BrowserStack remote URL - // and desired capabilities defined above + // sdk injects desired capabilities IOSDriver driver = new IOSDriver( new URL("http://hub.browserstack.com/wd/hub"), caps diff --git a/java_8/src/test/java/ios/BrowserStackSampleLocal.java b/java_8/src/test/java/ios/BrowserStackSampleLocal.java index 0493d13..1f300a2 100644 --- a/java_8/src/test/java/ios/BrowserStackSampleLocal.java +++ b/java_8/src/test/java/ios/BrowserStackSampleLocal.java @@ -1,6 +1,5 @@ package ios; -import com.browserstack.local.Local; import io.appium.java_client.AppiumBy; import io.appium.java_client.ios.IOSDriver; import java.io.File; @@ -16,55 +15,10 @@ public class BrowserStackSampleLocal { - 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); - options.put("local", "true"); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - public static void main(String[] args) throws Exception { - // Start the BrowserStack Local binary - setupLocal(); DesiredCapabilities capabilities = new DesiredCapabilities(); - HashMap browserstackOptions = new HashMap(); - - // Set your access credentials - browserstackOptions.put("userName", userName); - browserstackOptions.put("accessKey", accessKey); - - // 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", "local_test"); - - // Set the browserstack.local capability to true - browserstackOptions.put("local", "true"); - - // Passing browserstack capabilities inside bstack:options - capabilities.setCapability("bstack:options", browserstackOptions); - - // Set URL of the application under test - capabilities.setCapability("app", "bs://"); - - // Specify device and os_version for testing - capabilities.setCapability("deviceName", "iPhone 12"); - capabilities.setCapability("platformName", "ios"); - capabilities.setCapability("platformVersion", "13"); - // 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 @@ -123,7 +77,5 @@ public Boolean apply(WebDriver d) { // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); - // Stop the BrowserStack Local binary - tearDownLocal(); } }