Skip to content

Commit 4ec6fa5

Browse files
Initial commit
1 parent de8a871 commit 4ec6fa5

21 files changed

Lines changed: 752 additions & 0 deletions

File tree

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.png
2+
target/
3+
local.log
4+
.idea
5+
*.iml
6+
.DS_Store
7+
**/logs/*
8+
reports/
9+
logs/

android/LocalSample.apk

3.84 MB
Binary file not shown.

android/WikipediaSample.apk

19.4 MB
Binary file not shown.

android/browserstack.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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: cucumber-testng
26+
27+
source: cucumber-java:appium-sample-main:v1.0
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+
platforms:
38+
- deviceName: Samsung Galaxy S22 Ultra
39+
platformVersion: 12.0
40+
platformName: android
41+
- deviceName: Samsung Galaxy S21
42+
platformVersion: 11.0
43+
platformName: android
44+
- deviceName: Google Pixel 6 Pro
45+
platformVersion: 12.0
46+
platformName: android
47+
48+
# =======================
49+
# Parallels per Platform
50+
# =======================
51+
# The number of parallel threads to be used for each platform set.
52+
# BrowserStack's SDK runner will select the best strategy based on the configured value
53+
#
54+
# 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
55+
#
56+
# 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
57+
parallelsPerPlatform: 1
58+
59+
# ==========================================
60+
# BrowserStack Local
61+
# (For localhost, staging/private websites)
62+
# ==========================================
63+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
64+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
65+
browserstackLocal: true # <boolean> (Default false)
66+
#browserStackLocalOptions:
67+
#Options to be passed to BrowserStack local in-case of advanced configurations
68+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
69+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
70+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
71+
72+
# ===================
73+
# Debugging features
74+
# ===================
75+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
76+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing

android/pom.xml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.browserstack</groupId>
6+
<artifactId>cucumber-java-appium-app-browserstack</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>cucumber-java-appium-app-browserstack</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
<cucumber.version>7.4.1</cucumber.version>
18+
<testng.version>7.4.0</testng.version>
19+
<selenium-java.version>4.13.0</selenium-java.version>
20+
<java-client.version>8.6.0</java-client.version>
21+
<browserstack-local-java.version>1.0.6</browserstack-local-java.version>
22+
<json-simple.version>1.1.1</json-simple.version>
23+
<browserstack-java-sdk.version>LATEST</browserstack-java-sdk.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.testng</groupId>
29+
<artifactId>testng</artifactId>
30+
<version>${testng.version}</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.cucumber</groupId>
35+
<artifactId>cucumber-java</artifactId>
36+
<version>${cucumber.version}</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.cucumber</groupId>
41+
<artifactId>cucumber-testng</artifactId>
42+
<version>${cucumber.version}</version>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.seleniumhq.selenium</groupId>
47+
<artifactId>selenium-java</artifactId>
48+
<version>${selenium-java.version}</version>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>io.appium</groupId>
53+
<artifactId>java-client</artifactId>
54+
<version>${java-client.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.browserstack</groupId>
58+
<artifactId>browserstack-java-sdk</artifactId>
59+
<version>${browserstack-java-sdk.version}</version>
60+
<scope>compile</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.qameta.allure</groupId>
64+
<artifactId>allure-testng</artifactId>
65+
<version>2.18.1</version>
66+
<scope>test</scope>
67+
</dependency>
68+
</dependencies>
69+
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-compiler-plugin</artifactId>
75+
<version>3.8.0</version>
76+
<configuration>
77+
<source>8</source>
78+
<target>8</target>
79+
</configuration>
80+
</plugin>
81+
<plugin>
82+
<artifactId>maven-dependency-plugin</artifactId>
83+
<executions>
84+
<execution>
85+
<id>getClasspathFilenames</id>
86+
<goals>
87+
<goal>properties</goal>
88+
</goals>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-surefire-plugin</artifactId>
95+
<version>3.0.0-M5</version>
96+
<configuration>
97+
<suiteXmlFiles>
98+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
99+
</suiteXmlFiles>
100+
<argLine>
101+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
102+
</argLine>
103+
<systemPropertyVariables>
104+
<cucumber.publish.quiet>true</cucumber.publish.quiet>
105+
<cucumber.features>src/test/resources/features/test</cucumber.features>
106+
</systemPropertyVariables>
107+
</configuration>
108+
</plugin>
109+
</plugins>
110+
</build>
111+
<profiles>
112+
<profile>
113+
<id>sample-test</id>
114+
<build>
115+
<plugins>
116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-surefire-plugin</artifactId>
119+
<version>3.0.0-M5</version>
120+
<configuration>
121+
<suiteXmlFiles>
122+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
123+
</suiteXmlFiles>
124+
<argLine>
125+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
126+
</argLine>
127+
<systemPropertyVariables>
128+
<cucumber.publish.quiet>true</cucumber.publish.quiet>
129+
<cucumber.features>src/test/resources/features/test</cucumber.features>
130+
</systemPropertyVariables>
131+
</configuration>
132+
</plugin>
133+
</plugins>
134+
</build>
135+
</profile>
136+
<profile>
137+
<id>sample-local-test</id>
138+
<build>
139+
<plugins>
140+
<plugin>
141+
<groupId>org.apache.maven.plugins</groupId>
142+
<artifactId>maven-surefire-plugin</artifactId>
143+
<version>3.0.0-M5</version>
144+
<configuration>
145+
<suiteXmlFiles>
146+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
147+
</suiteXmlFiles>
148+
<argLine>
149+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
150+
</argLine>
151+
<systemPropertyVariables>
152+
<cucumber.publish.quiet>true</cucumber.publish.quiet>
153+
<cucumber.features>src/test/resources/features/localtest</cucumber.features>
154+
</systemPropertyVariables>
155+
</configuration>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
</profile>
160+
</profiles>
161+
162+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.browserstack;
2+
3+
import io.cucumber.testng.*;
4+
5+
@CucumberOptions(
6+
glue = "com.browserstack.stepdefs",
7+
features = "src/test/resources/features/test",
8+
plugin = {
9+
"pretty",
10+
"html:reports/tests/cucumber/cucumber-pretty.html",
11+
"testng:reports/tests/cucumber/testng/cucumber.xml",
12+
"json:reports/tests/cucumber/json/cucumberTestReport.json"
13+
}
14+
)
15+
public class RunWebDriverCucumberTests extends AbstractTestNGCucumberTests {}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.browserstack.stepdefs;
2+
3+
import io.appium.java_client.android.AndroidDriver;
4+
import io.cucumber.java.After;
5+
import io.cucumber.java.Before;
6+
import io.cucumber.java.Scenario;
7+
import io.cucumber.java.en.Given;
8+
import io.cucumber.java.en.Then;
9+
import io.cucumber.java.en.When;
10+
import org.apache.commons.io.FileUtils;
11+
import org.openqa.selenium.*;
12+
import java.io.File;
13+
import java.io.IOException;
14+
import java.net.MalformedURLException;
15+
import java.net.URL;
16+
import java.time.Duration;
17+
import java.util.HashMap;
18+
import java.util.List;
19+
20+
import org.openqa.selenium.support.ui.ExpectedConditions;
21+
import org.openqa.selenium.support.ui.WebDriverWait;
22+
import org.testng.Assert;
23+
import io.appium.java_client.AppiumBy;
24+
25+
public class StackDemoSteps {
26+
private WebDriver driver;
27+
28+
@Before
29+
public void setUp() throws MalformedURLException {
30+
MutableCapabilities capabilities = new MutableCapabilities();
31+
HashMap<String, String> bstackOptions = new HashMap<>();
32+
bstackOptions.putIfAbsent("source", "cucumber-java:appium-sample-main:v1.0");
33+
capabilities.setCapability("bstack:options", bstackOptions);
34+
driver = new AndroidDriver(
35+
new URL("https://hub.browserstack.com/wd/hub"), capabilities);
36+
}
37+
38+
@Given("I try to search using Wikipedia App")
39+
public void I_try_to_search_wikipedia_app() throws Throwable {
40+
WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
41+
ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia")));
42+
searchElement.click();
43+
}
44+
45+
46+
@Then("I search with keyword BrowserStack")
47+
public void I_search_with_keyword_browserstack() throws InterruptedException {
48+
WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
49+
ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/search_src_text")));
50+
insertTextElement.sendKeys("BrowserStack");
51+
Thread.sleep(5000);
52+
}
53+
54+
@Then("The search results should be listed")
55+
public void search_results_should_be_listed() {
56+
List<WebElement> allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView"));
57+
Assert.assertTrue(allProductsName.size() > 0);
58+
}
59+
60+
@When("I start test on the Local Sample App")
61+
public void I_start_test_on_the_local_sample_app() {
62+
WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
63+
ExpectedConditions.elementToBeClickable(AppiumBy.id("com.example.android.basicnetworking:id/test_action")));
64+
searchElement.click();
65+
WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until(
66+
ExpectedConditions.elementToBeClickable(AppiumBy.className("android.widget.TextView")));
67+
}
68+
69+
@Then("I should see {string}")
70+
public void I_should_see(String localString) throws InterruptedException, IOException {
71+
WebElement testElement = null;
72+
List<WebElement> allTextViewElements = driver.findElements(AppiumBy.className("android.widget.TextView"));
73+
Thread.sleep(10);
74+
for (WebElement textElement : allTextViewElements) {
75+
if (textElement.getText().contains("The active connection is")) {
76+
testElement = textElement;
77+
}
78+
}
79+
80+
if (testElement == null) {
81+
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
82+
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "screenshot.png"));
83+
System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "screenshot.png");
84+
throw new Error("Cannot find the needed TextView element from app");
85+
}
86+
String matchedString = testElement.getText();
87+
System.out.println(matchedString);
88+
Assert.assertTrue(matchedString.contains("The active connection is wifi"));
89+
Assert.assertTrue(matchedString.contains(localString));
90+
}
91+
92+
@After
93+
public void teardown(Scenario scenario) throws Exception {
94+
Thread.sleep(2000);
95+
driver.quit();
96+
}
97+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allure.results.directory=target/allure-results
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Feature: BrowserStack Local Testing
2+
3+
Scenario: BStack Local Test - Can check tunnel working
4+
When I start test on the Local Sample App
5+
Then I should see "Up and running"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: BrowserStack Demo
2+
3+
Scenario: BStack Sample Test - Search BrowserStack
4+
Given I try to search using Wikipedia App
5+
Then I search with keyword BrowserStack
6+
Then The search results should be listed

0 commit comments

Comments
 (0)