Skip to content

Commit ae71996

Browse files
Merge pull request #24 from mattonem/simple-sdk
introducing browserstack-sdk to the sample repo
2 parents c2e15ad + 20b970f commit ae71996

38 files changed

+478
-936
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ target/
33
local.log
44
.idea
55
*.iml
6+
.DS_Store
7+
**/logs/*

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier!
4141

4242
### **Run first test :**
4343

44-
- Switch to `run_first_test` directory under [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples)
45-
- 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)
46-
47-
### **Speed up test execution with parallel testing :**
48-
49-
- Switch to `run_parallel_test` directory under [Android examples](android/testng-examples/) or [iOS examples](ios/testng-examples/)
50-
- 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)
44+
- Switch to one of the following directories: [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples)
45+
- Run the following maven command `mvn test -P first`
5146

5247
### **Use Local testing for apps that access resources hosted in development or testing environments :**
5348

54-
- Switch to `run_local_test` directory under [Android examples](android/testng-examples/) or [iOS examples](ios/testng-examples/)
55-
- 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)
49+
- Simply configure the `browserstackLocal` parameter in the `browserstack.yml` file accordingly in [Android examples](android/testng-examples/) or [iOS examples](ios/testng-examples/).
50+
- 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 and run the tests with the following command: `mvn test -P local`
51+
5652

5753
**Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help)
5854

6.31 MB
Binary file not shown.
19.4 MB
Binary file not shown.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
5+
# BROWSERSTACK_ACCESS_KEY as env variables
6+
userName: BROWSERSTACK_USERNAME
7+
accessKey: BROWSERSTACK_ACCESS_KEY
8+
9+
# ======================
10+
# Organizing your tests
11+
# ======================
12+
# Use `projectName`, `buildName`, `name` capabilities to organise your tests
13+
# `name` is the name of your test sessions and is automatically picked from your
14+
# test name and doesn't need to be set manually when using BrowserStack SDK
15+
# `buildName` is used to name your CI/CD job or the execution of your test suite.
16+
# Ensure you add a dynamic identifier, like an incremental build number from your
17+
# CI/CD or timestamp at the end of every build; otherwise tests from different
18+
# executions will be grouped together on BrowserStack
19+
buildName: browserstack-build
20+
# Use `projectName` to set the name of your project. Example, Marketing Website
21+
projectName: TestNg Android Project
22+
# Use `framework` to set the framework of your project. Example, testng, cucumber, cucumber-testng
23+
framework: testng
24+
25+
source: testng:sample-sdk:v1.0
26+
27+
app: ./WikipediaSample.apk
28+
# app: ./LocalSample.ipa #For running local tests
29+
30+
# =======================================
31+
# Platforms (Browsers / Devices to test)
32+
# =======================================
33+
# Platforms object contains all the browser / device combinations you want to test on.
34+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
35+
36+
platforms:
37+
- deviceName: Samsung Galaxy S22 Ultra
38+
osVersion: 12.0
39+
platformName: android
40+
- deviceName: Samsung Galaxy S21
41+
osVersion: 11.0
42+
platformName: android
43+
- deviceName: Google Pixel 6 Pro
44+
osVersion: 12.0
45+
platformName: android
46+
47+
# =======================
48+
# Parallels per Platform
49+
# =======================
50+
# The number of parallel threads to be used for each platform set.
51+
# BrowserStack's SDK runner will select the best strategy based on the configured value
52+
#
53+
# 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
54+
#
55+
# 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
56+
parallelsPerPlatform: 1
57+
58+
# ==========================================
59+
# BrowserStack Local
60+
# (For localhost, staging/private websites)
61+
# ==========================================
62+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
63+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
64+
browserstackLocal: true # <boolean> (Default false)
65+
#browserStackLocalOptions:
66+
#Options to be passed to BrowserStack local in-case of advanced configurations
67+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
68+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
69+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
70+
71+
# ===================
72+
# Debugging features
73+
# ===================
74+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
75+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
76+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
77+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

android/testng-examples/pom.xml

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>com.browserstack</groupId>
6-
<artifactId>testng-browserstack</artifactId>
6+
<artifactId>testng-browserstack-android</artifactId>
77
<version>1.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

@@ -12,51 +12,73 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.target>1.8</maven.compiler.target>
16+
<maven.compiler.source>1.8</maven.compiler.source>
1517
<surefire.version>2.19.1</surefire.version>
16-
17-
<test.file></test.file>
18+
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
1819
<config.file>default</config.file>
1920
</properties>
2021

2122
<dependencies>
22-
<dependency>
23-
<groupId>org.testng</groupId>
24-
<artifactId>testng</artifactId>
25-
<version>6.9.10</version>
26-
</dependency>
27-
<dependency>
28-
<groupId>io.appium</groupId>
29-
<artifactId>java-client</artifactId>
30-
<version>7.0.0</version>
31-
</dependency>
32-
<dependency>
33-
<groupId>commons-io</groupId>
34-
<artifactId>commons-io</artifactId>
35-
<version>1.3.2</version>
36-
</dependency>
37-
<dependency>
38-
<groupId>org.seleniumhq.selenium</groupId>
39-
<artifactId>selenium-java</artifactId>
40-
<version>3.141.59</version>
41-
</dependency>
42-
<dependency>
43-
<groupId>com.browserstack</groupId>
44-
<artifactId>browserstack-local-java</artifactId>
45-
<version>1.0.3</version>
46-
</dependency>
47-
<dependency>
48-
<groupId>com.googlecode.json-simple</groupId>
49-
<artifactId>json-simple</artifactId>
50-
<version>1.1.1</version>
51-
</dependency>
23+
<dependency>
24+
<groupId>org.testng</groupId>
25+
<artifactId>testng</artifactId>
26+
<version>7.6.1</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.appium</groupId>
30+
<artifactId>java-client</artifactId>
31+
<version>8.2.1</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>commons-io</groupId>
35+
<artifactId>commons-io</artifactId>
36+
<version>2.11.0</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.seleniumhq.selenium</groupId>
40+
<artifactId>selenium-remote-driver</artifactId>
41+
<version>4.6.0</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.browserstack</groupId>
45+
<artifactId>browserstack-local-java</artifactId>
46+
<version>1.0.3</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.googlecode.json-simple</groupId>
50+
<artifactId>json-simple</artifactId>
51+
<version>1.1.1</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.browserstack</groupId>
55+
<artifactId>browserstack-java-sdk</artifactId>
56+
<version>LATEST</version>
57+
<scope>compile</scope>
58+
</dependency>
5259
</dependencies>
5360

5461
<build>
5562
<plugins>
63+
<plugin>
64+
<artifactId>maven-dependency-plugin</artifactId>
65+
<version>3.3.0</version>
66+
<executions>
67+
<execution>
68+
<id>getClasspathFilenames</id>
69+
<goals>
70+
<goal>properties</goal>
71+
</goals>
72+
</execution>
73+
</executions>
74+
</plugin>
5675
<plugin>
5776
<groupId>org.apache.maven.plugins</groupId>
5877
<artifactId>maven-surefire-plugin</artifactId>
5978
<version>2.22.2</version>
79+
<configuration>
80+
<argLine>-javaagent:${com.browserstack:browserstack-java-sdk:jar}</argLine>
81+
</configuration>
6082
</plugin>
6183
<plugin>
6284
<groupId>org.apache.maven.plugins</groupId>
@@ -80,14 +102,13 @@
80102
<artifactId>maven-surefire-plugin</artifactId>
81103
<configuration>
82104
<suiteXmlFiles>
83-
<suiteXmlFile>src/test/resources/com/browserstack/run_first_test/first.testng.xml</suiteXmlFile>
105+
<suiteXmlFile>src/test/resources/com/browserstack/first.testng.xml</suiteXmlFile>
84106
</suiteXmlFiles>
85107
</configuration>
86108
</plugin>
87109
</plugins>
88110
</build>
89111
</profile>
90-
91112
<profile>
92113
<id>local</id>
93114
<build>
@@ -97,30 +118,12 @@
97118
<artifactId>maven-surefire-plugin</artifactId>
98119
<configuration>
99120
<suiteXmlFiles>
100-
<suiteXmlFile>src/test/resources/com/browserstack/run_local_test/local.testng.xml</suiteXmlFile>
101-
</suiteXmlFiles>
102-
</configuration>
103-
</plugin>
104-
</plugins>
105-
</build>
106-
</profile>
107-
108-
<profile>
109-
<id>parallel</id>
110-
<build>
111-
<plugins>
112-
<plugin>
113-
<groupId>org.apache.maven.plugins</groupId>
114-
<artifactId>maven-surefire-plugin</artifactId>
115-
<configuration>
116-
<suiteXmlFiles>
117-
<suiteXmlFile>src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml</suiteXmlFile>
121+
<suiteXmlFile>src/test/resources/com/browserstack/local.testng.xml</suiteXmlFile>
118122
</suiteXmlFiles>
119123
</configuration>
120124
</plugin>
121125
</plugins>
122126
</build>
123127
</profile>
124128
</profiles>
125-
126129
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.browserstack;
2+
3+
import java.net.URL;
4+
5+
import org.openqa.selenium.MutableCapabilities;
6+
import org.testng.annotations.AfterMethod;
7+
import org.testng.annotations.BeforeMethod;
8+
9+
import io.appium.java_client.AppiumDriver;
10+
import io.appium.java_client.android.AndroidDriver;
11+
import io.appium.java_client.android.options.UiAutomator2Options;
12+
13+
14+
public class AppiumTest {
15+
16+
public AppiumDriver driver;
17+
18+
@BeforeMethod(alwaysRun=true)
19+
public void setUp() throws Exception {
20+
MutableCapabilities capabilities = new UiAutomator2Options();
21+
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
22+
}
23+
24+
@AfterMethod(alwaysRun=true)
25+
public void tearDown() throws Exception {
26+
driver.quit();
27+
}
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.browserstack;
2+
3+
import java.time.Duration;
4+
import java.util.List;
5+
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.support.ui.ExpectedConditions;
8+
import org.openqa.selenium.support.ui.WebDriverWait;
9+
import org.testng.Assert;
10+
import org.testng.annotations.Test;
11+
12+
import io.appium.java_client.AppiumBy;
13+
14+
public class FirstTest extends AppiumTest {
15+
16+
@Test
17+
public void test() throws Exception {
18+
WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
19+
ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia")));
20+
21+
searchElement.click();
22+
WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
23+
ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/search_src_text")));
24+
insertTextElement.sendKeys("BrowserStack");
25+
Thread.sleep(5000);
26+
27+
List<WebElement> allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView"));
28+
Assert.assertTrue(allProductsName.size() > 0);
29+
}
30+
}

android/testng-examples/src/test/java/com/browserstack/run_local_test/LocalTest.java renamed to android/testng-examples/src/test/java/com/browserstack/LocalTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
package com.browserstack.run_local_test;
2-
3-
import org.testng.Assert;
4-
import org.testng.annotations.Test;
1+
package com.browserstack;
52

63
import java.io.File;
4+
import java.time.Duration;
75
import java.util.List;
8-
import org.apache.commons.io.FileUtils;
9-
10-
import io.appium.java_client.MobileBy;
11-
import io.appium.java_client.android.AndroidElement;
126

7+
import org.apache.commons.io.FileUtils;
138
import org.openqa.selenium.OutputType;
149
import org.openqa.selenium.TakesScreenshot;
15-
import org.openqa.selenium.support.ui.WebDriverWait;
10+
import org.openqa.selenium.WebElement;
1611
import org.openqa.selenium.support.ui.ExpectedConditions;
12+
import org.openqa.selenium.support.ui.WebDriverWait;
13+
import org.testng.Assert;
14+
import org.testng.annotations.Test;
15+
16+
import io.appium.java_client.AppiumBy;
1717

18-
public class LocalTest extends BrowserStackTestNGTest {
18+
public class LocalTest extends AppiumTest {
1919

2020
@Test
2121
public void test() throws Exception {
22-
AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until(
23-
ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action")));
22+
WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
23+
ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.basicnetworking:id/test_action")));
2424
searchElement.click();
25-
AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until(
26-
ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView")));
25+
WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
26+
ExpectedConditions.elementToBeClickable(AppiumBy.className("android.widget.TextView")));
2727

28-
AndroidElement testElement = null;
29-
List<AndroidElement> allTextViewElements = driver.findElementsByClassName("android.widget.TextView");
28+
WebElement testElement = null;
29+
List<WebElement> allTextViewElements = driver.findElements(AppiumBy.className("android.widget.TextView"));
3030
Thread.sleep(10);
31-
for(AndroidElement textElement : allTextViewElements) {
31+
for(WebElement textElement : allTextViewElements) {
3232
if(textElement.getText().contains("The active connection is")) {
3333
testElement = textElement;
3434
}

0 commit comments

Comments
 (0)