Skip to content

Commit e2b62b6

Browse files
first commit
0 parents  commit e2b62b6

11 files changed

Lines changed: 447 additions & 0 deletions

File tree

browserstack.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and
5+
# BROWSERSTACK_ACCESS_KEY as env variables
6+
userName: YOUR_USERNAME
7+
accessKey: YOUR_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+
# =======================================
28+
# Platforms (Browsers / Devices to test)
29+
# =======================================
30+
# Platforms object contains all the browser / device combinations you want to test on.
31+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
32+
platforms:
33+
- os: OS X
34+
osVersion: Big Sur
35+
browserName: Chrome
36+
browserVersion: latest
37+
38+
additionalPlatforms:
39+
- deviceName: Samsung Galaxy S22 Ultra
40+
browserName: chrome # Try 'samsung' for Samsung browser
41+
osVersion: 12.0
42+
43+
# =======================
44+
# Parallels per Platform
45+
# =======================
46+
# The number of parallel threads to be used for each platform set.
47+
# BrowserStack's SDK runner will select the best strategy based on the configured value
48+
#
49+
# 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
50+
#
51+
# 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
52+
parallelsPerPlatform: 1
53+
54+
# ==========================================
55+
# BrowserStack Local
56+
# (For localhost, staging/private websites)
57+
# ==========================================
58+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
59+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
60+
browserstackLocal: false # <boolean> (Default false)
61+
62+
# Options to be passed to BrowserStack local in-case of advanced configurations
63+
# browserStackLocalOptions:
64+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
65+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
66+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
67+
68+
# ===================
69+
# Debugging features
70+
# ===================
71+
debug: true # <boolean> # Set to true if you need screenshots for every selenium command ran
72+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
73+
#consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
74+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
75+
logLevel: debug

pom.xml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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-browserstack</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>cucumber-java-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.1.4</selenium-java.version>
20+
<browserstack-local-java.version>1.0.6</browserstack-local-java.version>
21+
<json-simple.version>1.1.1</json-simple.version>
22+
<browserstack-java-sdk.version>LATEST</browserstack-java-sdk.version>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.testng</groupId>
28+
<artifactId>testng</artifactId>
29+
<version>${testng.version}</version>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>io.cucumber</groupId>
34+
<artifactId>cucumber-java</artifactId>
35+
<version>${cucumber.version}</version>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>io.cucumber</groupId>
40+
<artifactId>cucumber-testng</artifactId>
41+
<version>${cucumber.version}</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.seleniumhq.selenium</groupId>
46+
<artifactId>selenium-java</artifactId>
47+
<version>${selenium-java.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.browserstack</groupId>
52+
<artifactId>browserstack-java-sdk</artifactId>
53+
<version>${browserstack-java-sdk.version}</version>
54+
<scope>compile</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>io.qameta.allure</groupId>
58+
<artifactId>allure-testng</artifactId>
59+
<version>2.18.1</version>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-compiler-plugin</artifactId>
69+
<version>3.8.0</version>
70+
<configuration>
71+
<source>8</source>
72+
<target>8</target>
73+
</configuration>
74+
</plugin>
75+
<plugin>
76+
<artifactId>maven-dependency-plugin</artifactId>
77+
<executions>
78+
<execution>
79+
<id>getClasspathFilenames</id>
80+
<goals>
81+
<goal>properties</goal>
82+
</goals>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-surefire-plugin</artifactId>
89+
<version>3.0.0-M5</version>
90+
<configuration>
91+
<suiteXmlFiles>
92+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
93+
</suiteXmlFiles>
94+
<argLine>
95+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
96+
</argLine>
97+
<systemPropertyVariables>
98+
<cucumber.publish.quiet>true</cucumber.publish.quiet>
99+
</systemPropertyVariables>
100+
</configuration>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
<profiles>
105+
<profile>
106+
<id>sample-test</id>
107+
<build>
108+
<plugins>
109+
<plugin>
110+
<groupId>org.apache.maven.plugins</groupId>
111+
<artifactId>maven-surefire-plugin</artifactId>
112+
<version>3.0.0-M5</version>
113+
<configuration>
114+
<suiteXmlFiles>
115+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
116+
</suiteXmlFiles>
117+
<argLine>
118+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
119+
</argLine>
120+
<systemPropertyVariables>
121+
<cucumber.publish.quiet>true</cucumber.publish.quiet>
122+
<cucumber.features>src/test/resources/features/test</cucumber.features>
123+
</systemPropertyVariables>
124+
</configuration>
125+
</plugin>
126+
</plugins>
127+
</build>
128+
</profile>
129+
<profile>
130+
<id>sample-local-test</id>
131+
<build>
132+
<plugins>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-surefire-plugin</artifactId>
136+
<version>3.0.0-M5</version>
137+
<configuration>
138+
<suiteXmlFiles>
139+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
140+
</suiteXmlFiles>
141+
<argLine>
142+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
143+
</argLine>
144+
<systemPropertyVariables>
145+
<cucumber.publish.quiet>true</cucumber.publish.quiet>
146+
<cucumber.features>src/test/resources/features/localtest</cucumber.features>
147+
</systemPropertyVariables>
148+
</configuration>
149+
</plugin>
150+
</plugins>
151+
</build>
152+
</profile>
153+
</profiles>
154+
155+
</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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.browserstack.pageobjects;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.support.ui.ExpectedConditions;
6+
import org.openqa.selenium.support.ui.WebDriverWait;
7+
8+
import java.time.Duration;
9+
10+
public class HomePage {
11+
private WebDriver webDriver;
12+
13+
private String selectedProductName;
14+
15+
public HomePage(WebDriver webDriver) {
16+
this.webDriver = webDriver;
17+
this.selectedProductName = "";
18+
}
19+
20+
private By firstProductName = By.xpath("//*[@id=\"1\"]/p");
21+
22+
private By firstProductAddToCartButton = By.xpath("//*[@id=\"1\"]/div[4]");
23+
24+
private By cartPane = By.className("float-cart__content");
25+
26+
private By productCartText = By.xpath("//*[@id=\"__next\"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]");
27+
28+
public void selectFirstProductName() {
29+
String firstProduct = webDriver.findElement(firstProductName).getText();
30+
setSelectedProductName(firstProduct);
31+
}
32+
33+
public void clickAddToCartButton() {
34+
webDriver.findElement(firstProductAddToCartButton).click();
35+
}
36+
37+
public void waitForCartToOpen() {
38+
new WebDriverWait(webDriver, Duration.ofSeconds(30)).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(cartPane));
39+
}
40+
41+
public String getProductCartText() {
42+
return webDriver.findElement(productCartText).getText();
43+
}
44+
45+
public void setSelectedProductName(String selectedProductName) {
46+
this.selectedProductName = selectedProductName;
47+
}
48+
49+
public String getSelectedProductName() {
50+
return selectedProductName;
51+
}
52+
}

0 commit comments

Comments
 (0)