From eddcacbfc2a2cb5236ae4bf8b47db816553d2d25 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 23 Sep 2022 13:35:58 +0530 Subject: [PATCH 01/11] Added source capability --- README.md | 2 +- src/test/resources/conf/local.conf.json | 1 + src/test/resources/conf/parallel.conf.json | 1 + src/test/resources/conf/single.conf.json | 1 + src/test/resources/conf/suite.conf.json | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9638de0..53854b05 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [TestNG](http://testng.org) Integration with BrowserStack. -Master branch contains **Selenium 3** samples, for **Selenium 4 - W3C protocol** please checkout [selenium-4](https://github.com/browserstack/testng-browserstack/tree/selenium-4) branch +Master branch contains **Selenium 4** samples, for **Selenium 3 - JSON Wire Protocol** please checkout [selenium-3](https://github.com/browserstack/testng-browserstack/tree/selenium-3) branch ![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780) diff --git a/src/test/resources/conf/local.conf.json b/src/test/resources/conf/local.conf.json index 27416af1..30580ff0 100644 --- a/src/test/resources/conf/local.conf.json +++ b/src/test/resources/conf/local.conf.json @@ -6,6 +6,7 @@ "capabilities": { "build": "browserstack-build-1", "name": "local_test", + "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true, "browserstack.local": true }, diff --git a/src/test/resources/conf/parallel.conf.json b/src/test/resources/conf/parallel.conf.json index 48bc9c74..b816ad3a 100644 --- a/src/test/resources/conf/parallel.conf.json +++ b/src/test/resources/conf/parallel.conf.json @@ -6,6 +6,7 @@ "capabilities": { "build": "browserstack-build-1", "name": "parallel_test", + "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/src/test/resources/conf/single.conf.json b/src/test/resources/conf/single.conf.json index 3de3fd55..14f6fd51 100644 --- a/src/test/resources/conf/single.conf.json +++ b/src/test/resources/conf/single.conf.json @@ -6,6 +6,7 @@ "capabilities": { "build": "browserstack-build-1", "name": "single_test", + "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/src/test/resources/conf/suite.conf.json b/src/test/resources/conf/suite.conf.json index 7f19ce11..519528f7 100644 --- a/src/test/resources/conf/suite.conf.json +++ b/src/test/resources/conf/suite.conf.json @@ -6,6 +6,7 @@ "capabilities": { "build": "browserstack-build-1", "name": "suite_test", + "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, From f386b89422e04fec0bf57d79f5c1c78225781f53 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 3 Oct 2022 12:18:59 +0530 Subject: [PATCH 02/11] corrected sessionName --- src/test/resources/conf/local.conf.json | 2 +- src/test/resources/conf/parallel.conf.json | 2 +- src/test/resources/conf/single.conf.json | 2 +- src/test/resources/conf/suite.conf.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/resources/conf/local.conf.json b/src/test/resources/conf/local.conf.json index 30580ff0..01f6270e 100644 --- a/src/test/resources/conf/local.conf.json +++ b/src/test/resources/conf/local.conf.json @@ -5,7 +5,7 @@ "capabilities": { "build": "browserstack-build-1", - "name": "local_test", + "name": "BStack local testng", "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true, "browserstack.local": true diff --git a/src/test/resources/conf/parallel.conf.json b/src/test/resources/conf/parallel.conf.json index b816ad3a..2be1b950 100644 --- a/src/test/resources/conf/parallel.conf.json +++ b/src/test/resources/conf/parallel.conf.json @@ -5,7 +5,7 @@ "capabilities": { "build": "browserstack-build-1", - "name": "parallel_test", + "name": "BStack parallel testng", "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/src/test/resources/conf/single.conf.json b/src/test/resources/conf/single.conf.json index 14f6fd51..d296ec34 100644 --- a/src/test/resources/conf/single.conf.json +++ b/src/test/resources/conf/single.conf.json @@ -5,7 +5,7 @@ "capabilities": { "build": "browserstack-build-1", - "name": "single_test", + "name": "BStack single testng", "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/src/test/resources/conf/suite.conf.json b/src/test/resources/conf/suite.conf.json index 519528f7..b011c96a 100644 --- a/src/test/resources/conf/suite.conf.json +++ b/src/test/resources/conf/suite.conf.json @@ -5,7 +5,7 @@ "capabilities": { "build": "browserstack-build-1", - "name": "suite_test", + "name": "BStack suite testng", "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, From 6594f8efacb95dcdaf792c91efc215cc14b33a71 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 3 Oct 2022 22:38:07 +0530 Subject: [PATCH 03/11] Hardcoded source --- src/test/java/com/browserstack/BrowserStackTestNGTest.java | 1 + src/test/resources/conf/local.conf.json | 1 - src/test/resources/conf/parallel.conf.json | 1 - src/test/resources/conf/single.conf.json | 1 - src/test/resources/conf/suite.conf.json | 1 - 5 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/com/browserstack/BrowserStackTestNGTest.java b/src/test/java/com/browserstack/BrowserStackTestNGTest.java index 81682b30..27c74255 100644 --- a/src/test/java/com/browserstack/BrowserStackTestNGTest.java +++ b/src/test/java/com/browserstack/BrowserStackTestNGTest.java @@ -29,6 +29,7 @@ public void setUp(String config_file, String environment) throws Exception { JSONObject envs = (JSONObject) config.get("environments"); DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability("browserstack.source", "testng:sample-selenium-3:v1.0"); Map envCapabilities = (Map) envs.get(environment); Iterator it = envCapabilities.entrySet().iterator(); diff --git a/src/test/resources/conf/local.conf.json b/src/test/resources/conf/local.conf.json index 01f6270e..df1c23e4 100644 --- a/src/test/resources/conf/local.conf.json +++ b/src/test/resources/conf/local.conf.json @@ -6,7 +6,6 @@ "capabilities": { "build": "browserstack-build-1", "name": "BStack local testng", - "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true, "browserstack.local": true }, diff --git a/src/test/resources/conf/parallel.conf.json b/src/test/resources/conf/parallel.conf.json index 2be1b950..622d10e2 100644 --- a/src/test/resources/conf/parallel.conf.json +++ b/src/test/resources/conf/parallel.conf.json @@ -6,7 +6,6 @@ "capabilities": { "build": "browserstack-build-1", "name": "BStack parallel testng", - "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/src/test/resources/conf/single.conf.json b/src/test/resources/conf/single.conf.json index d296ec34..b4c57f80 100644 --- a/src/test/resources/conf/single.conf.json +++ b/src/test/resources/conf/single.conf.json @@ -6,7 +6,6 @@ "capabilities": { "build": "browserstack-build-1", "name": "BStack single testng", - "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/src/test/resources/conf/suite.conf.json b/src/test/resources/conf/suite.conf.json index b011c96a..da7200ef 100644 --- a/src/test/resources/conf/suite.conf.json +++ b/src/test/resources/conf/suite.conf.json @@ -6,7 +6,6 @@ "capabilities": { "build": "browserstack-build-1", "name": "BStack suite testng", - "browserstack.source": "testng:sample-selenium-3-v1.0", "browserstack.debug": true }, From ee00a065a5c4c367597372c7955aae3508797699 Mon Sep 17 00:00:00 2001 From: kamal-kaur04 <38219887+kamal-kaur04@users.noreply.github.com> Date: Tue, 11 Oct 2022 16:00:09 +0530 Subject: [PATCH 04/11] fix gradle build exception compile not found --- .gitignore | 8 ++++++++ build.gradle | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1ef32d1e..767b12c6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,11 @@ local.log .gradle build/ .DS_Store +.classpath +.project +.settings +browserstack.err +gradle +gradlew +gradlew.bat +test-output diff --git a/build.gradle b/build.gradle index bf8cb469..d71c160d 100644 --- a/build.gradle +++ b/build.gradle @@ -5,11 +5,11 @@ plugins { repositories { mavenCentral() } dependencies { - compile 'org.testng:testng:6.9.10' - compile 'commons-io:commons-io:1.3.2' - compile 'org.seleniumhq.selenium:selenium-java:3.12.0' - compile 'com.browserstack:browserstack-local-java:0.1.0' - compile 'com.googlecode.json-simple:json-simple:1.1.1' + implementation 'org.testng:testng:6.9.10' + implementation 'commons-io:commons-io:1.3.2' + implementation 'org.seleniumhq.selenium:selenium-java:3.12.0' + implementation 'com.browserstack:browserstack-local-java:1.0.6' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' } group = 'com.browserstack' From 2bfb8b54cd4ed81e9dd2cae4ebab24d73b6a6403 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Wed, 21 Dec 2022 19:23:23 +0530 Subject: [PATCH 05/11] http->https in hub url --- src/test/java/com/browserstack/BrowserStackTestNGTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/browserstack/BrowserStackTestNGTest.java b/src/test/java/com/browserstack/BrowserStackTestNGTest.java index 27c74255..cd77b364 100644 --- a/src/test/java/com/browserstack/BrowserStackTestNGTest.java +++ b/src/test/java/com/browserstack/BrowserStackTestNGTest.java @@ -66,7 +66,7 @@ public void setUp(String config_file, String environment) throws Exception { } driver = new RemoteWebDriver( - new URL("http://" + username + ":" + accessKey + "@" + config.get("server") + "/wd/hub"), capabilities); + new URL("https://" + username + ":" + accessKey + "@" + config.get("server") + "/wd/hub"), capabilities); } @AfterMethod(alwaysRun = true) From b6250747279a688dcce7301aa102e0645ebf66d1 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Thu, 23 Mar 2023 14:02:29 +0530 Subject: [PATCH 06/11] Made parallel test as default --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 53854b05..bf577889 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,8 @@ Master branch contains **Selenium 4** samples, for **Selenium 3 - JSON Wire Prot ### Running your tests -- To run a single test, run `mvn test -P single` +- To run tests, run `mvn test -P parallel` - To run local tests, run `mvn test -P local` -- To run parallel tests, run `mvn test -P parallel` - To run the test suite, run `mvn test -P suite` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) @@ -34,9 +33,8 @@ Master branch contains **Selenium 4** samples, for **Selenium 3 - JSON Wire Prot ### Running your tests -- To run a single test, run `gradle singleTest` +- To run tests, run `gradle parallelTest` - To run local tests, run `gradle localTest` -- To run parallel tests, run `gradle parallelTest` - To run the test suite, run `gradle suiteTest` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) From 9bd3ffa6acf7ebbe39c3ae88ee885d8e3c0efa7e Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Thu, 23 Mar 2023 19:43:04 +0530 Subject: [PATCH 07/11] Fix for parallel with local --- config/parallel.testng.xml | 4 +- pom.xml | 5 ++ .../browserstack/BrowserStackTestNGTest.java | 66 ++++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/config/parallel.testng.xml b/config/parallel.testng.xml index 24c4721f..c887ae7b 100644 --- a/config/parallel.testng.xml +++ b/config/parallel.testng.xml @@ -1,8 +1,8 @@ + - @@ -10,7 +10,6 @@ - @@ -18,7 +17,6 @@ - diff --git a/pom.xml b/pom.xml index ac200e08..d20dbef8 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,11 @@ org.apache.maven.plugins maven-surefire-plugin 2.18.1 + + + config/parallel.testng.xml + + diff --git a/src/test/java/com/browserstack/BrowserStackTestNGTest.java b/src/test/java/com/browserstack/BrowserStackTestNGTest.java index cd77b364..96bf2c3a 100644 --- a/src/test/java/com/browserstack/BrowserStackTestNGTest.java +++ b/src/test/java/com/browserstack/BrowserStackTestNGTest.java @@ -13,22 +13,54 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.*; public class BrowserStackTestNGTest { public WebDriver driver; private Local l; + private static JSONObject config; + private static Map commonCapabilities; + private static String username; + private static String accessKey; + + @BeforeSuite(alwaysRun=true) + @Parameters(value = { "config" }) + public void beforeSuite(String config_file) throws Exception { + JSONParser parser = new JSONParser(); + config = (JSONObject) parser.parse(new FileReader("src/test/resources/conf/" + config_file)); + commonCapabilities = (Map) config.get("capabilities"); + + username = System.getenv("BROWSERSTACK_USERNAME"); + if (username == null) { + username = (String) config.get("user"); + } + + accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); + if (accessKey == null) { + accessKey = (String) config.get("key"); + } + try { + if ((commonCapabilities.get("browserstack.local") != null && + commonCapabilities.get("browserstack.local").toString().equalsIgnoreCase("true") && (l == null))) { + l = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + l.start(options); + } + } catch (Exception e) { + System.out.println("Error while start local - " + e); + } + } @BeforeMethod(alwaysRun = true) @org.testng.annotations.Parameters(value = { "config", "environment" }) @SuppressWarnings("unchecked") public void setUp(String config_file, String environment) throws Exception { JSONParser parser = new JSONParser(); - JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/conf/" + config_file)); + config = (JSONObject) parser.parse(new FileReader("src/test/resources/conf/" + config_file)); JSONObject envs = (JSONObject) config.get("environments"); - DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability("browserstack.source", "testng:sample-selenium-3:v1.0"); Map envCapabilities = (Map) envs.get(environment); @@ -47,24 +79,6 @@ public void setUp(String config_file, String environment) throws Exception { } } - String username = System.getenv("BROWSERSTACK_USERNAME"); - if (username == null) { - username = (String) config.get("user"); - } - - String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if (accessKey == null) { - accessKey = (String) config.get("key"); - } - - if (capabilities.getCapability("browserstack.local") != null - && capabilities.getCapability("browserstack.local") == "true") { - l = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - l.start(options); - } - driver = new RemoteWebDriver( new URL("https://" + username + ":" + accessKey + "@" + config.get("server") + "/wd/hub"), capabilities); } @@ -72,8 +86,10 @@ public void setUp(String config_file, String environment) throws Exception { @AfterMethod(alwaysRun = true) public void tearDown() throws Exception { driver.quit(); - if (l != null) { - l.stop(); - } + } + + @AfterSuite(alwaysRun = true) + public void afterSuite() throws Exception { + if (l != null) l.stop(); } } From c30b8f890c46129301cc12e3c99ade702412ae9c Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 24 Mar 2023 12:38:31 +0530 Subject: [PATCH 08/11] Fix --- pom.xml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index d20dbef8..003a6b73 100644 --- a/pom.xml +++ b/pom.xml @@ -54,11 +54,6 @@ org.apache.maven.plugins maven-surefire-plugin 2.18.1 - - - config/parallel.testng.xml - - @@ -66,6 +61,9 @@ single + + true + From 5697a9ba2540d0bdf36959afc5f0ff780f55b215 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 24 Mar 2023 12:39:29 +0530 Subject: [PATCH 09/11] Fix --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 003a6b73..4c2308f5 100644 --- a/pom.xml +++ b/pom.xml @@ -61,9 +61,6 @@ single - - true - @@ -98,6 +95,9 @@ parallel + + true + From ace0be5a795947b0e249a0f67ff9f2e1a0dc0cf3 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 27 Mar 2023 12:44:14 +0530 Subject: [PATCH 10/11] Fix --- pom.xml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4c2308f5..d20dbef8 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,11 @@ org.apache.maven.plugins maven-surefire-plugin 2.18.1 + + + config/parallel.testng.xml + + @@ -95,9 +100,6 @@ parallel - - true - From 223619114223962660877c60fbfc740521b172a4 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Tue, 28 Mar 2023 13:05:12 +0530 Subject: [PATCH 11/11] Update source --- src/test/java/com/browserstack/BrowserStackTestNGTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/browserstack/BrowserStackTestNGTest.java b/src/test/java/com/browserstack/BrowserStackTestNGTest.java index 96bf2c3a..235597e0 100644 --- a/src/test/java/com/browserstack/BrowserStackTestNGTest.java +++ b/src/test/java/com/browserstack/BrowserStackTestNGTest.java @@ -61,7 +61,7 @@ public void setUp(String config_file, String environment) throws Exception { JSONObject envs = (JSONObject) config.get("environments"); DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("browserstack.source", "testng:sample-selenium-3:v1.0"); + capabilities.setCapability("browserstack.source", "testng:sample-selenium-3:v1.1"); Map envCapabilities = (Map) envs.get(environment); Iterator it = envCapabilities.entrySet().iterator();