Skip to content

Commit 8e1aa69

Browse files
agarneha1331francisf
authored andcommitted
Made same as testng
1 parent d3f2953 commit 8e1aa69

6 files changed

Lines changed: 174 additions & 365 deletions

File tree

.gitignore

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

README.md

Lines changed: 82 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,97 @@
1-
# Java-selenium-browserstack
2-
---
1+
# testng-browserstack
32

4-
## Prerequisite
5-
Make sure `maven` is installed in your system. See if it is properly installed.
3+
[TestNG](http://testng.org) Integration with BrowserStack.
64

7-
```
8-
mvn --version
9-
```
5+
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
106

11-
## Steps to run test
7+
## Using Maven
128

13-
In every test file (JavaSample, JavaLocalSample, JavaParallelSample) make sure you set your credentials.
14-
```java
15-
public static final String AUTOMATE_USERNAME = "BROWSERSTACK_USERNAME";
16-
public static final String AUTOMATE_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY";
17-
```
9+
### Run sample build
1810

19-
1. Clone and navigate to the repo.
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`
2016

21-
```
22-
git clone https://github.com/browserstack/java-selenium-browserstack.git
23-
cd java-selenium-browserstack
24-
```
17+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
2518

26-
2. Change capabilities of test.
27-
28-
```java
29-
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
30-
browserstackOptions.put("os", "OS X");
31-
browserstackOptions.put("osVersion", "Sierra");
32-
browserstackOptions.put("local", "false");
33-
browserstackOptions.put("seleniumVersion", "4.0.0");
34-
capabilities.setCapability("bstack:options", browserstackOptions);
35-
capabilities.setCapability("sessionName", "BStack-[Java] Sample Test"); // test name
36-
capabilities.setCapability("buildName", "BStack Build Number 1"); // CI/CD job or build name
37-
```
19+
### Integrate your test suite
3820

39-
## Build and run test using maven.
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:
4022

41-
### Install Dependencies using maven.
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>
4232
```
43-
mvn install
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`.
4434
```
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
4563

46-
### Run tests using maven.
64+
### Run sample build
4765

48-
a. To run single test session.
49-
```
50-
mvn -Dexec.mainClass="com.browserstack.app.JavaSample" -Dexec.classpathScope=test test-compile exec:java
51-
```
66+
- Clone the repository
67+
- Install dependencies `gradle build`
68+
- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`
69+
- To run local tests, run `gradle sampleLocalTest`
5270

53-
b. To run parallel test session.
54-
```
55-
mvn -Dexec.mainClass="com.browserstack.app.JavaParallelSample" -Dexec.classpathScope=test test-compile exec:java
56-
```
71+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
72+
73+
### Integrate your test suite
74+
75+
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:
5776

58-
c. To run local test session.
59-
```
60-
mvn -Dexec.mainClass="com.browserstack.app.JavaLocalSample" -Dexec.classpathScope=test test-compile exec:java
61-
```
77+
* Following are the changes required in `gradle.build` -
78+
* Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies
79+
* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* :
80+
```
81+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
82+
83+
task sampleTest(type: Test) {
84+
useTestNG() {
85+
dependsOn cleanTest
86+
useDefaultListeners = true
87+
suites "config/sample-test.testng.xml"
88+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
89+
}
90+
}
91+
```
92+
93+
* Install dependencies `gradle build`
94+
95+
96+
## Notes
97+
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)

pom.xml

Lines changed: 81 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,117 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
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">
53
<modelVersion>4.0.0</modelVersion>
64

7-
<groupId>com.browserstack.app</groupId>
8-
<artifactId>java-browserstack</artifactId>
5+
<groupId>com.browserstack</groupId>
6+
<artifactId>testng-browserstack</artifactId>
97
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
109

11-
<name>java-browserstack</name>
12-
<!-- FIXME change it to the project's website -->
13-
<url>http://www.browserstack.com</url>
10+
<name>testng-browserstack</name>
11+
<url>https://www.github.com/browserstack/testng-browserstack</url>
1412

1513
<properties>
1614
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1715
<maven.compiler.source>1.8</maven.compiler.source>
1816
<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-local-test.testng.xml</config.file>
1922
</properties>
2023

2124
<dependencies>
2225
<dependency>
23-
<groupId>junit</groupId>
24-
<artifactId>junit</artifactId>
25-
<version>4.11</version>
26-
<scope>test</scope>
27-
</dependency>
28-
<dependency>
29-
<groupId>commons-io</groupId>
30-
<artifactId>commons-io</artifactId>
31-
<version>1.3.2</version>
26+
<groupId>org.testng</groupId>
27+
<artifactId>testng</artifactId>
28+
<version>${testng.version}</version>
3229
</dependency>
3330
<dependency>
3431
<groupId>org.seleniumhq.selenium</groupId>
3532
<artifactId>selenium-java</artifactId>
36-
<version>4.1.0</version>
33+
<version>${selenium.version}</version>
3734
</dependency>
3835
<dependency>
3936
<groupId>com.browserstack</groupId>
40-
<artifactId>browserstack-local-java</artifactId>
41-
<version>1.0.3</version>
42-
</dependency>
43-
<dependency>
44-
<groupId>com.googlecode.json-simple</groupId>
45-
<artifactId>json-simple</artifactId>
46-
<version>1.1.1</version>
37+
<artifactId>browserstack-java-sdk</artifactId>
38+
<version>LATEST</version>
39+
<scope>compile</scope>
4740
</dependency>
4841
</dependencies>
4942

5043
<build>
51-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
52-
<plugins>
53-
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
54-
<plugin>
55-
<artifactId>maven-clean-plugin</artifactId>
56-
<version>3.1.0</version>
57-
</plugin>
58-
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
59-
<plugin>
60-
<artifactId>maven-resources-plugin</artifactId>
61-
<version>3.0.2</version>
62-
</plugin>
63-
<plugin>
64-
<artifactId>maven-compiler-plugin</artifactId>
65-
<version>3.8.0</version>
66-
</plugin>
67-
<plugin>
68-
<artifactId>maven-surefire-plugin</artifactId>
69-
<version>2.22.1</version>
70-
</plugin>
71-
<plugin>
72-
<artifactId>maven-jar-plugin</artifactId>
73-
<version>3.0.2</version>
74-
</plugin>
75-
<plugin>
76-
<artifactId>maven-install-plugin</artifactId>
77-
<version>2.5.2</version>
78-
</plugin>
79-
<plugin>
80-
<artifactId>maven-deploy-plugin</artifactId>
81-
<version>2.8.2</version>
82-
</plugin>
83-
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
84-
<plugin>
85-
<artifactId>maven-site-plugin</artifactId>
86-
<version>3.7.1</version>
87-
</plugin>
88-
<plugin>
89-
<artifactId>maven-project-info-reports-plugin</artifactId>
90-
<version>3.0.0</version>
91-
</plugin>
92-
</plugins>
93-
</pluginManagement>
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>
9478
</build>
79+
9580
<profiles>
9681
<profile>
97-
<id>single</id>
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>
98103
<build>
99104
<plugins>
100105
<plugin>
101106
<groupId>org.apache.maven.plugins</groupId>
102107
<artifactId>maven-surefire-plugin</artifactId>
103108
<configuration>
104-
<includes>
105-
<include>com/browserstack/app/JavaSample.java</include>
106-
</includes>
109+
<suiteXmlFiles>
110+
<suiteXmlFile>config/sample-test.testng.xml</suiteXmlFile>
111+
</suiteXmlFiles>
112+
<argLine>
113+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
114+
</argLine>
107115
</configuration>
108116
</plugin>
109117
</plugins>

0 commit comments

Comments
 (0)