Skip to content
Open

Test #133

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/Semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:

container:
# A Docker image with Semgrep installed. Do not change this.
image: returntocorp/semgrep

image: returntocorp/semgrep:1.166.0
# Skip any PR created by dependabot to avoid permission issues:
if: (github.actor != 'dependabot[bot]')

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ gradlew
gradlew.bat
logs
browserstack.err
log
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# testng-browserstack
# now-testng-browserstack

[TestNG](http://testng.org) Integration with BrowserStack.

Expand All @@ -12,7 +12,6 @@
- Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml.
- Install dependencies `mvn compile`
- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test`
- To run local tests, run `mvn test -P sample-local-test`

Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)

Expand All @@ -30,7 +29,7 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t
<scope>compile</scope>
</dependency>
```
* 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`.
* 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`.
```
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
Expand All @@ -49,7 +48,7 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>config/sample-local-test.testng.xml</suiteXmlFile>
<suiteXmlFile>config/sample-test.testng.xml</suiteXmlFile>
</suiteXmlFiles>
<argLine>
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
Expand All @@ -69,7 +68,6 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t
- Clone the repository
- Install dependencies `gradle build`
- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`
- To run local tests, run `gradle sampleLocalTest`

Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)

Expand All @@ -79,7 +77,7 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t

* Following are the changes required in `gradle.build` -
* Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies
* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* :
* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* :
```
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }

Expand Down
102 changes: 21 additions & 81 deletions browserstack.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,22 @@
# =============================
# Set BrowserStack Credentials
# =============================
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and
# BROWSERSTACK_ACCESS_KEY as env variables
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY

# ======================
# BrowserStack Reporting
# ======================
# The following capabilities are used to set up reporting on BrowserStack:
# Set 'projectName' to the name of your project. Example, Marketing Website
projectName: BrowserStack Samples
# Set `buildName` as the name of the job / testsuite being run
buildName: browserstack build
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
# buildName. Choose your buildIdentifier format from the available expressions:
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}
# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng`
# This property is needed to send test context to BrowserStack (test name, status)
userName: $BROWSERSTACK_USERNAME
accessKey: $BROWSERSTACK_ACCESS_KEY
framework: testng

# =======================================
# Platforms (Browsers / Devices to test)
# =======================================
# Platforms object contains all the browser / device combinations you want to test on.
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
platforms:
- os: OS X
osVersion: Big Sur
browserName: Chrome
browserVersion: latest
- os: Windows
osVersion: 10
browserName: Edge
browserVersion: latest
- deviceName: Samsung Galaxy S22 Ultra
browserName: chrome # Try 'samsung' for Samsung browser
osVersion: 12.0

# =======================
# Parallels per Platform
# =======================
# The number of parallel threads to be used for each platform set.
# BrowserStack's SDK runner will select the best strategy based on the configured value
#
# 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
#
# 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
parallelsPerPlatform: 1

source: testng:sample-master:v1.1

# ==========================================
# BrowserStack Local
# (For localhost, staging/private websites)
# ==========================================
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
browserstackLocal: true # <boolean> (Default false)

# Options to be passed to BrowserStack local in-case of advanced configurations
# browserStackLocalOptions:
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections

# ===================
# Debugging features
# ===================
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

# Test Observability is an intelligent test reporting & debugging product. It collects data using the SDK. Read more about what data is collected at https://www.browserstack.com/docs/test-observability/references/terms-and-conditions
# Visit observability.browserstack.com to see your test reports and insights. To disable test observability, specify `testObservability: false` in the key below.
testObservability: true
browserstackLocal: ${BROWSERSTACK_LOCAL_CUSTOM}
buildName: ${BROWSERSTACK_BUILD_NAME}
source: ${BROWSERSTACK_BUILD_NAME}
projectName: ${BROWSERSTACK_PROJECT_NAME}
percy: true
percyCaptureMode: testcase
debug: true
networkLogs: true
consoleLogs: verbose
performance: report
accessibility: true
accessibilityOptions:
wcagVersion: wcag21aaa # Default: wcag21aa
includeIssueType:
bestPractice: true # Default: false
needsReview: true # Default: true
experimental: false # Default: true
advanced: false
parallelsPerPlatform: ${BSTACK_PARALLELS}
18 changes: 3 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ plugins {
repositories { mavenCentral() }

dependencies {
implementation 'org.testng:testng:7.4.0'
implementation 'commons-io:commons-io:1.3.2'
testImplementation 'org.testng:testng:7.7.1'
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
implementation 'com.browserstack:browserstack-local-java:1.0.6'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'
}

group = 'com.browserstack'
version = '1.0-SNAPSHOT'
description = 'testng-browserstack'
sourceCompatibility = '1.8'
description = 'now-testng-browserstack'
sourceCompatibility = '11'

def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }

Expand All @@ -36,12 +33,3 @@ task sampleTest(type: Test) {
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
}
}

task sampleLocalTest(type: Test) {
useTestNG() {
dependsOn cleanTest
useDefaultListeners = true
suites "config/sample-local-test.testng.xml"
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
}
}
10 changes: 0 additions & 10 deletions config/sample-local-test.testng.xml

This file was deleted.

4 changes: 2 additions & 2 deletions config/sample-test.testng.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Cross-Platform">
<test name="BStackDemo">
<test name="NOWDemoTest">
<classes>
<class name="com.browserstack.BStackDemoTest" />
<class name="com.browserstack.NOWDemoTest" />
</classes>
</test>
</suite>
32 changes: 6 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<testng.version>7.4.0</testng.version>
<surefire.version>2.19.1</surefire.version>
<selenium.version>4.1.4</selenium.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<testng.version>7.11.0</testng.version>
<surefire.version>3.2.2</surefire.version>
<selenium.version>4.38.0</selenium.version>
<json-simple.version>1.1.1</json-simple.version>
<config.file>config/sample-test.testng.xml</config.file>
</properties>
Expand All @@ -35,7 +35,7 @@
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-java-sdk</artifactId>
<version>LATEST</version>
<version>1.46.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -78,26 +78,6 @@
</build>

<profiles>
<profile>
<id>sample-local-test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>config/sample-local-test.testng.xml</suiteXmlFile>
</suiteXmlFiles>
<argLine>
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>sample-test</id>
<build>
Expand Down
29 changes: 0 additions & 29 deletions src/test/java/com/browserstack/BStackDemoTest.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/test/java/com/browserstack/BStackLocalTest.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/test/java/com/browserstack/NOWDemoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.browserstack;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.browserstack.SeleniumTest;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.browserstack.v2.utils.BrowserStack;


public class NOWDemoTest extends SeleniumTest {
@Test
public void openTestPage() throws Exception {
BrowserStack.setCustomTag("ID", System.getenv().getOrDefault("BSTACK_NOW_WEB_TEST_ID", "TC-1"));
String content = new String(Files.readAllBytes(Paths.get("browserstack.yml")));
System.out.println(content);

String webEndpointFromEnv = System.getenv().getOrDefault("CX_TEST_URL", "https://bstackdemo.com");
System.out.println("CX_TEST_URL from Env: " + webEndpointFromEnv);
driver.get(webEndpointFromEnv);

Assert.assertTrue(driver.getPageSource().length() > 100);
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/browserstack/SeleniumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public void setUp() throws Exception {
public void tearDown() throws Exception {
driver.quit();
}
}
}