From 34739277819948218be0bb2ca995bf5aa011c38d Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 23 Sep 2022 18:06:18 +0530 Subject: [PATCH 1/9] Added source capability --- junit-4/src/test/resources/conf/local.conf.json | 1 + junit-4/src/test/resources/conf/parallel.conf.json | 1 + junit-4/src/test/resources/conf/single.conf.json | 1 + junit-5/src/test/resources/caps.json | 3 +++ 4 files changed, 6 insertions(+) diff --git a/junit-4/src/test/resources/conf/local.conf.json b/junit-4/src/test/resources/conf/local.conf.json index 4815773..d58b0d3 100644 --- a/junit-4/src/test/resources/conf/local.conf.json +++ b/junit-4/src/test/resources/conf/local.conf.json @@ -5,6 +5,7 @@ "capabilities": { "build": "junit-browserstack", "name": "local_test", + "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true, "browserstack.local": true }, diff --git a/junit-4/src/test/resources/conf/parallel.conf.json b/junit-4/src/test/resources/conf/parallel.conf.json index a465e5c..fd01196 100644 --- a/junit-4/src/test/resources/conf/parallel.conf.json +++ b/junit-4/src/test/resources/conf/parallel.conf.json @@ -5,6 +5,7 @@ "capabilities": { "build": "junit-browserstack", "name": "parallel_test", + "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true }, "environments": [ diff --git a/junit-4/src/test/resources/conf/single.conf.json b/junit-4/src/test/resources/conf/single.conf.json index 1b7e6f2..f6738b0 100644 --- a/junit-4/src/test/resources/conf/single.conf.json +++ b/junit-4/src/test/resources/conf/single.conf.json @@ -5,6 +5,7 @@ "capabilities": { "build": "junit-browserstack", "name": "single_test", + "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true }, "environments": [ diff --git a/junit-5/src/test/resources/caps.json b/junit-5/src/test/resources/caps.json index a2a8e79..6b4a042 100644 --- a/junit-5/src/test/resources/caps.json +++ b/junit-5/src/test/resources/caps.json @@ -7,6 +7,7 @@ "common_caps": { "name": "single-test", "build": "junit5-browserstack", + "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.networkLogs": "true", "browserstack.debug": "true" @@ -24,6 +25,7 @@ "common_caps": { "name": "local-test", "build": "junit5-browserstack", + "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.local": "true", "browserstack.debug": "true" @@ -41,6 +43,7 @@ "common_caps": { "name": "parallel-test", "build": "junit5-browserstack", + "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.debug": "true" }, From 3d33c049d23d88d224b825529b49df81b57425f7 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 3 Oct 2022 12:44:04 +0530 Subject: [PATCH 2/9] corrected sessionName --- junit-4/src/test/resources/conf/local.conf.json | 4 ++-- junit-4/src/test/resources/conf/parallel.conf.json | 4 ++-- junit-4/src/test/resources/conf/single.conf.json | 4 ++-- junit-5/src/test/resources/caps.json | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/junit-4/src/test/resources/conf/local.conf.json b/junit-4/src/test/resources/conf/local.conf.json index d58b0d3..abdb660 100644 --- a/junit-4/src/test/resources/conf/local.conf.json +++ b/junit-4/src/test/resources/conf/local.conf.json @@ -3,8 +3,8 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "build": "junit-browserstack", - "name": "local_test", + "build": "browserstack-build-1", + "name": "BStack local junit-4", "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true, "browserstack.local": true diff --git a/junit-4/src/test/resources/conf/parallel.conf.json b/junit-4/src/test/resources/conf/parallel.conf.json index fd01196..b768cb9 100644 --- a/junit-4/src/test/resources/conf/parallel.conf.json +++ b/junit-4/src/test/resources/conf/parallel.conf.json @@ -3,8 +3,8 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "build": "junit-browserstack", - "name": "parallel_test", + "build": "browserstack-build-1", + "name": "BStack parallel junit-4", "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/junit-4/src/test/resources/conf/single.conf.json b/junit-4/src/test/resources/conf/single.conf.json index f6738b0..1c3d177 100644 --- a/junit-4/src/test/resources/conf/single.conf.json +++ b/junit-4/src/test/resources/conf/single.conf.json @@ -3,8 +3,8 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "build": "junit-browserstack", - "name": "single_test", + "build": "browserstack-build-1", + "name": "BStack single junit-4", "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true }, diff --git a/junit-5/src/test/resources/caps.json b/junit-5/src/test/resources/caps.json index 6b4a042..4591849 100644 --- a/junit-5/src/test/resources/caps.json +++ b/junit-5/src/test/resources/caps.json @@ -5,8 +5,8 @@ "tests": { "single": { "common_caps": { - "name": "single-test", - "build": "junit5-browserstack", + "name": "BStack single junit-5", + "build": "browserstack-build-1", "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.networkLogs": "true", @@ -23,8 +23,8 @@ }, "local": { "common_caps": { - "name": "local-test", - "build": "junit5-browserstack", + "name": "BStack local junit-5", + "build": "browserstack-build-1", "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.local": "true", @@ -41,8 +41,8 @@ }, "parallel": { "common_caps": { - "name": "parallel-test", - "build": "junit5-browserstack", + "name": "BStack parallel junit-5", + "build": "browserstack-build-1", "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.debug": "true" From ddf6afa545396662b868f82a9ac755daf8d7bae4 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 3 Oct 2022 20:40:03 +0530 Subject: [PATCH 3/9] Hardcoded source --- .../src/test/java/com/browserstack/BrowserStackJUnitTest.java | 2 +- junit-4/src/test/resources/conf/local.conf.json | 1 - junit-4/src/test/resources/conf/parallel.conf.json | 1 - junit-4/src/test/resources/conf/single.conf.json | 1 - junit-5/src/test/java/runners/BstackRunner.java | 1 + junit-5/src/test/resources/caps.json | 3 --- 6 files changed, 2 insertions(+), 7 deletions(-) diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 3bc83ea..83b28ca 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -70,7 +70,7 @@ public void setUp() throws Exception { JSONArray envs = (JSONArray) config.get("environments"); DesiredCapabilities capabilities = new DesiredCapabilities(); - + capabilities.setCapability("browserstack.source", "junit-4:sample-selenium-3:v1.0"); Map envCapabilities = (Map) envs.get(taskID); Iterator it = envCapabilities.entrySet().iterator(); while (it.hasNext()) { diff --git a/junit-4/src/test/resources/conf/local.conf.json b/junit-4/src/test/resources/conf/local.conf.json index abdb660..860cea1 100644 --- a/junit-4/src/test/resources/conf/local.conf.json +++ b/junit-4/src/test/resources/conf/local.conf.json @@ -5,7 +5,6 @@ "capabilities": { "build": "browserstack-build-1", "name": "BStack local junit-4", - "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true, "browserstack.local": true }, diff --git a/junit-4/src/test/resources/conf/parallel.conf.json b/junit-4/src/test/resources/conf/parallel.conf.json index b768cb9..11f92e5 100644 --- a/junit-4/src/test/resources/conf/parallel.conf.json +++ b/junit-4/src/test/resources/conf/parallel.conf.json @@ -5,7 +5,6 @@ "capabilities": { "build": "browserstack-build-1", "name": "BStack parallel junit-4", - "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true }, "environments": [ diff --git a/junit-4/src/test/resources/conf/single.conf.json b/junit-4/src/test/resources/conf/single.conf.json index 1c3d177..84c8db9 100644 --- a/junit-4/src/test/resources/conf/single.conf.json +++ b/junit-4/src/test/resources/conf/single.conf.json @@ -5,7 +5,6 @@ "capabilities": { "build": "browserstack-build-1", "name": "BStack single junit-4", - "browserstack.source": "junit-4-sample-selenium-3-v1.0", "browserstack.debug": true }, "environments": [ diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index afbd65d..708d1b2 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -77,6 +77,7 @@ public Stream provideTestTemplateInvocationContex while (platformIterator.hasNext()) { capabilities = new DesiredCapabilities(); + capabilities.setCapability("browserstack.source", "junit-5:sample-selenium-3:v1.0"); Iterator commonCapsIterator = commonCapsMap.entrySet().iterator(); while (commonCapsIterator.hasNext()) { Map.Entry capsName = (Map.Entry) commonCapsIterator.next(); diff --git a/junit-5/src/test/resources/caps.json b/junit-5/src/test/resources/caps.json index 4591849..e74d051 100644 --- a/junit-5/src/test/resources/caps.json +++ b/junit-5/src/test/resources/caps.json @@ -7,7 +7,6 @@ "common_caps": { "name": "BStack single junit-5", "build": "browserstack-build-1", - "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.networkLogs": "true", "browserstack.debug": "true" @@ -25,7 +24,6 @@ "common_caps": { "name": "BStack local junit-5", "build": "browserstack-build-1", - "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.local": "true", "browserstack.debug": "true" @@ -43,7 +41,6 @@ "common_caps": { "name": "BStack parallel junit-5", "build": "browserstack-build-1", - "browserstack.source": "junit-5-sample-selenium-3-v1.0", "browserstack.console": "verbose", "browserstack.debug": "true" }, From 1b84573d5384db2c8a726311baf8177ec5433b8c Mon Sep 17 00:00:00 2001 From: kamal-kaur04 <38219887+kamal-kaur04@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:13:45 +0530 Subject: [PATCH 4/9] remove automate plugin and fix selector failing on iPhone --- junit-4/pom.xml | 28 ++----------------- .../java/com/browserstack/SingleTest.java | 2 +- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/junit-4/pom.xml b/junit-4/pom.xml index 8b31b9c..faf37db 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -17,8 +17,8 @@ default - 1.6 - 1.6 + 1.8 + 1.8 @@ -47,11 +47,6 @@ json-simple 1.1.1 - - com.browserstack - automate-testassist - 1.0.0 - @@ -60,24 +55,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.12.4 - - - com.browserstack - automate-maven-plugin - 1.0.0 - - 1.8 - 1.8 - 1.8 - - - - - test-compile - - - + 2.19.1 diff --git a/junit-4/src/test/java/com/browserstack/SingleTest.java b/junit-4/src/test/java/com/browserstack/SingleTest.java index 77a854f..e1e09a3 100644 --- a/junit-4/src/test/java/com/browserstack/SingleTest.java +++ b/junit-4/src/test/java/com/browserstack/SingleTest.java @@ -25,7 +25,7 @@ public void test() throws URISyntaxException, IOException { String product_name = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='1']/p"))).getText(); WebElement cart_btn = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='1']/div[4]"))); cart_btn.click(); - wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("float-cart__content"))); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".float\\-cart__content"))); final String product_in_cart = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='__next']/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]"))).getText(); assertTrue(product_name.matches(product_in_cart)); mark(sessionId, "passed", "Product has been successfully added to the cart!"); From 00697f1690ba11562c64e6582d67930257a60b29 Mon Sep 17 00:00:00 2001 From: kamal-kaur04 <38219887+kamal-kaur04@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:51:17 +0530 Subject: [PATCH 5/9] reduce the number of environments in junit-4,5 --- junit-5/src/test/java/tests/SingleTest.java | 2 +- junit-5/src/test/resources/caps.json | 28 --------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/junit-5/src/test/java/tests/SingleTest.java b/junit-5/src/test/java/tests/SingleTest.java index 14de8bf..9b30f74 100644 --- a/junit-5/src/test/java/tests/SingleTest.java +++ b/junit-5/src/test/java/tests/SingleTest.java @@ -24,7 +24,7 @@ void singleTest(WebDriver driver) { String product_name = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='1']/p"))).getText(); WebElement cart_btn = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='1']/div[4]"))); cart_btn.click(); - wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("float-cart__content"))); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".float\\-cart__content"))); final String product_in_cart = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='__next']/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]"))).getText(); if (product_name.equals(product_in_cart)) { sessionStatus.markTestStatus("passed", "Product has been successfully added to the cart!"); diff --git a/junit-5/src/test/resources/caps.json b/junit-5/src/test/resources/caps.json index e74d051..98de82a 100644 --- a/junit-5/src/test/resources/caps.json +++ b/junit-5/src/test/resources/caps.json @@ -51,43 +51,15 @@ "os": "Windows", "os_version": "10" }, - "safari": { - "browser": "safari", - "browser_version": "latest", - "os": "OS X", - "os_version": "Big Sur" - }, - "firefox": { - "browser": "firefox", - "browser_version": "latest-2", - "os": "OS X", - "os_version": "Monterey" - }, "edge": { "browser": "edge", "browser_version": "latest", "os": "Windows", "os_version": "11" }, - "android": { - "device": "Samsung Galaxy S21", - "os_version": "11.0" - }, "ios": { "device": "iPhone 12 Mini", "os_version": "14" - }, - "tab": { - "device": "Samsung Galaxy Tab S7" - }, - "ipad": { - "device": "iPad Mini 2019" - }, - "xiaomi": { - "device": "Xiaomi Redmi Note 9" - }, - "oneplus": { - "device": "OnePlus 9" } } } From 72d14a06e25821bd0611971ffb3dea68d42823c8 Mon Sep 17 00:00:00 2001 From: kamal-kaur04 <38219887+kamal-kaur04@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:54:19 +0530 Subject: [PATCH 6/9] reduce the number of environments in junit-4 --- junit-4/src/test/resources/conf/parallel.conf.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/junit-4/src/test/resources/conf/parallel.conf.json b/junit-4/src/test/resources/conf/parallel.conf.json index 11f92e5..c05c1aa 100644 --- a/junit-4/src/test/resources/conf/parallel.conf.json +++ b/junit-4/src/test/resources/conf/parallel.conf.json @@ -11,19 +11,10 @@ { "browser": "chrome" }, - { - "browser": "firefox" - }, { "browser": "safari", "os": "OS X" }, - { - "browser": "Internet Explorer" - }, - { - "device": "Samsung Galaxy S21" - }, { "device": "iPhone 12" } From df59d3ff297e03fc3622003d6947daf7d1430f21 Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Wed, 9 Nov 2022 20:51:40 +0530 Subject: [PATCH 7/9] add individual config file for each profile as junit 4 --- .../browserstack/BrowserStackJUnitTest.java | 1 - junit-5/pom.xml | 6 +- .../src/test/java/runners/BstackRunner.java | 49 ++++++-------- junit-5/src/test/resources/caps.json | 67 ------------------- .../src/test/resources/conf/local.conf.json | 16 +++++ .../test/resources/conf/parallel.conf.json | 22 ++++++ .../src/test/resources/conf/single.conf.json | 15 +++++ 7 files changed, 75 insertions(+), 101 deletions(-) delete mode 100644 junit-5/src/test/resources/caps.json create mode 100644 junit-5/src/test/resources/conf/local.conf.json create mode 100644 junit-5/src/test/resources/conf/parallel.conf.json create mode 100644 junit-5/src/test/resources/conf/single.conf.json diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 83b28ca..946e48f 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -21,7 +21,6 @@ import java.io.FileReader; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 5ff7725..2d4dbbc 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -73,7 +73,7 @@ ${tests.single} - single + single.conf.json false @@ -94,7 +94,7 @@ ${tests.local} - local + local.conf.json false @@ -115,7 +115,7 @@ ${tests.single} - parallel + parallel.conf.json diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index 708d1b2..d731e0c 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -1,5 +1,6 @@ package runners; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.junit.jupiter.api.extension.*; @@ -16,16 +17,10 @@ public class BstackRunner implements TestTemplateInvocationContextProvider { public WebDriver driver; - public DesiredCapabilities capabilities; public String username, accesskey, server; private JSONObject mainConfig; - private JSONObject browserConfig; - private JSONObject profileConfig; - private JSONObject testConfig; - private JSONObject platformConfig; - private JSONObject commonCapsConfig; - private HashMap allCapsMap; - private HashMap commonCapsMap; + private JSONArray platformConfig; + private HashMap commonCapsConfig; public BstackRunner() { this.username = setupCredsAndServer().get("username"); @@ -35,8 +30,10 @@ public BstackRunner() { public HashMap setupCredsAndServer() { try { - JSONParser parse = new JSONParser(); - mainConfig = (JSONObject) parse.parse(new FileReader("src/test/resources/caps.json")); + if (System.getProperty("config") != null) { + JSONParser parser = new JSONParser(); + mainConfig = (JSONObject) parser.parse(new FileReader("src/test/resources/conf/" + System.getProperty("config"))); + } server = (String) mainConfig.get("server"); username = System.getenv("BROWSERSTACK_USERNAME"); if (username == null) { @@ -47,9 +44,9 @@ public HashMap setupCredsAndServer() { accesskey = (String) mainConfig.get("key"); } } catch (Exception e) { - System.out.println(e.getMessage()); + e.printStackTrace(); } - HashMap creds = new HashMap(); + HashMap creds = new HashMap<>(); creds.put("username", username); creds.put("accesskey", accesskey); creds.put("server", server); @@ -64,31 +61,23 @@ public boolean supportsTestTemplate(ExtensionContext extensionContext) { @Override public Stream provideTestTemplateInvocationContexts(ExtensionContext extensionContext) { List desiredCapsInvocationContexts = new ArrayList<>(); - //picks the test profile based on the maven command executed - single, local, parallel - String profile = System.getProperty("config"); try { - testConfig = (JSONObject) mainConfig.get("tests"); - profileConfig = (JSONObject) testConfig.get(profile); - platformConfig = (JSONObject) profileConfig.get("platform"); - commonCapsConfig = (JSONObject) profileConfig.get("common_caps"); - commonCapsMap = (HashMap) commonCapsConfig; - Iterator platformIterator = platformConfig.keySet().iterator(); + platformConfig = (JSONArray) mainConfig.get("environments"); + commonCapsConfig = (HashMap) mainConfig.get("capabilities"); - while (platformIterator.hasNext()) { - capabilities = new DesiredCapabilities(); + for (Object platform : platformConfig) { + DesiredCapabilities capabilities = new DesiredCapabilities(); + Map envCapabilities = (Map) platform; capabilities.setCapability("browserstack.source", "junit-5:sample-selenium-3:v1.0"); - Iterator commonCapsIterator = commonCapsMap.entrySet().iterator(); + Iterator commonCapsIterator = commonCapsConfig.entrySet().iterator(); while (commonCapsIterator.hasNext()) { Map.Entry capsName = (Map.Entry) commonCapsIterator.next(); capabilities.setCapability((String) capsName.getKey(), capsName.getValue()); } - final String platformName = (String) platformIterator.next(); - browserConfig = (JSONObject) platformConfig.get(platformName); - allCapsMap = (HashMap) browserConfig; - Iterator finalCapsIterator = allCapsMap.entrySet().iterator(); - while (finalCapsIterator.hasNext()) { - Map.Entry pair = (Map.Entry) finalCapsIterator.next(); + Iterator envCapsIterator = envCapabilities.entrySet().iterator(); + while (envCapsIterator.hasNext()) { + Map.Entry pair = (Map.Entry) envCapsIterator.next(); capabilities.setCapability((String) pair.getKey(), pair.getValue()); } //Initializing local testing connection @@ -102,7 +91,7 @@ public Stream provideTestTemplateInvocationContex } } catch (Exception e) { - System.out.println(e); + e.printStackTrace(); } return desiredCapsInvocationContexts.stream(); } diff --git a/junit-5/src/test/resources/caps.json b/junit-5/src/test/resources/caps.json deleted file mode 100644 index 98de82a..0000000 --- a/junit-5/src/test/resources/caps.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "server": "hub.browserstack.com", - "user": "BROWSERSTACK_USERNAME", - "key": "BROWSERSTACK_ACCESS_KEY", - "tests": { - "single": { - "common_caps": { - "name": "BStack single junit-5", - "build": "browserstack-build-1", - "browserstack.console": "verbose", - "browserstack.networkLogs": "true", - "browserstack.debug": "true" - }, - "platform": { - "chrome": { - "browser": "chrome", - "browser_version": "latest", - "os": "Windows", - "os_version": "10" - } - } - }, - "local": { - "common_caps": { - "name": "BStack local junit-5", - "build": "browserstack-build-1", - "browserstack.console": "verbose", - "browserstack.local": "true", - "browserstack.debug": "true" - }, - "platform": { - "chrome": { - "browser": "chrome", - "browser_version": "latest", - "os": "Windows", - "os_version": "10" - } - } - }, - "parallel": { - "common_caps": { - "name": "BStack parallel junit-5", - "build": "browserstack-build-1", - "browserstack.console": "verbose", - "browserstack.debug": "true" - }, - "platform": { - "chrome": { - "browser": "chrome", - "browser_version": "latest-1", - "os": "Windows", - "os_version": "10" - }, - "edge": { - "browser": "edge", - "browser_version": "latest", - "os": "Windows", - "os_version": "11" - }, - "ios": { - "device": "iPhone 12 Mini", - "os_version": "14" - } - } - } - } -} diff --git a/junit-5/src/test/resources/conf/local.conf.json b/junit-5/src/test/resources/conf/local.conf.json new file mode 100644 index 0000000..edafdb0 --- /dev/null +++ b/junit-5/src/test/resources/conf/local.conf.json @@ -0,0 +1,16 @@ +{ + "server": "hub.browserstack.com", + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "build": "browserstack-build-1", + "name": "BStack local junit-5", + "browserstack.debug": true, + "browserstack.local": true + }, + "environments": [ + { + "browser": "chrome" + } + ] +} diff --git a/junit-5/src/test/resources/conf/parallel.conf.json b/junit-5/src/test/resources/conf/parallel.conf.json new file mode 100644 index 0000000..36ce3ff --- /dev/null +++ b/junit-5/src/test/resources/conf/parallel.conf.json @@ -0,0 +1,22 @@ +{ + "server": "hub.browserstack.com", + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "build": "browserstack-build-1", + "name": "BStack parallel junit-5", + "browserstack.debug": true + }, + "environments": [ + { + "browser": "chrome" + }, + { + "browser": "safari", + "os": "OS X" + }, + { + "device": "iPhone 12" + } + ] +} diff --git a/junit-5/src/test/resources/conf/single.conf.json b/junit-5/src/test/resources/conf/single.conf.json new file mode 100644 index 0000000..9b5a3fd --- /dev/null +++ b/junit-5/src/test/resources/conf/single.conf.json @@ -0,0 +1,15 @@ +{ + "server": "hub.browserstack.com", + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "build": "browserstack-build-1", + "name": "BStack single junit-5", + "browserstack.debug": true + }, + "environments": [ + { + "browser": "chrome" + } + ] +} From f658867006cff029c7be38e8f3778c76197c2348 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 24 Mar 2023 17:24:55 +0530 Subject: [PATCH 8/9] Made parallel test as default --- junit-4/README.md | 3 +-- junit-4/pom.xml | 3 +++ .../browserstack/BrowserStackJUnitTest.java | 26 ++++++++++++++----- junit-5/README.md | 3 +-- junit-5/pom.xml | 3 +++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/junit-4/README.md b/junit-4/README.md index 30e5cc1..d4ad85d 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -15,9 +15,8 @@ Master branch contains **Selenium 3** samples, for **Selenium 4 - W3C protocol** * Update *.conf.json files inside the `src/test/resources/conf` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). ## 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` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) diff --git a/junit-4/pom.xml b/junit-4/pom.xml index faf37db..c533cd2 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -116,6 +116,9 @@ parallel + + true + diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 946e48f..5c229a6 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -31,6 +31,8 @@ public class BrowserStackJUnitTest { public static String username, accessKey; private static JSONObject config; public WebDriver driver; + private static Object lock = new Object(); + private static Integer parallels = 0; @Parameter(value = 0) public int taskID; private Local l; @@ -96,11 +98,18 @@ public void setUp() throws Exception { 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); + synchronized (lock) { + parallels++; + if ((l == null || !l.isRunning()) && capabilities.getCapability("browserstack.local") != null && capabilities.getCapability("browserstack.local") == "true") { + l = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + try { + l.start(options); + } catch (Exception e){ + e.printStackTrace(); + } + } } driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + config.get("server") + "/wd/hub"), capabilities); @@ -108,7 +117,10 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { - driver.quit(); - if (l != null) l.stop(); + synchronized (lock){ + parallels--; + driver.quit(); + if (l != null && parallels == 0) l.stop(); + } } } diff --git a/junit-5/README.md b/junit-5/README.md index 2616273..1f8a5a5 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -17,9 +17,8 @@ Master branch contains **Selenium 3** samples, for **Selenium 4 - W3C protocol** junit.jupiter.execution.parallel.config.fixed.parallelism=${parallel.count} ``` ## 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` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 2d4dbbc..b9baef7 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -104,6 +104,9 @@ parallel + + true + From b32f5d3414f67eedc6e1f60af4f285b88c824a1a Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Tue, 28 Mar 2023 12:18:06 +0530 Subject: [PATCH 9/9] Update source --- junit-4/pom.xml | 11 +++++++--- .../browserstack/BrowserStackJUnitTest.java | 2 +- junit-5/pom.xml | 20 ++++++++++++++++--- .../src/test/java/runners/BstackRunner.java | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/junit-4/pom.xml b/junit-4/pom.xml index c533cd2..3a05ecd 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -56,6 +56,14 @@ org.apache.maven.plugins maven-surefire-plugin 2.19.1 + + + com/browserstack/SingleTest.java + + + parallel.conf.json + + @@ -116,9 +124,6 @@ parallel - - true - diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 5c229a6..38f668e 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -71,7 +71,7 @@ public void setUp() throws Exception { JSONArray envs = (JSONArray) config.get("environments"); DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("browserstack.source", "junit-4:sample-selenium-3:v1.0"); + capabilities.setCapability("browserstack.source", "junit-4:sample-selenium-3:v1.1"); Map envCapabilities = (Map) envs.get(taskID); Iterator it = envCapabilities.entrySet().iterator(); while (it.hasNext()) { diff --git a/junit-5/pom.xml b/junit-5/pom.xml index b9baef7..d2e2181 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -47,6 +47,23 @@ maven-surefire-plugin ${maven-surefire-plugin} maven-plugin + + + ${tests.single} + + + parallel.conf.json + + + + junit.jupiter.execution.parallel.enabled = true + junit.jupiter.execution.parallel.mode.default = concurrent + junit.jupiter.execution.parallel.config.strategy=fixed + junit.jupiter.execution.parallel.config.fixed.parallelism=${parallel.count} + + + false + com.browserstack @@ -104,9 +121,6 @@ parallel - - true - diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index d731e0c..7c62947 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -69,7 +69,7 @@ public Stream provideTestTemplateInvocationContex for (Object platform : platformConfig) { DesiredCapabilities capabilities = new DesiredCapabilities(); Map envCapabilities = (Map) platform; - capabilities.setCapability("browserstack.source", "junit-5:sample-selenium-3:v1.0"); + capabilities.setCapability("browserstack.source", "junit-5:sample-selenium-3:v1.1"); Iterator commonCapsIterator = commonCapsConfig.entrySet().iterator(); while (commonCapsIterator.hasNext()) { Map.Entry capsName = (Map.Entry) commonCapsIterator.next();