Skip to content

Commit 884a05d

Browse files
committed
First commit
0 parents  commit 884a05d

File tree

10 files changed

+480
-0
lines changed

10 files changed

+480
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.png
2+
target/
3+
local.log
4+
.idea
5+
*.iml
6+
.gradle
7+
build/
8+
.DS_Store
9+
gradle
10+
gradlew
11+
gradlew.bat
12+
logs
13+
browserstack.err

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# testng-browserstack
2+
3+
[TestNG](http://testng.org) Integration with BrowserStack.
4+
5+
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
6+
7+
## Using Maven
8+
9+
### Run sample build
10+
11+
- Clone the repository
12+
- Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml.
13+
- Install dependencies `mvn compile`
14+
- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test`
15+
- To run local tests, run `mvn test -P sample-local-test`
16+
17+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
18+
19+
### Integrate your test suite
20+
21+
This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow the steps below to install the SDK in your test suite and run tests on BrowserStack:
22+
23+
* Create sample browserstack.yml file with the browserstack related capabilities with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) and place it in your root folder.
24+
* Add maven dependency of browserstack-java-sdk in your pom.xml file
25+
```sh
26+
<dependency>
27+
<groupId>com.browserstack</groupId>
28+
<artifactId>browserstack-java-sdk</artifactId>
29+
<version>LATEST</version>
30+
<scope>compile</scope>
31+
</dependency>
32+
```
33+
* Modify your build plugin to run tests by adding argLine `-javaagent:${com.browserstack:browserstack-java-sdk:jar}` and `maven-dependency-plugin` for resolving dependencies in the profiles `sample-test` and `sample-local-test`.
34+
```
35+
<plugin>
36+
<artifactId>maven-dependency-plugin</artifactId>
37+
<executions>
38+
<execution>
39+
<id>getClasspathFilenames</id>
40+
<goals>
41+
<goal>properties</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-surefire-plugin</artifactId>
49+
<version>3.0.0-M5</version>
50+
<configuration>
51+
<suiteXmlFiles>
52+
<suiteXmlFile>config/sample-local-test.testng.xml</suiteXmlFile>
53+
</suiteXmlFiles>
54+
<argLine>
55+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
56+
</argLine>
57+
</configuration>
58+
</plugin>
59+
```
60+
* Install dependencies `mvn compile`
61+
62+
## Using Gradle
63+
64+
### Prerequisites
65+
- If using Gradle, Java v9+ is required.
66+
67+
### Run sample build
68+
69+
- Clone the repository
70+
- Install dependencies `gradle build`
71+
- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`
72+
- To run local tests, run `gradle sampleLocalTest`
73+
74+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
75+
76+
### Integrate your test suite
77+
78+
This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow the steps below to install the SDK in your test suite and run tests on BrowserStack:
79+
80+
* Following are the changes required in `gradle.build` -
81+
* Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies
82+
* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* :
83+
```
84+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
85+
86+
task sampleTest(type: Test) {
87+
useTestNG() {
88+
dependsOn cleanTest
89+
useDefaultListeners = true
90+
suites "config/sample-test.testng.xml"
91+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
92+
}
93+
}
94+
```
95+
96+
* Install dependencies `gradle build`
97+
98+
99+
## Notes
100+
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)

browserstack.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
userName: #YOUR USERNAME
2+
accessKey: #YOUR ACCESS_KEY
3+
platforms:
4+
- os: Windows
5+
osVersion: 10
6+
browserName: Chrome
7+
browserVersion: 120.0
8+
- os: OS X
9+
osVersion: Monterey
10+
browserName: Safari
11+
browserVersion: 15.6
12+
- deviceName: iPhone 13
13+
osVersion: 15
14+
browserName: Chromium
15+
deviceOrientation: portrait
16+
parallelsPerPlatform: 1
17+
browserstackLocal: true
18+
buildName: End-to-End Flow
19+
projectName: T&H Project - CDI
20+
accessibility: true
21+
percy: true

build.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
repositories { mavenCentral() }
6+
7+
dependencies {
8+
implementation 'org.testng:testng:7.4.0'
9+
implementation 'commons-io:commons-io:1.3.2'
10+
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
11+
implementation 'com.browserstack:browserstack-local-java:1.0.6'
12+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
13+
compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'
14+
}
15+
16+
group = 'com.browserstack'
17+
version = '1.0-SNAPSHOT'
18+
description = 'testng-browserstack'
19+
sourceCompatibility = '1.8'
20+
21+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
22+
23+
tasks.withType(JavaCompile) {
24+
options.encoding = 'UTF-8'
25+
}
26+
27+
tasks.withType(Test) {
28+
systemProperties = System.properties
29+
}
30+
31+
task sampleTest(type: Test) {
32+
useTestNG() {
33+
dependsOn cleanTest
34+
useDefaultListeners = true
35+
suites "config/sample-test.testng.xml"
36+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
37+
}
38+
}
39+
40+
task sampleLocalTest(type: Test) {
41+
useTestNG() {
42+
dependsOn cleanTest
43+
useDefaultListeners = true
44+
suites "config/sample-local-test.testng.xml"
45+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
46+
}
47+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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.WanderStackLocalTest"/>
7+
</classes>
8+
</test>
9+
</suite>
10+

config/sample-test.testng.xml

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="Cross-Platform">
4+
<test name="WanderStack">
5+
<classes>
6+
<class name="com.browserstack.WanderStackTest" />
7+
</classes>
8+
</test>
9+
</suite>

pom.xml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
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</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>testng-browserstack</name>
11+
<url>https://www.github.com/browserstack/testng-browserstack</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+
<testng.version>7.4.0</testng.version>
18+
<surefire.version>2.19.1</surefire.version>
19+
<selenium.version>4.1.4</selenium.version>
20+
<json-simple.version>1.1.1</json-simple.version>
21+
<config.file>config/sample-test.testng.xml</config.file>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.testng</groupId>
27+
<artifactId>testng</artifactId>
28+
<version>${testng.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.seleniumhq.selenium</groupId>
32+
<artifactId>selenium-java</artifactId>
33+
<version>${selenium.version}</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.browserstack</groupId>
37+
<artifactId>browserstack-java-sdk</artifactId>
38+
<version>LATEST</version>
39+
<scope>compile</scope>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<artifactId>maven-dependency-plugin</artifactId>
47+
<executions>
48+
<execution>
49+
<id>getClasspathFilenames</id>
50+
<goals>
51+
<goal>properties</goal>
52+
</goals>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>${surefire.version}</version>
60+
<configuration>
61+
<suiteXmlFiles>
62+
<suiteXmlFile>${config.file}</suiteXmlFile>
63+
</suiteXmlFiles>
64+
<argLine>
65+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
66+
</argLine>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-compiler-plugin</artifactId>
72+
<configuration>
73+
<source>${maven.compiler.source}</source>
74+
<target>${maven.compiler.target}</target>
75+
</configuration>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
80+
<profiles>
81+
<profile>
82+
<id>sample-local-test</id>
83+
<build>
84+
<plugins>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-surefire-plugin</artifactId>
88+
<configuration>
89+
<suiteXmlFiles>
90+
<suiteXmlFile>config/sample-local-test.testng.xml</suiteXmlFile>
91+
</suiteXmlFiles>
92+
<argLine>
93+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
94+
</argLine>
95+
</configuration>
96+
</plugin>
97+
</plugins>
98+
</build>
99+
</profile>
100+
101+
<profile>
102+
<id>sample-test</id>
103+
<build>
104+
<plugins>
105+
<plugin>
106+
<groupId>org.apache.maven.plugins</groupId>
107+
<artifactId>maven-surefire-plugin</artifactId>
108+
<configuration>
109+
<suiteXmlFiles>
110+
<suiteXmlFile>config/sample-test.testng.xml</suiteXmlFile>
111+
</suiteXmlFiles>
112+
<argLine>
113+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
114+
</argLine>
115+
</configuration>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
</profile>
120+
</profiles>
121+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.browserstack;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.Test;
5+
6+
public class BStackLocalTest extends SeleniumTest {
7+
8+
@Test
9+
public void test() throws Exception {
10+
driver.get("http://bs-local.com:45454/");
11+
12+
Assert.assertTrue(driver.getTitle().contains("BrowserStack Local"));
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.browserstack;
2+
3+
import org.testng.annotations.AfterMethod;
4+
import org.testng.annotations.BeforeMethod;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.chrome.ChromeDriver;
7+
import org.openqa.selenium.chrome.ChromeOptions;
8+
9+
public class SeleniumTest {
10+
public WebDriver driver;
11+
12+
@BeforeMethod(alwaysRun = true)
13+
@SuppressWarnings("unchecked")
14+
public void setUp() throws Exception {
15+
ChromeOptions options = new ChromeOptions();
16+
options.addArguments("start-maximized");
17+
driver = new ChromeDriver(options);
18+
}
19+
20+
@AfterMethod(alwaysRun = true)
21+
public void tearDown() throws Exception {
22+
driver.quit();
23+
}
24+
}

0 commit comments

Comments
 (0)