Skip to content

Commit 8956a14

Browse files
authored
Merge pull request #33 from browserstack/merge_sdk_to_master
Merge sdk to master
2 parents 0de59be + 8c3a218 commit 8956a14

38 files changed

+484
-940
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ target/
33
local.log
44
.idea
55
*.iml
6+
**/logs/*
7+
.DS_Store

README.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# testng-appium-app-browserstack
22

3-
This repository demonstrates how to run Appium tests in [TestNG](http://testng.org) on BrowserStack App Automate.
3+
This repository demonstrates how to run Appium tests in [TestNG](http://testng.org) on BrowserStack App Automate using BrowserStack SDK.
44

55
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
66

@@ -39,20 +39,19 @@ mvn clean
3939

4040
Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier!
4141

42-
### **Run first test :**
42+
### **Run Sample 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 sample-test`
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+
```
51+
browserstackLocal: true
52+
```
53+
- 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 sample-local-test`
54+
5655

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

3.84 MB
Binary file not shown.
19.4 MB
Binary file not shown.
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
# BrowserStack Reporting
11+
# ======================
12+
# The following capabilities are used to set up reporting on BrowserStack:
13+
# Set 'projectName' to the name of your project. Example, Marketing Website
14+
projectName: BrowserStack Samples
15+
# Set `buildName` as the name of the job / testsuite being run
16+
buildName: browserstack build
17+
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
18+
# buildName. Choose your buildIdentifier format from the available expressions:
19+
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
20+
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
21+
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
22+
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}
23+
# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng`
24+
# This property is needed to send test context to BrowserStack (test name, status)
25+
framework: testng
26+
27+
source: testng:appium-sample-sdk:v1.1
28+
29+
app: ./WikipediaSample.apk
30+
#app: ./LocalSample.apk #For running local tests
31+
32+
# =======================================
33+
# Platforms (Browsers / Devices to test)
34+
# =======================================
35+
# Platforms object contains all the browser / device combinations you want to test on.
36+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
37+
38+
platforms:
39+
- deviceName: Samsung Galaxy S22 Ultra
40+
osVersion: 12.0
41+
platformName: android
42+
- deviceName: Samsung Galaxy S21
43+
osVersion: 11.0
44+
platformName: android
45+
- deviceName: Google Pixel 6 Pro
46+
osVersion: 12.0
47+
platformName: android
48+
49+
# =======================
50+
# Parallels per Platform
51+
# =======================
52+
# The number of parallel threads to be used for each platform set.
53+
# BrowserStack's SDK runner will select the best strategy based on the configured value
54+
#
55+
# 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
56+
#
57+
# 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
58+
parallelsPerPlatform: 1
59+
60+
# ==========================================
61+
# BrowserStack Local
62+
# (For localhost, staging/private websites)
63+
# ==========================================
64+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
65+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
66+
browserstackLocal: true # <boolean> (Default false)
67+
#browserStackLocalOptions:
68+
#Options to be passed to BrowserStack local in-case of advanced configurations
69+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
70+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
71+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
72+
73+
# ===================
74+
# Debugging features
75+
# ===================
76+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
77+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
78+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
79+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

android/testng-examples/pom.xml

+59-58
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,71 @@
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.5</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.seleniumhq.selenium</groupId>
30+
<artifactId>selenium-java</artifactId>
31+
<version>4.13.0</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.appium</groupId>
35+
<artifactId>java-client</artifactId>
36+
<version>8.6.0</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>commons-io</groupId>
40+
<artifactId>commons-io</artifactId>
41+
<version>2.11.0</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.googlecode.json-simple</groupId>
45+
<artifactId>json-simple</artifactId>
46+
<version>1.1.1</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.browserstack</groupId>
50+
<artifactId>browserstack-java-sdk</artifactId>
51+
<version>LATEST</version>
52+
<scope>compile</scope>
53+
</dependency>
5254
</dependencies>
5355

5456
<build>
5557
<plugins>
58+
<plugin>
59+
<artifactId>maven-dependency-plugin</artifactId>
60+
<version>3.3.0</version>
61+
<executions>
62+
<execution>
63+
<id>getClasspathFilenames</id>
64+
<goals>
65+
<goal>properties</goal>
66+
</goals>
67+
</execution>
68+
</executions>
69+
</plugin>
5670
<plugin>
5771
<groupId>org.apache.maven.plugins</groupId>
5872
<artifactId>maven-surefire-plugin</artifactId>
5973
<version>2.22.2</version>
74+
<configuration>
75+
<suiteXmlFiles>
76+
<suiteXmlFile>src/test/resources/com/browserstack/sample-test.testng.xml</suiteXmlFile>
77+
</suiteXmlFiles>
78+
<argLine>-javaagent:${com.browserstack:browserstack-java-sdk:jar}</argLine>
79+
</configuration>
6080
</plugin>
6181
<plugin>
6282
<groupId>org.apache.maven.plugins</groupId>
@@ -72,55 +92,36 @@
7292

7393
<profiles>
7494
<profile>
75-
<id>first</id>
76-
<build>
77-
<plugins>
78-
<plugin>
79-
<groupId>org.apache.maven.plugins</groupId>
80-
<artifactId>maven-surefire-plugin</artifactId>
81-
<configuration>
82-
<suiteXmlFiles>
83-
<suiteXmlFile>src/test/resources/com/browserstack/run_first_test/first.testng.xml</suiteXmlFile>
84-
</suiteXmlFiles>
85-
</configuration>
86-
</plugin>
87-
</plugins>
88-
</build>
89-
</profile>
90-
91-
<profile>
92-
<id>local</id>
95+
<id>sample-test</id>
9396
<build>
9497
<plugins>
9598
<plugin>
9699
<groupId>org.apache.maven.plugins</groupId>
97100
<artifactId>maven-surefire-plugin</artifactId>
98101
<configuration>
99102
<suiteXmlFiles>
100-
<suiteXmlFile>src/test/resources/com/browserstack/run_local_test/local.testng.xml</suiteXmlFile>
103+
<suiteXmlFile>src/test/resources/com/browserstack/sample-test.testng.xml</suiteXmlFile>
101104
</suiteXmlFiles>
102105
</configuration>
103106
</plugin>
104107
</plugins>
105108
</build>
106109
</profile>
107-
108110
<profile>
109-
<id>parallel</id>
111+
<id>sample-local-test</id>
110112
<build>
111113
<plugins>
112114
<plugin>
113115
<groupId>org.apache.maven.plugins</groupId>
114116
<artifactId>maven-surefire-plugin</artifactId>
115117
<configuration>
116118
<suiteXmlFiles>
117-
<suiteXmlFile>src/test/resources/com/browserstack/run_parallel_test/parallel.testng.xml</suiteXmlFile>
119+
<suiteXmlFile>src/test/resources/com/browserstack/sample-local-test.testng.xml</suiteXmlFile>
118120
</suiteXmlFiles>
119121
</configuration>
120122
</plugin>
121123
</plugins>
122124
</build>
123125
</profile>
124126
</profiles>
125-
126127
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.android.AndroidDriver;
10+
import io.appium.java_client.android.options.UiAutomator2Options;
11+
12+
13+
public class AppiumTest {
14+
15+
public AndroidDriver driver;
16+
17+
@BeforeMethod(alwaysRun=true)
18+
public void setUp() throws Exception {
19+
MutableCapabilities capabilities = new UiAutomator2Options();
20+
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
21+
}
22+
23+
@AfterMethod(alwaysRun=true)
24+
public void tearDown() throws Exception {
25+
driver.quit();
26+
}
27+
}
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+
}

0 commit comments

Comments
 (0)