diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 1682128..19a0d5c 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -67,6 +67,14 @@ jobs: cd android/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.apk" + - name: Run Gradle sample-test for testng Android + run: | + cd android/testng-examples + gradle clean sampleTest + - name: Run Gradle sampleLocalTest for testng Android + run: | + cd android/testng-examples + gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk" - name: Run mvn test for testng ios run: | cd ios/testng-examples @@ -82,6 +90,14 @@ jobs: cd ios/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.ipa" + - name: Run Gradle sample-test for testng ios + run: | + cd ios/testng-examples + gradle clean sampleTest + - name: Run Gradle sampleLocalTest for testng ios + run: | + cd ios/testng-examples + gradle clean sample-local-test -D"browserstack.app"="./LocalSample.ipa" - if: always() uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 id: status-check-completed diff --git a/.gitignore b/.gitignore index 871cd6a..f5c4409 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ target/ local.log .idea *.iml +**/logs/* +.DS_Store +build +gradle +.gradle +gradlew* diff --git a/README.md b/README.md index 3b16806..7abe9a0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # testng-appium-app-browserstack -This repository demonstrates how to run Appium tests in [TestNG](http://testng.org) on BrowserStack App Automate. +This repository demonstrates how to run Appium tests in [TestNG](http://testng.org) on BrowserStack App Automate using BrowserStack SDK. ![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780) @@ -14,10 +14,14 @@ This repository demonstrates how to run Appium tests in [TestNG](http://testng.o - 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 +2. Maven (Only required if using Maven as the build tool) - 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) +3. Gradle (Only required if using Gradle as the build tool) + - If Gradle is not downloaded, download it from [here](https://gradle.org/releases/) + - For installation, follow the instructions [here](https://gradle.org/install/) + ### Install the dependencies To install the dependencies for Android tests, run : @@ -39,20 +43,37 @@ mvn clean Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier! -### **Run first test :** +### **Run Sample test :** + +- Switch to one of the following directories: [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) +- **For Maven:** Run the following command to execute tests in the Maven environment: + ```sh + mvn test -P sample-test + ``` +- **For Gradle:** Run the following command to execute tests in the Gradle environment: + ```sh + gradle clean sampleTest + ``` -- Switch to `run_first_test` directory under [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) -- Follow the steps outlined in the documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/testng) +### **Use Local testing for apps that access resources hosted in development or testing environments :** -### **Speed up test execution with parallel testing :** +- Simply configure the `browserstackLocal` parameter in the `browserstack.yml` file accordingly in [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples). + ``` + browserstackLocal: true + ``` +- You can use the `LocalSample` app provided in both folder [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) to run your test. Change the app parameter in the `browserstack.yml` file. -- Switch to `run_parallel_test` directory under [Android examples](android/testng-examples/) or [iOS examples](ios/testng-examples/) -- Follow the steps outlined in the documentation - [Get Started with parallel testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/testng/parallelize-tests) +- **For Maven:** Run the following command to execute tests in the Maven environment: + ```sh + mvn test -P sample-local-test + ``` +- **For Gradle:** Run the following command to execute tests in the Gradle environment: + ```sh + gradle clean sampleLocalTest + ``` -### **Use Local testing for apps that access resources hosted in development or testing environments :** +-similarly for gradle you can do :- gradle clean sampleLocalTest -- Switch to `run_local_test` directory under [Android examples](android/testng-examples/) or [iOS examples](ios/testng-examples/) -- Follow the steps outlined in the documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/testng/local-testing) **Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help) diff --git a/android/testng-examples/LocalSample.apk b/android/testng-examples/LocalSample.apk new file mode 100644 index 0000000..f31c574 Binary files /dev/null and b/android/testng-examples/LocalSample.apk differ diff --git a/android/testng-examples/WikipediaSample.apk b/android/testng-examples/WikipediaSample.apk new file mode 100644 index 0000000..286e346 Binary files /dev/null and b/android/testng-examples/WikipediaSample.apk differ diff --git a/android/testng-examples/browserstack.yml b/android/testng-examples/browserstack.yml new file mode 100644 index 0000000..8451886 --- /dev/null +++ b/android/testng-examples/browserstack.yml @@ -0,0 +1,79 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: BROWSERSTACK_USERNAME +accessKey: BROWSERSTACK_ACCESS_KEY + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Samples +# Set `buildName` as the name of the job / testsuite being run +buildName: browserstack build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} +# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng` +# This property is needed to send test context to BrowserStack (test name, status) +framework: testng + +source: testng:appium-sample-sdk:v1.1 + +app: ./WikipediaSample.apk +#app: ./LocalSample.apk #For running local tests + +# ======================================= +# 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: Samsung Galaxy S22 Ultra + osVersion: 12.0 + platformName: android + - deviceName: Samsung Galaxy S21 + osVersion: 11.0 + platformName: android + - deviceName: Google Pixel 6 Pro + osVersion: 12.0 + platformName: android + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: true # (Default 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) diff --git a/android/testng-examples/build.gradle b/android/testng-examples/build.gradle new file mode 100644 index 0000000..92de6d2 --- /dev/null +++ b/android/testng-examples/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'java' +} + +repositories { mavenCentral() } + +dependencies { + testImplementation 'org.testng:testng:7.5' + implementation 'org.seleniumhq.selenium:selenium-java:4.13.0' + implementation 'io.appium:java-client:8.6.0' + implementation 'commons-io:commons-io:2.11.0' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'testng-browserstack' +sourceCompatibility = '1.8' + +def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Test) { + systemProperties = System.properties +} + +task sampleTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} + +task sampleLocalTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-local-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} diff --git a/android/testng-examples/pom.xml b/android/testng-examples/pom.xml index 0d96421..a45d8f2 100644 --- a/android/testng-examples/pom.xml +++ b/android/testng-examples/pom.xml @@ -1,9 +1,9 @@ - + + 4.0.0 com.browserstack - testng-browserstack + testng-browserstack-android 1.0-SNAPSHOT jar @@ -12,51 +12,71 @@ UTF-8 + 1.8 + 1.8 2.19.1 - - + 3.0.0-M5 default - - org.testng - testng - 6.9.10 - - - io.appium - java-client - 7.0.0 - - - commons-io - commons-io - 1.3.2 - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - - - com.browserstack - browserstack-local-java - 1.0.3 - - - com.googlecode.json-simple - json-simple - 1.1.1 - + + org.testng + testng + 7.5 + + + org.seleniumhq.selenium + selenium-java + 4.13.0 + + + io.appium + java-client + 8.6.0 + + + commons-io + commons-io + 2.11.0 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + com.browserstack + browserstack-java-sdk + LATEST + compile + + + maven-dependency-plugin + 3.3.0 + + + getClasspathFilenames + + properties + + + + org.apache.maven.plugins maven-surefire-plugin 2.22.2 + + + src/test/resources/com/browserstack/sample-test.testng.xml + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + org.apache.maven.plugins @@ -72,24 +92,7 @@ - first - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/com/browserstack/run_first_test/first.testng.xml - - - - - - - - - local + sample-test @@ -97,16 +100,15 @@ maven-surefire-plugin - src/test/resources/com/browserstack/run_local_test/local.testng.xml + src/test/resources/com/browserstack/sample-test.testng.xml - - parallel + sample-local-test @@ -114,7 +116,7 @@ maven-surefire-plugin - src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml + src/test/resources/com/browserstack/sample-local-test.testng.xml @@ -122,5 +124,4 @@ - diff --git a/android/testng-examples/settings.gradle b/android/testng-examples/settings.gradle new file mode 100644 index 0000000..55607bd --- /dev/null +++ b/android/testng-examples/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + gradlePluginPortal() + } + + resolutionStrategy { + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.1.2") + } + } + } +} +rootProject.name = 'testng-browserstack-android' diff --git a/android/testng-examples/src/test/java/com/browserstack/AppiumTest.java b/android/testng-examples/src/test/java/com/browserstack/AppiumTest.java new file mode 100644 index 0000000..72708fc --- /dev/null +++ b/android/testng-examples/src/test/java/com/browserstack/AppiumTest.java @@ -0,0 +1,27 @@ +package com.browserstack; + +import java.net.URL; + +import org.openqa.selenium.MutableCapabilities; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; + +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + + +public class AppiumTest { + + public AndroidDriver driver; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + MutableCapabilities capabilities = new UiAutomator2Options(); + driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + driver.quit(); + } +} diff --git a/android/testng-examples/src/test/java/com/browserstack/FirstTest.java b/android/testng-examples/src/test/java/com/browserstack/FirstTest.java new file mode 100644 index 0000000..ad63a40 --- /dev/null +++ b/android/testng-examples/src/test/java/com/browserstack/FirstTest.java @@ -0,0 +1,34 @@ +package com.browserstack; + +import java.time.Duration; +import java.util.List; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; + +public class FirstTest extends AppiumTest { + + @Test + public void test() throws Exception { + WebElement skipButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.presenceOfElementLocated(AppiumBy.id("org.wikipedia.alpha:id/fragment_onboarding_skip_button"))); + skipButton.click(); + + WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia"))); + + searchElement.click(); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); + insertTextElement.sendKeys("BrowserStack"); + Thread.sleep(5000); + + List allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView")); + Assert.assertTrue(allProductsName.size() > 0); + } +} diff --git a/android/testng-examples/src/test/java/com/browserstack/run_local_test/LocalTest.java b/android/testng-examples/src/test/java/com/browserstack/LocalTest.java similarity index 64% rename from android/testng-examples/src/test/java/com/browserstack/run_local_test/LocalTest.java rename to android/testng-examples/src/test/java/com/browserstack/LocalTest.java index c682666..cc4387b 100644 --- a/android/testng-examples/src/test/java/com/browserstack/run_local_test/LocalTest.java +++ b/android/testng-examples/src/test/java/com/browserstack/LocalTest.java @@ -1,34 +1,34 @@ -package com.browserstack.run_local_test; - -import org.testng.Assert; -import org.testng.annotations.Test; +package com.browserstack; import java.io.File; +import java.time.Duration; import java.util.List; -import org.apache.commons.io.FileUtils; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidElement; +import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; -public class LocalTest extends BrowserStackTestNGTest { +public class LocalTest extends AppiumTest { @Test public void test() throws Exception { - AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); + WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.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"))); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.className("android.widget.TextView"))); - AndroidElement testElement = null; - List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); + WebElement testElement = null; + List allTextViewElements = driver.findElements(AppiumBy.className("android.widget.TextView")); Thread.sleep(10); - for(AndroidElement textElement : allTextViewElements) { + for(WebElement textElement : allTextViewElements) { if(textElement.getText().contains("The active connection is")) { testElement = textElement; } diff --git a/android/testng-examples/src/test/java/com/browserstack/run_first_test/BrowserStackTestNGTest.java b/android/testng-examples/src/test/java/com/browserstack/run_first_test/BrowserStackTestNGTest.java deleted file mode 100644 index d763a6d..0000000 --- a/android/testng-examples/src/test/java/com/browserstack/run_first_test/BrowserStackTestNGTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.browserstack.run_first_test; - -import java.net.URL; -import java.util.Map; -import java.util.Iterator; -import java.io.FileReader; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.JSONArray; - -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.remote.DesiredCapabilities; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.AfterMethod; - - -public class BrowserStackTestNGTest { - public AndroidDriver driver; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - JSONParser parser = new JSONParser(); - JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/com/browserstack/run_first_test/first.conf.json")); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - JSONArray envs = (JSONArray) config.get("environments"); - Map envCapabilities = (Map) envs.get(0); - Iterator it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); - } - - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(capabilities.getCapability(pair.getKey().toString()) == null){ - capabilities.setCapability(pair.getKey().toString(), pair.getValue()); - } - } - - String username = System.getenv("BROWSERSTACK_USERNAME"); - if(username == null) { - username = (String) config.get("username"); - } - - String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if(accessKey == null) { - accessKey = (String) config.get("access_key"); - } - - String app = System.getenv("BROWSERSTACK_APP_ID"); - if(app != null && !app.isEmpty()) { - capabilities.setCapability("app", app); - } - - driver = new AndroidDriver(new URL("http://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - // Invoke driver.quit() to indicate that the test is completed. - // Otherwise, it will appear as timed out on BrowserStack. - driver.quit(); - } -} diff --git a/android/testng-examples/src/test/java/com/browserstack/run_first_test/FirstTest.java b/android/testng-examples/src/test/java/com/browserstack/run_first_test/FirstTest.java deleted file mode 100644 index b77b748..0000000 --- a/android/testng-examples/src/test/java/com/browserstack/run_first_test/FirstTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.browserstack.run_first_test; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import org.testng.Assert; -import org.testng.annotations.Test; -import java.util.List; - -public class FirstTest extends BrowserStackTestNGTest { - - @Test - public void test() throws Exception { - 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.assertTrue(allProductsName.size() > 0); - } -} diff --git a/android/testng-examples/src/test/java/com/browserstack/run_local_test/BrowserStackTestNGTest.java b/android/testng-examples/src/test/java/com/browserstack/run_local_test/BrowserStackTestNGTest.java deleted file mode 100644 index 1bbfe29..0000000 --- a/android/testng-examples/src/test/java/com/browserstack/run_local_test/BrowserStackTestNGTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.browserstack.run_local_test; -import com.browserstack.local.Local; - -import java.net.URL; -import java.util.Map; -import java.util.HashMap; -import java.util.Iterator; -import java.io.FileReader; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.JSONArray; - -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.remote.DesiredCapabilities; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.AfterMethod; - - -public class BrowserStackTestNGTest { - public AndroidDriver driver; - private Local local; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - JSONParser parser = new JSONParser(); - JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/com/browserstack/run_local_test/local.conf.json")); - JSONArray envs = (JSONArray) config.get("environments"); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - Map envCapabilities = (Map) envs.get(0); - Iterator it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); - } - - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(capabilities.getCapability(pair.getKey().toString()) == null){ - capabilities.setCapability(pair.getKey().toString(), pair.getValue()); - } - } - - String username = System.getenv("BROWSERSTACK_USERNAME"); - if(username == null) { - username = (String) config.get("username"); - } - - String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if(accessKey == null) { - accessKey = (String) config.get("access_key"); - } - - String app = System.getenv("BROWSERSTACK_APP_ID"); - if(app != null && !app.isEmpty()) { - capabilities.setCapability("app", app); - } - - if(capabilities.getCapability("browserstack.local") != null && capabilities.getCapability("browserstack.local") == "true"){ - local = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - local.start(options); - } - - driver = new AndroidDriver(new URL("http://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - // Invoke driver.quit() to indicate that the test is completed. - // Otherwise, it will appear as timed out on BrowserStack. - driver.quit(); - if(local != null) local.stop(); - } -} diff --git a/android/testng-examples/src/test/java/com/browserstack/run_parallel_test/BrowserStackTestNGTest.java b/android/testng-examples/src/test/java/com/browserstack/run_parallel_test/BrowserStackTestNGTest.java deleted file mode 100644 index 4172790..0000000 --- a/android/testng-examples/src/test/java/com/browserstack/run_parallel_test/BrowserStackTestNGTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.browserstack.run_parallel_test; - -import java.net.URL; -import java.util.Map; -import java.util.Iterator; -import java.io.FileReader; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.JSONArray; - -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.remote.DesiredCapabilities; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Parameters; - - -public class BrowserStackTestNGTest { - public AndroidDriver driver; - - @BeforeMethod(alwaysRun=true) - @org.testng.annotations.Parameters(value={"deviceIndex"}) - public void setUp(String deviceIndex) throws Exception { - JSONParser parser = new JSONParser(); - JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json")); - JSONArray envs = (JSONArray) config.get("environments"); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - Map envCapabilities = (Map) envs.get(Integer.parseInt(deviceIndex)); - Iterator it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); - } - - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(capabilities.getCapability(pair.getKey().toString()) == null){ - capabilities.setCapability(pair.getKey().toString(), pair.getValue()); - } - } - - String username = System.getenv("BROWSERSTACK_USERNAME"); - if(username == null) { - username = (String) config.get("username"); - } - - String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if(accessKey == null) { - accessKey = (String) config.get("access_key"); - } - - String app = System.getenv("BROWSERSTACK_APP_ID"); - if(app != null && !app.isEmpty()) { - capabilities.setCapability("app", app); - } - - driver = new AndroidDriver(new URL("http://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - // Invoke driver.quit() to indicate that the test is completed. - // Otherwise, it will appear as timed out on BrowserStack. - driver.quit(); - } -} diff --git a/android/testng-examples/src/test/java/com/browserstack/run_parallel_test/ParallelTest.java b/android/testng-examples/src/test/java/com/browserstack/run_parallel_test/ParallelTest.java deleted file mode 100644 index a6d5e13..0000000 --- a/android/testng-examples/src/test/java/com/browserstack/run_parallel_test/ParallelTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.browserstack.run_parallel_test; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import org.testng.Assert; -import org.testng.annotations.Test; -import java.util.List; - -public class ParallelTest extends BrowserStackTestNGTest { - - @Test - public void test() throws Exception { - 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.assertTrue(allProductsName.size() > 0); - } -} diff --git a/android/testng-examples/src/test/resources/com/browserstack/run_first_test/first.conf.json b/android/testng-examples/src/test/resources/com/browserstack/run_first_test/first.conf.json deleted file mode 100644 index 48f3e7b..0000000 --- a/android/testng-examples/src/test/resources/com/browserstack/run_first_test/first.conf.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "server": "hub-cloud.browserstack.com", - "username": "BROWSERSTACK_USERNAME", - "access_key": "BROWSERSTACK_ACCESS_KEY", - - "capabilities": { - "project": "First TestNg Android Project", - "build": "browserstack-build-1", - "name": "first_test", - "browserstack.debug": true, - "app": "bs://" - }, - - "environments": [ - { - "device": "Google Pixel 3", - "os_version": "9.0" - } - ] -} diff --git a/android/testng-examples/src/test/resources/com/browserstack/run_local_test/local.conf.json b/android/testng-examples/src/test/resources/com/browserstack/run_local_test/local.conf.json deleted file mode 100644 index af26c45..0000000 --- a/android/testng-examples/src/test/resources/com/browserstack/run_local_test/local.conf.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "server": "hub-cloud.browserstack.com", - "username": "BROWSERSTACK_USERNAME", - "access_key": "BROWSERSTACK_ACCESS_KEY", - - "capabilities": { - "project": "First TestNg Android Project", - "build": "browserstack-build-1", - "name": "local_test", - "browserstack.debug": true, - "browserstack.local": true, - "app": "bs://" - }, - - "environments": [ - { - "device": "Google Pixel 3", - "os_version": "9.0" - } - ] -} diff --git a/android/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json b/android/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json deleted file mode 100644 index 5571d9a..0000000 --- a/android/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "server": "hub-cloud.browserstack.com", - "username": "BROWSERSTACK_USERNAME", - "access_key": "BROWSERSTACK_ACCESS_KEY", - - "capabilities": { - "project": "First TestNg Android Project", - "build": "browserstack-build-1", - "name": "parallel_test", - "browserstack.debug": true, - "app": "bs://" - }, - - "environments": [ - { - "device": "Google Pixel 3", - "os_version": "9.0" - }, - { - "device": "Samsung Galaxy S10e", - "os_version": "9.0" - } - ] -} diff --git a/android/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml b/android/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml deleted file mode 100644 index b009413..0000000 --- a/android/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/android/testng-examples/src/test/resources/com/browserstack/run_local_test/local.testng.xml b/android/testng-examples/src/test/resources/com/browserstack/sample-local-test.testng.xml similarity index 74% rename from android/testng-examples/src/test/resources/com/browserstack/run_local_test/local.testng.xml rename to android/testng-examples/src/test/resources/com/browserstack/sample-local-test.testng.xml index 26bcaff..49e888d 100644 --- a/android/testng-examples/src/test/resources/com/browserstack/run_local_test/local.testng.xml +++ b/android/testng-examples/src/test/resources/com/browserstack/sample-local-test.testng.xml @@ -3,7 +3,7 @@ - + diff --git a/android/testng-examples/src/test/resources/com/browserstack/run_first_test/first.testng.xml b/android/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml similarity index 74% rename from android/testng-examples/src/test/resources/com/browserstack/run_first_test/first.testng.xml rename to android/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml index 8624aeb..e5ee774 100644 --- a/android/testng-examples/src/test/resources/com/browserstack/run_first_test/first.testng.xml +++ b/android/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml @@ -3,7 +3,7 @@ - + diff --git a/ios/testng-examples/BStackSampleApp.ipa b/ios/testng-examples/BStackSampleApp.ipa new file mode 100644 index 0000000..c1891b8 Binary files /dev/null and b/ios/testng-examples/BStackSampleApp.ipa differ diff --git a/ios/testng-examples/LocalSample.ipa b/ios/testng-examples/LocalSample.ipa new file mode 100644 index 0000000..a937349 Binary files /dev/null and b/ios/testng-examples/LocalSample.ipa differ diff --git a/ios/testng-examples/browserstack.yml b/ios/testng-examples/browserstack.yml new file mode 100644 index 0000000..3ed4d02 --- /dev/null +++ b/ios/testng-examples/browserstack.yml @@ -0,0 +1,79 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: BROWSERSTACK_USERNAME +accessKey: BROWSERSTACK_ACCESS_KEY + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Samples +# Set `buildName` as the name of the job / testsuite being run +buildName: browserstack build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} +# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng` +# This property is needed to send test context to BrowserStack (test name, status) +framework: testng + +source: testng:appium-sample-sdk:v1.1 + +app: ./BStackSampleApp.ipa +#app: ./LocalSample.ipa #For running local tests + +# ======================================= +# 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: iPhone 14 Pro + osVersion: 16 + platformName: ios + - deviceName: iPhone 13 Pro + osVersion: 15 + platformName: ios + - deviceName: iPhone 15 Plus + osVersion: 17 + platformName: ios + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: true # (Default 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) diff --git a/ios/testng-examples/build.gradle b/ios/testng-examples/build.gradle new file mode 100644 index 0000000..92de6d2 --- /dev/null +++ b/ios/testng-examples/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'java' +} + +repositories { mavenCentral() } + +dependencies { + testImplementation 'org.testng:testng:7.5' + implementation 'org.seleniumhq.selenium:selenium-java:4.13.0' + implementation 'io.appium:java-client:8.6.0' + implementation 'commons-io:commons-io:2.11.0' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'testng-browserstack' +sourceCompatibility = '1.8' + +def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Test) { + systemProperties = System.properties +} + +task sampleTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} + +task sampleLocalTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-local-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} diff --git a/ios/testng-examples/pom.xml b/ios/testng-examples/pom.xml index 0d96421..be9d229 100644 --- a/ios/testng-examples/pom.xml +++ b/ios/testng-examples/pom.xml @@ -1,126 +1,127 @@ - - 4.0.0 + + + 4.0.0 - com.browserstack - testng-browserstack - 1.0-SNAPSHOT - jar + com.browserstack + testng-browserstack-ios + 1.0-SNAPSHOT + jar - testng-browserstack - https://github.com/browserstack/testng-appium-app-browserstack + testng-browserstack + https://github.com/browserstack/testng-appium-app-browserstack - - UTF-8 - 2.19.1 + + UTF-8 + 1.8 + 1.8 + 2.19.1 + 3.0.0-M5 + default + - - default - - - + - org.testng - testng - 6.9.10 + org.testng + testng + 7.5 - io.appium - java-client - 7.0.0 + org.seleniumhq.selenium + selenium-java + 4.13.0 - commons-io - commons-io - 1.3.2 + io.appium + java-client + 8.6.0 - org.seleniumhq.selenium - selenium-java - 3.141.59 + commons-io + commons-io + 2.11.0 - com.browserstack - browserstack-local-java - 1.0.3 + com.googlecode.json-simple + json-simple + 1.1.1 - com.googlecode.json-simple - json-simple - 1.1.1 + com.browserstack + browserstack-java-sdk + LATEST + compile - + + + + + + maven-dependency-plugin + 3.3.0 + + + getClasspathFilenames + + properties + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + src/test/resources/com/browserstack/sample-test.testng.xml + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + - + + + sample-test + - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/com/browserstack/sample-test.testng.xml + + + - - - - - first - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/com/browserstack/run_first_test/first.testng.xml - - - - - - - - - local - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/com/browserstack/run_local_test/local.testng.xml - - - - - - - - - parallel - - - - org.apache.maven.plugins - maven-surefire-plugin - - - src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml - - - - - - - - + + + + sample-local-test + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/com/browserstack/sample-local-test.testng.xml + + + + + + + diff --git a/ios/testng-examples/settings.gradle b/ios/testng-examples/settings.gradle new file mode 100644 index 0000000..e77c63f --- /dev/null +++ b/ios/testng-examples/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + gradlePluginPortal() + } + + resolutionStrategy { + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.1.2") + } + } + } +} +rootProject.name = 'testng-browserstack-ios' diff --git a/ios/testng-examples/src/test/java/com/browserstack/AppiumTest.java b/ios/testng-examples/src/test/java/com/browserstack/AppiumTest.java new file mode 100644 index 0000000..7101fca --- /dev/null +++ b/ios/testng-examples/src/test/java/com/browserstack/AppiumTest.java @@ -0,0 +1,27 @@ +package com.browserstack; + +import java.net.URL; + +import org.openqa.selenium.MutableCapabilities; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; + +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.options.XCUITestOptions; + + +public class AppiumTest { + + public IOSDriver driver; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + MutableCapabilities options = new XCUITestOptions(); + driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),options); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + driver.quit(); + } +} diff --git a/ios/testng-examples/src/test/java/com/browserstack/FirstTest.java b/ios/testng-examples/src/test/java/com/browserstack/FirstTest.java new file mode 100644 index 0000000..f7e990e --- /dev/null +++ b/ios/testng-examples/src/test/java/com/browserstack/FirstTest.java @@ -0,0 +1,32 @@ +package com.browserstack; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; + +import java.time.Duration; + +public class FirstTest extends AppiumTest { + + @Test + public void test() throws Exception { + WebElement textButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Button"))); + textButton.click(); + WebElement textInput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); + textInput.sendKeys("hello@browserstack.com"+"\n"); + + Thread.sleep(5000); + + WebElement textOutput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); + + Assert.assertEquals(textOutput.getText(),"hello@browserstack.com"); + } +} diff --git a/ios/testng-examples/src/test/java/com/browserstack/run_local_test/LocalTest.java b/ios/testng-examples/src/test/java/com/browserstack/LocalTest.java similarity index 70% rename from ios/testng-examples/src/test/java/com/browserstack/run_local_test/LocalTest.java rename to ios/testng-examples/src/test/java/com/browserstack/LocalTest.java index 0bf3c26..c9485e9 100644 --- a/ios/testng-examples/src/test/java/com/browserstack/run_local_test/LocalTest.java +++ b/ios/testng-examples/src/test/java/com/browserstack/LocalTest.java @@ -1,4 +1,4 @@ -package com.browserstack.run_local_test; +package com.browserstack; import org.testng.Assert; import org.testng.annotations.Test; @@ -13,27 +13,29 @@ import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSElement; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import java.time.Duration; -public class LocalTest extends BrowserStackTestNGTest { + +public class LocalTest extends AppiumTest { @Test public void test() throws Exception { - IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); + WebElement testButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("TestBrowserStackLocal"))); testButton.click(); - WebDriverWait wait = new WebDriverWait(driver, 30); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); wait.until(new ExpectedCondition() { @Override public Boolean apply(WebDriver d) { - String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); + String result = d.findElement(AppiumBy.accessibilityId("ResultBrowserStackLocal")).getAttribute("value"); return result != null && result.length() > 0; } }); - IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); + WebElement resultElement = (WebElement) driver.findElement(AppiumBy.accessibilityId("ResultBrowserStackLocal")); String resultString = resultElement.getText().toLowerCase(); System.out.println(resultString); diff --git a/ios/testng-examples/src/test/java/com/browserstack/run_first_test/BrowserStackTestNGTest.java b/ios/testng-examples/src/test/java/com/browserstack/run_first_test/BrowserStackTestNGTest.java deleted file mode 100644 index a615c89..0000000 --- a/ios/testng-examples/src/test/java/com/browserstack/run_first_test/BrowserStackTestNGTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.browserstack.run_first_test; -import com.browserstack.local.Local; - -import java.net.URL; -import java.util.Map; -import java.util.Iterator; -import java.io.FileReader; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.JSONArray; - -import org.openqa.selenium.remote.DesiredCapabilities; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.AfterMethod; - -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - - -public class BrowserStackTestNGTest { - public IOSDriver driver; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - JSONParser parser = new JSONParser(); - JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/com/browserstack/run_first_test/first.conf.json")); - JSONArray envs = (JSONArray) config.get("environments"); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - Map envCapabilities = (Map) envs.get(0); - Iterator it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); - } - - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(capabilities.getCapability(pair.getKey().toString()) == null){ - capabilities.setCapability(pair.getKey().toString(), pair.getValue()); - } - } - - String username = System.getenv("BROWSERSTACK_USERNAME"); - if(username == null) { - username = (String) config.get("username"); - } - - String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if(accessKey == null) { - accessKey = (String) config.get("access_key"); - } - - String app = System.getenv("BROWSERSTACK_APP_ID"); - if(app != null && !app.isEmpty()) { - capabilities.setCapability("app", app); - } - - driver = new IOSDriver(new URL("http://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - // Invoke driver.quit() to indicate that the test is completed. - // Otherwise, it will appear as timed out on BrowserStack. - driver.quit(); - } -} diff --git a/ios/testng-examples/src/test/java/com/browserstack/run_first_test/FirstTest.java b/ios/testng-examples/src/test/java/com/browserstack/run_first_test/FirstTest.java deleted file mode 100644 index 738163e..0000000 --- a/ios/testng-examples/src/test/java/com/browserstack/run_first_test/FirstTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.browserstack.run_first_test; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSElement; - - -public class FirstTest extends BrowserStackTestNGTest { - - @Test - public void test() throws Exception { - 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"+"\n"); - - Thread.sleep(5000); - - IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); - - Assert.assertEquals(textOutput.getText(),"hello@browserstack.com"); - } -} diff --git a/ios/testng-examples/src/test/java/com/browserstack/run_local_test/BrowserStackTestNGTest.java b/ios/testng-examples/src/test/java/com/browserstack/run_local_test/BrowserStackTestNGTest.java deleted file mode 100644 index 47764ab..0000000 --- a/ios/testng-examples/src/test/java/com/browserstack/run_local_test/BrowserStackTestNGTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.browserstack.run_local_test; -import com.browserstack.local.Local; - -import java.net.URL; -import java.util.Map; -import java.util.HashMap; -import java.util.Iterator; -import java.io.FileReader; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.JSONArray; - -import org.openqa.selenium.remote.DesiredCapabilities; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.AfterMethod; - -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - - -public class BrowserStackTestNGTest { - public IOSDriver driver; - private Local local; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - JSONParser parser = new JSONParser(); - JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/com/browserstack/run_local_test/local.conf.json")); - JSONArray envs = (JSONArray) config.get("environments"); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - Map envCapabilities = (Map) envs.get(0); - Iterator it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); - } - - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(capabilities.getCapability(pair.getKey().toString()) == null){ - capabilities.setCapability(pair.getKey().toString(), pair.getValue()); - } - } - - String username = System.getenv("BROWSERSTACK_USERNAME"); - if(username == null) { - username = (String) config.get("username"); - } - - String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if(accessKey == null) { - accessKey = (String) config.get("access_key"); - } - - String app = System.getenv("BROWSERSTACK_APP_ID"); - if(app != null && !app.isEmpty()) { - capabilities.setCapability("app", app); - } - - if(capabilities.getCapability("browserstack.local") != null && capabilities.getCapability("browserstack.local") == "true"){ - local = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - local.start(options); - } - - driver = new IOSDriver(new URL("http://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - // Invoke driver.quit() to indicate that the test is completed. - // Otherwise, it will appear as timed out on BrowserStack. - driver.quit(); - if(local != null) local.stop(); - } -} diff --git a/ios/testng-examples/src/test/java/com/browserstack/run_parallel_test/BrowserStackTestNGTest.java b/ios/testng-examples/src/test/java/com/browserstack/run_parallel_test/BrowserStackTestNGTest.java deleted file mode 100644 index e6e08bc..0000000 --- a/ios/testng-examples/src/test/java/com/browserstack/run_parallel_test/BrowserStackTestNGTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.browserstack.run_parallel_test; - -import java.net.URL; -import java.util.Map; -import java.util.Iterator; -import java.io.FileReader; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.JSONArray; - -import org.openqa.selenium.remote.DesiredCapabilities; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Parameters; - -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - - -public class BrowserStackTestNGTest { - public IOSDriver driver; - - @BeforeMethod(alwaysRun=true) - @org.testng.annotations.Parameters(value={"deviceIndex"}) - public void setUp(String deviceIndex) throws Exception { - JSONParser parser = new JSONParser(); - JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json")); - JSONArray envs = (JSONArray) config.get("environments"); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - Map envCapabilities = (Map) envs.get(Integer.parseInt(deviceIndex)); - Iterator it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString()); - } - - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - if(capabilities.getCapability(pair.getKey().toString()) == null){ - capabilities.setCapability(pair.getKey().toString(), pair.getValue()); - } - } - - String username = System.getenv("BROWSERSTACK_USERNAME"); - if(username == null) { - username = (String) config.get("username"); - } - - String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if(accessKey == null) { - accessKey = (String) config.get("access_key"); - } - - String app = System.getenv("BROWSERSTACK_APP_ID"); - if(app != null && !app.isEmpty()) { - capabilities.setCapability("app", app); - } - - driver = new IOSDriver(new URL("http://"+username+":"+accessKey+"@"+config.get("server")+"/wd/hub"), capabilities); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - // Invoke driver.quit() to indicate that the test is completed. - // Otherwise, it will appear as timed out on BrowserStack. - driver.quit(); - } -} diff --git a/ios/testng-examples/src/test/java/com/browserstack/run_parallel_test/ParallelTest.java b/ios/testng-examples/src/test/java/com/browserstack/run_parallel_test/ParallelTest.java deleted file mode 100644 index bbd3b80..0000000 --- a/ios/testng-examples/src/test/java/com/browserstack/run_parallel_test/ParallelTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.browserstack.run_parallel_test; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSElement; - - -public class ParallelTest extends BrowserStackTestNGTest { - - @Test - public void test() throws Exception { - 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"+"\n"); - - Thread.sleep(5000); - - IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); - - Assert.assertEquals(textOutput.getText(),"hello@browserstack.com"); - } -} diff --git a/ios/testng-examples/src/test/resources/com/browserstack/run_first_test/first.conf.json b/ios/testng-examples/src/test/resources/com/browserstack/run_first_test/first.conf.json deleted file mode 100644 index 9cba216..0000000 --- a/ios/testng-examples/src/test/resources/com/browserstack/run_first_test/first.conf.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "server": "hub-cloud.browserstack.com", - "username": "BROWSERSTACK_USERNAME", - "access_key": "BROWSERSTACK_ACCESS_KEY", - - "capabilities": { - "project": "First TestNg iOS Project", - "build": "browserstack-build-1", - "name": "first_test", - "browserstack.debug": true, - "app": "bs://" - }, - - "environments": [ - { - "device": "iPhone 11 Pro", - "os_version": "13" - } - ] -} diff --git a/ios/testng-examples/src/test/resources/com/browserstack/run_local_test/local.conf.json b/ios/testng-examples/src/test/resources/com/browserstack/run_local_test/local.conf.json deleted file mode 100644 index 9acbe44..0000000 --- a/ios/testng-examples/src/test/resources/com/browserstack/run_local_test/local.conf.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "server": "hub-cloud.browserstack.com", - "username": "BROWSERSTACK_USERNAME", - "access_key": "BROWSERSTACK_ACCESS_KEY", - - "capabilities": { - "project": "First TestNg iOS Project", - "build": "browserstack-build-1", - "name": "local_test", - "browserstack.debug": true, - "browserstack.local": true, - "app": "bs://" - }, - - "environments": [ - { - "device": "iPhone 11 Pro", - "os_version": "13" - } - ] -} diff --git a/ios/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json b/ios/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json deleted file mode 100644 index 6b7afe9..0000000 --- a/ios/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.conf.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "server": "hub-cloud.browserstack.com", - "username": "BROWSERSTACK_USERNAME", - "access_key": "BROWSERSTACK_ACCESS_KEY", - - "capabilities": { - "project": "First TestNg iOS Project", - "build": "browserstack-build-1", - "name": "parallel_test", - "browserstack.debug": true, - "app": "bs://" - }, - - "environments": [ - { - "device": "iPhone 11 Pro", - "os_version": "13" - }, - { - "device": "iPhone 11 Pro Max", - "os_version": "13" - } - ] -} diff --git a/ios/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml b/ios/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml deleted file mode 100644 index b009413..0000000 --- a/ios/testng-examples/src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/ios/testng-examples/src/test/resources/com/browserstack/run_local_test/local.testng.xml b/ios/testng-examples/src/test/resources/com/browserstack/sample-local-test.testng.xml similarity index 74% rename from ios/testng-examples/src/test/resources/com/browserstack/run_local_test/local.testng.xml rename to ios/testng-examples/src/test/resources/com/browserstack/sample-local-test.testng.xml index 26bcaff..49e888d 100644 --- a/ios/testng-examples/src/test/resources/com/browserstack/run_local_test/local.testng.xml +++ b/ios/testng-examples/src/test/resources/com/browserstack/sample-local-test.testng.xml @@ -3,7 +3,7 @@ - + diff --git a/ios/testng-examples/src/test/resources/com/browserstack/run_first_test/first.testng.xml b/ios/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml similarity index 74% rename from ios/testng-examples/src/test/resources/com/browserstack/run_first_test/first.testng.xml rename to ios/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml index 8624aeb..e5ee774 100644 --- a/ios/testng-examples/src/test/resources/com/browserstack/run_first_test/first.testng.xml +++ b/ios/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml @@ -3,7 +3,7 @@ - +