Skip to content

Commit a6f31d7

Browse files
first commit
0 parents  commit a6f31d7

8 files changed

Lines changed: 338 additions & 0 deletions

File tree

WikipediaSample.apk

17.3 MB
Binary file not shown.

browserstack.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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: Google Pixel 8 Pro
43+
osVersion: 14.0
44+
platformName: android
45+
- deviceName: OnePlus 11R
46+
osVersion: 13.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)
80+
accessibility: true
81+
accessibilityOptions:
82+
wcagVersion: wcag21aa
83+
includeIssueType:
84+
bestPractice: false

pom.xml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.browserstack</groupId>
6+
<artifactId>testng-browserstack-android</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>testng-browserstack</name>
11+
<url>https://github.com/browserstack/testng-appium-app-browserstack</url>
12+
13+
<properties>
14+
<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>
17+
<surefire.version>2.19.1</surefire.version>
18+
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
19+
<config.file>default</config.file>
20+
</properties>
21+
22+
<dependencies>
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>
54+
</dependencies>
55+
56+
<build>
57+
<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>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-surefire-plugin</artifactId>
73+
<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>
80+
</plugin>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-compiler-plugin</artifactId>
84+
<version>3.8.1</version>
85+
<configuration>
86+
<source>1.8</source>
87+
<target>1.8</target>
88+
</configuration>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
93+
<profiles>
94+
<profile>
95+
<id>sample-test</id>
96+
<build>
97+
<plugins>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-surefire-plugin</artifactId>
101+
<configuration>
102+
<suiteXmlFiles>
103+
<suiteXmlFile>src/test/resources/com/browserstack/sample-test.testng.xml</suiteXmlFile>
104+
</suiteXmlFiles>
105+
</configuration>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
</profile>
110+
<profile>
111+
<id>sample-local-test</id>
112+
<build>
113+
<plugins>
114+
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
116+
<artifactId>maven-surefire-plugin</artifactId>
117+
<configuration>
118+
<suiteXmlFiles>
119+
<suiteXmlFile>src/test/resources/com/browserstack/sample-local-test.testng.xml</suiteXmlFile>
120+
</suiteXmlFiles>
121+
</configuration>
122+
</plugin>
123+
</plugins>
124+
</build>
125+
</profile>
126+
</profiles>
127+
</project>
Lines changed: 27 additions & 0 deletions
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 skipButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
19+
ExpectedConditions.presenceOfElementLocated(AppiumBy.id("org.wikipedia.alpha:id/fragment_onboarding_skip_button")));
20+
skipButton.click();
21+
22+
WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
23+
ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia")));
24+
25+
searchElement.click();
26+
WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
27+
ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/search_src_text")));
28+
insertTextElement.sendKeys("BrowserStack");
29+
Thread.sleep(5000);
30+
31+
List<WebElement> allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView"));
32+
Assert.assertTrue(allProductsName.size() > 0);
33+
}
34+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.browserstack;
2+
3+
import java.io.File;
4+
import java.time.Duration;
5+
import java.util.List;
6+
7+
import org.apache.commons.io.FileUtils;
8+
import org.openqa.selenium.OutputType;
9+
import org.openqa.selenium.TakesScreenshot;
10+
import org.openqa.selenium.WebElement;
11+
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;
17+
18+
public class LocalTest extends AppiumTest {
19+
20+
@Test
21+
public void test() throws Exception {
22+
WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
23+
ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.basicnetworking:id/test_action")));
24+
searchElement.click();
25+
WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
26+
ExpectedConditions.elementToBeClickable(AppiumBy.className("android.widget.TextView")));
27+
28+
WebElement testElement = null;
29+
List<WebElement> allTextViewElements = driver.findElements(AppiumBy.className("android.widget.TextView"));
30+
Thread.sleep(10);
31+
for(WebElement textElement : allTextViewElements) {
32+
if(textElement.getText().contains("The active connection is")) {
33+
testElement = textElement;
34+
}
35+
}
36+
37+
if(testElement == null) {
38+
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
39+
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "screenshot.png"));
40+
System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "screenshot.png");
41+
throw new Error("Cannot find the needed TextView element from app");
42+
}
43+
String matchedString = testElement.getText();
44+
System.out.println(matchedString);
45+
Assert.assertTrue(matchedString.contains("The active connection is wifi"));
46+
Assert.assertTrue(matchedString.contains("Up and running"));
47+
}
48+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+
<suite name="Local">
4+
<test name="LocalTest">
5+
<classes>
6+
<class name="com.browserstack.LocalTest"/>
7+
</classes>
8+
</test>
9+
</suite>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+
<suite name="First">
4+
<test name="FirstTest">
5+
<classes>
6+
<class name="com.browserstack.FirstTest"/>
7+
</classes>
8+
</test>
9+
</suite>

0 commit comments

Comments
 (0)