diff --git a/.gitignore b/.gitignore index 4e96e650..c1b446e8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ gradlew gradlew.bat logs browserstack.err +log diff --git a/README.md b/README.md index 5a7e4fee..e38248df 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# testng-browserstack +# now-testng-browserstack [TestNG](http://testng.org) Integration with BrowserStack. @@ -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) @@ -30,7 +29,7 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t compile ``` -* 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`. ``` maven-dependency-plugin @@ -49,7 +48,7 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t 3.0.0-M5 - config/sample-local-test.testng.xml + config/sample-test.testng.xml -javaagent:${com.browserstack:browserstack-java-sdk:jar} @@ -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) @@ -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' } diff --git a/browserstack.yml b/browserstack.yml index 210b867c..1b248a79 100644 --- a/browserstack.yml +++ b/browserstack.yml @@ -1,82 +1,25 @@ -# ============================= -# 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 # (Default false) - -# Options to be passed to BrowserStack local in-case of advanced configurations -# browserStackLocalOptions: - # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. - # forceLocal: true # (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 # # Set to true if you need screenshots for every selenium command ran -networkLogs: false # Set to true to enable HAR logs capturing -consoleLogs: errors # 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: true # patch fix until we get the reason for Caused by: org.openqa.selenium.WebDriverException: [browserstack.local] is set to true but local testing through BrowserStack is not connected. +browserStackLocalOptions: + localIdentifier: 'browserstack-now-local' + force: true +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} diff --git a/build.gradle b/build.gradle index c46b782f..b69a7c9c 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } @@ -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}" - } -} diff --git a/config/sample-local-test.testng.xml b/config/sample-local-test.testng.xml deleted file mode 100644 index 5f776a44..00000000 --- a/config/sample-local-test.testng.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/config/sample-test.testng.xml b/config/sample-test.testng.xml index 0fff5a48..3af55e42 100644 --- a/config/sample-test.testng.xml +++ b/config/sample-test.testng.xml @@ -1,9 +1,9 @@ - + - + diff --git a/pom.xml b/pom.xml index fcef07c1..1c2f64f0 100644 --- a/pom.xml +++ b/pom.xml @@ -12,11 +12,11 @@ UTF-8 - 1.8 - 1.8 - 7.4.0 - 2.19.1 - 4.1.4 + 11 + 11 + 7.11.0 + 3.2.2 + 4.38.0 1.1.1 config/sample-test.testng.xml @@ -78,26 +78,6 @@ - - sample-local-test - - - - org.apache.maven.plugins - maven-surefire-plugin - - - config/sample-local-test.testng.xml - - - -javaagent:${com.browserstack:browserstack-java-sdk:jar} - - - - - - - sample-test diff --git a/src/test/java/com/browserstack/BStackDemoTest.java b/src/test/java/com/browserstack/BStackDemoTest.java deleted file mode 100644 index 8ce65cf8..00000000 --- a/src/test/java/com/browserstack/BStackDemoTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.browserstack; - -import com.browserstack.SeleniumTest; -import org.openqa.selenium.By; -import org.testng.Assert; -import org.testng.annotations.Test; - -public class BStackDemoTest extends SeleniumTest { - @Test - public void addProductToCart() throws Exception { - // navigate to bstackdemo - driver.get("https://www.bstackdemo.com"); - - // Check the title - Assert.assertTrue(driver.getTitle().matches("StackDemo")); - - // Save the text of the product for later verify - String productOnScreenText = driver.findElement(By.xpath("//*[@id=\"1\"]/p")).getText(); - // Click on add to cart button - driver.findElement(By.xpath("//*[@id=\"1\"]/div[4]")).click(); - - // See if the cart is opened or not - Assert.assertTrue(driver.findElement(By.cssSelector(".float\\-cart__content")).isDisplayed()); - - // Check the product inside the cart is same as of the main page - String productOnCartText = driver.findElement(By.xpath("//*[@id=\"__next\"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]")).getText(); - Assert.assertEquals(productOnScreenText, productOnCartText); - } -} diff --git a/src/test/java/com/browserstack/BStackLocalTest.java b/src/test/java/com/browserstack/BStackLocalTest.java deleted file mode 100644 index 4639bd9a..00000000 --- a/src/test/java/com/browserstack/BStackLocalTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.browserstack; - -import org.testng.Assert; -import org.testng.annotations.Test; - -public class BStackLocalTest extends SeleniumTest { - - @Test - public void test() throws Exception { - driver.get("http://bs-local.com:45454/"); - - Assert.assertTrue(driver.getTitle().contains("BrowserStack Local")); - } -} diff --git a/src/test/java/com/browserstack/NOWDemoTest.java b/src/test/java/com/browserstack/NOWDemoTest.java new file mode 100644 index 00000000..c7d1b36b --- /dev/null +++ b/src/test/java/com/browserstack/NOWDemoTest.java @@ -0,0 +1,22 @@ +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; + +public class NOWDemoTest extends SeleniumTest { + @Test + public void openTestPage() throws Exception { + + 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); + } +} diff --git a/src/test/java/com/browserstack/SeleniumTest.java b/src/test/java/com/browserstack/SeleniumTest.java index 0d8d717c..8bd9d4f9 100644 --- a/src/test/java/com/browserstack/SeleniumTest.java +++ b/src/test/java/com/browserstack/SeleniumTest.java @@ -21,4 +21,4 @@ public void setUp() throws Exception { public void tearDown() throws Exception { driver.quit(); } -} +} \ No newline at end of file