From 4b92c4175ef7ada3daa7a69fbcf29299a69643bc Mon Sep 17 00:00:00 2001 From: Karan Shah <64479353+karanshah-browserstack@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:32:10 +0530 Subject: [PATCH 01/50] Use Vanilla SDK for Junit Tests --- .gitignore | 3 +- junit-4/browserstack.yml | 60 ++++++++ junit-4/pom.xml | 74 ++++------ .../browserstack/BrowserStackJUnitTest.java | 138 ++++++------------ .../test/java/com/browserstack/LocalTest.java | 7 +- .../java/com/browserstack/SingleTest.java | 10 +- .../src/test/resources/conf/local.conf.json | 25 ---- .../test/resources/conf/parallel.conf.json | 48 ------ .../src/test/resources/conf/single.conf.json | 24 --- junit-5/browserstack.yml | 60 ++++++++ junit-5/pom.xml | 54 +++++-- .../src/test/java/runners/BstackRunner.java | 133 ++++++----------- junit-5/src/test/java/tests/LocalTest.java | 5 +- junit-5/src/test/java/tests/SingleTest.java | 12 +- .../test/java/utils/MarkSessionStatus.java | 39 ++--- .../test/java/utils/SetupLocalTesting.java | 53 ------- junit-5/src/test/resources/caps.json | 128 ---------------- 17 files changed, 298 insertions(+), 575 deletions(-) create mode 100644 junit-4/browserstack.yml delete mode 100644 junit-4/src/test/resources/conf/local.conf.json delete mode 100644 junit-4/src/test/resources/conf/parallel.conf.json delete mode 100644 junit-4/src/test/resources/conf/single.conf.json create mode 100644 junit-5/browserstack.yml delete mode 100644 junit-5/src/test/java/utils/SetupLocalTesting.java delete mode 100644 junit-5/src/test/resources/caps.json diff --git a/.gitignore b/.gitignore index 4274f56..c3103ae 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ browserstack.err *.iml local.log *.png -*.txt \ No newline at end of file +*.txt +**/logs \ No newline at end of file diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml new file mode 100644 index 0000000..9c7f077 --- /dev/null +++ b/junit-4/browserstack.yml @@ -0,0 +1,60 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: BROWSERSTACK_USERNAME +accessKey: BROWSERSTACK_ACCESS_KEY + +# ====================== +# Organizing your tests +# ====================== +# Use `projectName`, `buildName`, `name` capabilities to organise your tests +# `name` is the name of your test sessions and is automatically picked from your +# test name and doesn't need to be set manually when using BrowserStack SDK +# `buildName` is used to name your CI/CD job or the execution of your test suite. +# Ensure you add a dynamic identifier, like an incremental build number from your +# CI/CD or timestamp at the end of every build; otherwise tests from different +# executions will be grouped together on BrowserStack +buildName: browserstack-build-1 +# Use `projectName` to set the name of your project. Example, Marketing Website +projectName: BrowserStack Samples + +# ======================================= +# 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 + - device: Samsung Galaxy S22 Ultra + browserName: chrome # Try 'samsung' for Samsung browser + osVersion: 12.0 + +# ========================================== +# 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) + # browserStackLocalOptions: + # Options to be passed to BrowserStack local in-case of advanced configurations + # - 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) \ No newline at end of file diff --git a/junit-4/pom.xml b/junit-4/pom.xml index c8cba99..7ab6f3e 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -13,19 +13,20 @@ UTF-8 2.19.1 + 1.30 default - 1.6 - 1.6 + 1.8 + 1.8 junit junit - 4.13 + 4.13.1 commons-io @@ -35,39 +36,50 @@ org.seleniumhq.selenium selenium-java - 4.0.0 + 4.1.0 - com.browserstack - browserstack-local-java - 1.0.6 - - - com.googlecode.json-simple - json-simple - 1.1.1 + org.yaml + snakeyaml + ${snakeyml.version} - org.apache.httpcomponents - httpclient - 4.5.13 - test + com.browserstack + browserstack-java-sdk + LATEST + compile + + maven-dependency-plugin + + + getClasspathFilenames + + properties + + + + org.apache.maven.plugins maven-surefire-plugin - 2.12.4 + ${surefire.version} + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + - single + sample @@ -77,9 +89,6 @@ com/browserstack/SingleTest.java - - single.conf.json - @@ -97,29 +106,6 @@ com/browserstack/LocalTest.java - - local.conf.json - - - - - - - - - parallel - - - - org.apache.maven.plugins - maven-surefire-plugin - - - com/browserstack/SingleTest.java - - - parallel.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 00c12f8..3d3469c 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -1,51 +1,42 @@ package com.browserstack; -import com.browserstack.local.Local; -import org.apache.http.NameValuePair; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.message.BasicNameValuePair; -import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.remote.SessionId; +import org.yaml.snakeyaml.Yaml; -import java.io.FileReader; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; +import java.io.File; +import java.io.InputStream; import java.net.URL; +import java.nio.file.Files; import java.util.*; @RunWith(Parallelized.class) public class BrowserStackJUnitTest { public static String username, accessKey; - private static JSONObject config; + private static Map browserstackYamlMap; public WebDriver driver; - public HashMap bstackOptions; @Parameter(value = 0) public int taskID; - private Local bsLocal; + public static final String USER_DIR = "user.dir"; @Parameters - public static Iterable data() throws Exception { + public static Iterable data() { List taskIDs = new ArrayList(); - - if (System.getProperty("config") != null) { - JSONParser parser = new JSONParser(); - config = (JSONObject) parser - .parse(new FileReader("src/test/resources/conf/" + System.getProperty("config"))); - int envs = ((JSONArray) config.get("environments")).size(); - + if (browserstackYamlMap == null) { + File file = new File(getUserDir() + "/browserstack.yml"); + browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); + } + if (browserstackYamlMap != null) { + ArrayList> browserStackPlatforms = (ArrayList>) browserstackYamlMap.get("platforms"); + int envs = browserStackPlatforms.size(); for (int i = 0; i < envs; i++) { taskIDs.add(i); } @@ -53,86 +44,47 @@ public static Iterable data() throws Exception { return taskIDs; } - public static void mark(SessionId sessionID, String status, String reason) throws URISyntaxException, IOException { - URI uri = new URI("https://" + username + ":" + accessKey + "@api.browserstack.com/automate/sessions/" + sessionID + ".json"); - HttpPut putRequest = new HttpPut(uri); - - ArrayList nameValuePairs = new ArrayList(); - nameValuePairs.add((new BasicNameValuePair("status", status))); - nameValuePairs.add((new BasicNameValuePair("reason", reason))); - putRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs)); - - HttpClientBuilder.create().build().execute(putRequest); + public static void mark(WebDriver remoteDriver, String status, String reason) { + final JavascriptExecutor jse = (JavascriptExecutor) remoteDriver; + JSONObject executorObject = new JSONObject(); + JSONObject argumentsObject = new JSONObject(); + argumentsObject.put("status", status); + argumentsObject.put("reason", reason); + executorObject.put("action", "setSessionStatus"); + executorObject.put("arguments", argumentsObject); + jse.executeScript(String.format("browserstack_executor: %s", executorObject)); } @Before - @SuppressWarnings("unchecked") public void setUp() throws Exception { - JSONArray envs = (JSONArray) config.get("environments"); - bstackOptions = new HashMap(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - Map envCapabilities = (Map) envs.get(taskID); - Iterator> it = envCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = it.next(); - if ("bstack:options".equals(pair.getKey())) { - bstackOptions.putAll((Map) pair.getValue()); - } else { - capabilities.setCapability(pair.getKey(), pair.getValue()); - } - } - - Map commonCapabilities = (Map) config.get("capabilities"); - it = commonCapabilities.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = it.next(); - if ("bstack:options".equals(pair.getKey())) { - bstackOptions.putAll((Map) pair.getValue()); - } else { - capabilities.setCapability(pair.getKey(), pair.getValue()); - } - } - capabilities.setCapability("bstack:options", bstackOptions); - - username = System.getenv("BROWSERSTACK_USERNAME"); - if (username == null) { - username = (String) config.get("userName"); + if (browserstackYamlMap == null) { + File file = new File(getUserDir() + "/browserstack.yml"); + browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); } - - accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if (accessKey == null) { - accessKey = (String) config.get("accessKey"); - } - - this.checkAndStartBrowserStackLocal(capabilities, accessKey); - - driver = new RemoteWebDriver( - new URL("https://" + username + ":" + accessKey + "@" + config.get("server") + "/wd/hub"), capabilities); + Thread.currentThread().setName(this.getClass().getName() + "@" + taskID); + DesiredCapabilities capabilities = new DesiredCapabilities(); + this.driver = new RemoteWebDriver( + new URL("https://" + username + ":" + accessKey + "@hub.browserstack.com/wd/hub"), capabilities); } - public void checkAndStartBrowserStackLocal(DesiredCapabilities capabilities, String accessKey) throws Exception { - if (bsLocal != null) { - return; - } - JSONObject localCaps = new JSONObject(bstackOptions); + private static String getUserDir() { + return System.getProperty(USER_DIR); + } - if (capabilities.getCapability("bstack:options") != null - && localCaps.get("local") != null - && ((Boolean) localCaps.get("local")) == true) { - bsLocal = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - bsLocal.start(options); + private static Map convertYamlFileToMap(File yamlFile, Map map) { + try { + InputStream inputStream = Files.newInputStream(yamlFile.toPath()); + Yaml yaml = new Yaml(); + Map config = yaml.load(inputStream); + map.putAll(config); + } catch (Exception e) { + throw new RuntimeException(String.format("Malformed browserstack.yml file - %s.", e)); } + return map; } @After - public void tearDown() throws Exception { - driver.quit(); - if (bsLocal != null) { - bsLocal.stop(); - } + public void tearDown() { + this.driver.quit(); } } diff --git a/junit-4/src/test/java/com/browserstack/LocalTest.java b/junit-4/src/test/java/com/browserstack/LocalTest.java index 8c8e2ac..8c7bee0 100644 --- a/junit-4/src/test/java/com/browserstack/LocalTest.java +++ b/junit-4/src/test/java/com/browserstack/LocalTest.java @@ -1,8 +1,6 @@ package com.browserstack; import org.junit.Test; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.remote.SessionId; import java.io.IOException; import java.net.URISyntaxException; @@ -13,15 +11,14 @@ public class LocalTest extends BrowserStackJUnitTest { @Test public void test() throws URISyntaxException, IOException { - SessionId sessionId = ((RemoteWebDriver) driver).getSessionId(); try { driver.get("http://bs-local.com:45691/check"); assertTrue(driver.getPageSource().contains("Up and running")); - mark(sessionId, "passed", "Local content validated!"); + mark(driver, "passed", "Local content validated!"); } catch (Throwable t) { - mark(sessionId, "failed", "Local content not validated!"); + mark(driver, "failed", "Local content not validated!"); System.out.println("Exception: " + t); } } diff --git a/junit-4/src/test/java/com/browserstack/SingleTest.java b/junit-4/src/test/java/com/browserstack/SingleTest.java index 77a854f..7e9eb07 100644 --- a/junit-4/src/test/java/com/browserstack/SingleTest.java +++ b/junit-4/src/test/java/com/browserstack/SingleTest.java @@ -3,13 +3,12 @@ import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.remote.SessionId; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import java.io.IOException; import java.net.URISyntaxException; +import java.time.Duration; import static org.junit.Assert.assertTrue; @@ -17,10 +16,9 @@ public class SingleTest extends BrowserStackJUnitTest { @Test public void test() throws URISyntaxException, IOException { - SessionId sessionId = ((RemoteWebDriver) driver).getSessionId(); try { driver.get("https://bstackdemo.com/"); - final WebDriverWait wait = new WebDriverWait(driver, 10); + final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.titleIs("StackDemo")); 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]"))); @@ -28,9 +26,9 @@ public void test() throws URISyntaxException, IOException { wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("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!"); + mark(driver, "passed", "Product has been successfully added to the cart!"); } catch (Throwable t) { - mark(sessionId, "failed", "There was some issue!"); + mark(driver, "failed", "There was some issue!"); System.out.println("Exception: " + t); } } diff --git a/junit-4/src/test/resources/conf/local.conf.json b/junit-4/src/test/resources/conf/local.conf.json deleted file mode 100644 index 11fe4a6..0000000 --- a/junit-4/src/test/resources/conf/local.conf.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "server": "hub.browserstack.com", - "userName": "BROWSERSTACK_USERNAME", - "accessKey": "BROWSERSTACK_ACCESS_KEY", - "capabilities": { - "bstack:options": { - "sessionName": "local_test", - "buildName": "junit-browserstack", - "projectName": "My Test Project", - "debug": true, - "local": true, - "seleniumVersion": "4.0.0" - } - }, - "environments": [ - { - "bstack:options": { - "os": "Windows", - "osVersion": "10" - }, - "browser": "chrome", - "browserVersion": "latest-1" - } - ] -} diff --git a/junit-4/src/test/resources/conf/parallel.conf.json b/junit-4/src/test/resources/conf/parallel.conf.json deleted file mode 100644 index ff934d9..0000000 --- a/junit-4/src/test/resources/conf/parallel.conf.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "server": "hub.browserstack.com", - "userName": "BROWSERSTACK_USERNAME", - "accessKey": "BROWSERSTACK_ACCESS_KEY", - "capabilities": { - "bstack:options": { - "sessionName": "parallel_test", - "buildName": "junit-browserstack", - "projectName": "My Test Project", - "debug": true, - "seleniumVersion": "4.0.0" - } - }, - "environments": [ - { - "browser": "chrome", - "bstack:options": { - "os": "OS X", - "osVersion": "Big Sur" - } - }, - { - "browser": "firefox", - "bstack:options": { - "os": "Windows", - "osVersion": "11" - } - }, - { - "browser": "safari", - "browserVersion": "latest", - "bstack:options": { - "os": "OS X", - "osVersion": "Monterey" - } - }, - { - "bstack:options": { - "deviceName": "Samsung Galaxy S21" - } - }, - { - "bstack:options": { - "deviceName": "iPhone 12" - } - } - ] -} diff --git a/junit-4/src/test/resources/conf/single.conf.json b/junit-4/src/test/resources/conf/single.conf.json deleted file mode 100644 index 78c39c0..0000000 --- a/junit-4/src/test/resources/conf/single.conf.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "server": "hub.browserstack.com", - "userName": "BROWSERSTACK_USERNAME", - "accessKey": "BROWSERSTACK_ACCESS_KEY", - "capabilities": { - "bstack:options": { - "sessionName": "single_test", - "buildName": "junit-browserstack", - "projectName": "My Test Project", - "seleniumVersion": "4.0.0", - "debug": true - } - }, - "environments": [ - { - "bstack:options": { - "os": "Windows", - "osVersion": "11" - }, - "browser": "Chrome", - "browserVersion": "latest" - } - ] -} diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml new file mode 100644 index 0000000..78d45f0 --- /dev/null +++ b/junit-5/browserstack.yml @@ -0,0 +1,60 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: BROWSERSTACK_USERNAME +accessKey: BROWSERSTACK_ACCESS_KEY + +# ====================== +# Organizing your tests +# ====================== +# Use `projectName`, `buildName`, `name` capabilities to organise your tests +# `name` is the name of your test sessions and is automatically picked from your +# test name and doesn't need to be set manually when using BrowserStack SDK +# `buildName` is used to name your CI/CD job or the execution of your test suite. +# Ensure you add a dynamic identifier, like an incremental build number from your +# CI/CD or timestamp at the end of every build; otherwise tests from different +# executions will be grouped together on BrowserStack +buildName: browserstack-build-1 +# Use `projectName` to set the name of your project. Example, Marketing Website +projectName: BrowserStack Samples + +# ======================================= +# 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 + - device: Samsung Galaxy S22 Ultra + browserName: chrome # Try 'samsung' for Samsung browser + osVersion: 12.0 + +# ========================================== +# 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) + # browserStackLocalOptions: + # Options to be passed to BrowserStack local in-case of advanced configurations +# - 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) \ No newline at end of file diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 985ed25..9e36e4c 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -11,9 +11,9 @@ 5.8.1 5.4.0 1.1 - 4.0.0-alpha-3 + 4.1.0 3.0.0-M5 - 1.0.6 + 1.30 4.5.13 5 **/tests.SingleTest.java @@ -48,17 +48,48 @@ ${maven-surefire-plugin} maven-plugin - - com.browserstack - browserstack-local-java - ${browserstack-local-java} - org.apache.httpcomponents httpclient ${httpclient} + + org.yaml + snakeyaml + ${snakeyml.version} + + + com.browserstack + browserstack-java-sdk + LATEST + compile + + + + + maven-dependency-plugin + + + getClasspathFilenames + + properties + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin} + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + + + + single @@ -72,9 +103,6 @@ ${tests.single} - - single - false @@ -93,9 +121,6 @@ ${tests.local} - - local - false @@ -114,9 +139,6 @@ ${tests.single} - - parallel - junit.jupiter.execution.parallel.enabled = true diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index 723e6cb..0080dc6 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -1,63 +1,44 @@ package runners; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.junit.jupiter.api.extension.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; -import utils.SetupLocalTesting; +import org.yaml.snakeyaml.Yaml; -import java.io.FileReader; +import java.io.File; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; import java.util.*; import java.util.stream.Stream; 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 HashMap bstackOptions; - private HashMap bstackOptionsCommonCaps; - private HashMap bstackOptionsPlatform; + public String username, accesskey; + private static Map browserstackYamlMap; + public static final String USER_DIR = "user.dir"; public BstackRunner() { - this.username = setupCredsAndServer().get("username"); - this.accesskey = setupCredsAndServer().get("accesskey"); - this.server = setupCredsAndServer().get("server"); + this.browserstackYamlMap = setupCredsAndServer(); } - public HashMap setupCredsAndServer() { - try { - JSONParser parse = new JSONParser(); - mainConfig = (JSONObject) parse.parse(new FileReader("src/test/resources/caps.json")); - server = (String) mainConfig.get("server"); - username = System.getenv("BROWSERSTACK_USERNAME"); - if (username == null) { - username = (String) mainConfig.get("user"); - } - accesskey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if (accesskey == null) { - accesskey = (String) mainConfig.get("key"); - } - } catch (Exception e) { - System.out.println(e.getMessage()); + public Map setupCredsAndServer() { + + File file = new File(getUserDir() + "/browserstack.yml"); + browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); + username = System.getenv("BROWSERSTACK_USERNAME"); + if (username == null) { + username = browserstackYamlMap.get("userName").toString(); } - HashMap creds = new HashMap(); - creds.put("username", username); - creds.put("accesskey", accesskey); - creds.put("server", server); - return creds; + accesskey = System.getenv("BROWSERSTACK_ACCESS_KEY"); + if (accesskey == null) { + accesskey = browserstackYamlMap.get("accessKey").toString(); + } + return browserstackYamlMap; } @Override @@ -68,65 +49,32 @@ public boolean supportsTestTemplate(ExtensionContext extensionContext) { @Override public Stream provideTestTemplateInvocationContexts(ExtensionContext extensionContext) { List desiredCapsInvocationContexts = new ArrayList<>(); + ArrayList> browserStackPlatforms = (ArrayList>) browserstackYamlMap.get("platforms"); + int platformSize = browserStackPlatforms.size(); + for (int i = 0; i < platformSize; i++) { + capabilities = new DesiredCapabilities(); + desiredCapsInvocationContexts.add(invocationContext(capabilities, i)); + } + return desiredCapsInvocationContexts.stream(); + } - //picks the test profile based on the maven command executed - single, local, parallel - String profile = System.getProperty("config"); + private String getUserDir() { + return System.getProperty(USER_DIR); + } + private Map convertYamlFileToMap(File yamlFile, Map map) { 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(); - while (platformIterator.hasNext()) { - - capabilities = new DesiredCapabilities(); - Iterator commonCapsIterator = commonCapsMap.entrySet().iterator(); - while (commonCapsIterator.hasNext()) { - Map.Entry capsName = (Map.Entry) commonCapsIterator.next(); - if ("bstack:options".equals(capsName.getKey().toString())) { - bstackOptionsCommonCaps = (HashMap) commonCapsConfig.get("bstack:options"); - } else { - capabilities.setCapability((String) capsName.getKey(), capsName.getValue()); - } - } - - final String platformType = (String) platformIterator.next(); - browserConfig = (JSONObject) platformConfig.get(platformType); - allCapsMap = (HashMap) browserConfig; - - Iterator finalCapsIterator = allCapsMap.entrySet().iterator(); - while (finalCapsIterator.hasNext()) { - Map.Entry platformName = (Map.Entry) finalCapsIterator.next(); - if ("bstack:options".equals(platformName.getKey().toString())) { - bstackOptionsPlatform = (HashMap) browserConfig.get("bstack:options"); - } else { - capabilities.setCapability((String) platformName.getKey(), platformName.getValue()); - } - } - //Initializing local testing connection - if (bstackOptionsCommonCaps.containsKey("local")) { - HashMap localOptions = new HashMap<>(); - localOptions.put("key", accesskey); - //Add more local options here, e.g. forceLocal, localIdentifier, etc. - SetupLocalTesting.createInstance(localOptions); - } - bstackOptions = new HashMap<>(); - bstackOptions.putAll(bstackOptionsCommonCaps); - bstackOptions.putAll(bstackOptionsPlatform); - capabilities.setCapability("bstack:options", bstackOptions); - - desiredCapsInvocationContexts.add(invocationContext(capabilities)); - } + InputStream inputStream = Files.newInputStream(yamlFile.toPath()); + Yaml yaml = new Yaml(); + Map config = yaml.load(inputStream); + map.putAll(config); } catch (Exception e) { - System.out.println(e); + throw new RuntimeException(String.format("Malformed browserstack.yml file - %s.", e)); } - return desiredCapsInvocationContexts.stream(); + return map; } - private TestTemplateInvocationContext invocationContext(DesiredCapabilities caps) { + private TestTemplateInvocationContext invocationContext(DesiredCapabilities caps, int i) { return new TestTemplateInvocationContext() { @Override @@ -143,7 +91,8 @@ public boolean supportsParameter(ParameterContext parameterContext, public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { try { - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + "@" + server + "/wd/hub"), caps); + Thread.currentThread().setName("Junit5@"+i); + driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + "@hub.browserstack.com/wd/hub"), caps); } catch (MalformedURLException e) { e.printStackTrace(); } diff --git a/junit-5/src/test/java/tests/LocalTest.java b/junit-5/src/test/java/tests/LocalTest.java index de2d9bc..ba01b37 100644 --- a/junit-5/src/test/java/tests/LocalTest.java +++ b/junit-5/src/test/java/tests/LocalTest.java @@ -2,8 +2,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.remote.SessionId; import runners.WebDriverTest; import utils.MarkSessionStatus; @@ -12,8 +10,7 @@ public class LocalTest { @WebDriverTest void localTest(WebDriver driver) { - SessionId sessionId = ((RemoteWebDriver) driver).getSessionId(); - MarkSessionStatus sessionStatus = new MarkSessionStatus(sessionId); + MarkSessionStatus sessionStatus = new MarkSessionStatus(driver); try { driver.get("http://localhost:45691/check"); diff --git a/junit-5/src/test/java/tests/SingleTest.java b/junit-5/src/test/java/tests/SingleTest.java index b2c7e43..784fe96 100644 --- a/junit-5/src/test/java/tests/SingleTest.java +++ b/junit-5/src/test/java/tests/SingleTest.java @@ -3,8 +3,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.remote.SessionId; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import runners.WebDriverTest; @@ -16,8 +14,7 @@ public class SingleTest { @WebDriverTest void singleTest(WebDriver driver) { - SessionId sessionId = ((RemoteWebDriver) driver).getSessionId(); - MarkSessionStatus sessionStatus = new MarkSessionStatus(sessionId); + MarkSessionStatus sessionStatus = new MarkSessionStatus(driver); try { driver.get("https://bstackdemo.com/"); @@ -39,11 +36,4 @@ void singleTest(WebDriver driver) { } driver.quit(); } - - //@WebDriverTest - void bstackTest(WebDriver driver) { - driver.get("https://bstackdemo.com/"); - System.out.println("Test1: " + Thread.currentThread().getName()); - driver.quit(); - } } diff --git a/junit-5/src/test/java/utils/MarkSessionStatus.java b/junit-5/src/test/java/utils/MarkSessionStatus.java index 52bb8f2..a106cf4 100644 --- a/junit-5/src/test/java/utils/MarkSessionStatus.java +++ b/junit-5/src/test/java/utils/MarkSessionStatus.java @@ -1,36 +1,25 @@ package utils; -import org.apache.http.NameValuePair; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.message.BasicNameValuePair; -import org.openqa.selenium.remote.SessionId; +import org.json.simple.JSONObject; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; import runners.BstackRunner; -import java.net.URI; -import java.util.ArrayList; - public class MarkSessionStatus extends BstackRunner { - SessionId sessionId; + WebDriver webDriver; - public MarkSessionStatus(SessionId sessionId) { - this.sessionId = sessionId; + public MarkSessionStatus(WebDriver webDriver) { + this.webDriver = webDriver; } public void markTestStatus(String status, String reason) { - try { - URI uri = new URI("https://" + username + ":" + accesskey + "@api.browserstack.com/automate/sessions/" + sessionId + ".json"); - HttpPut putRequest = new HttpPut(uri); - - ArrayList nameValuePairs = new ArrayList(); - nameValuePairs.add((new BasicNameValuePair("status", status))); - nameValuePairs.add((new BasicNameValuePair("reason", reason))); - putRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs)); - - HttpClientBuilder.create().build().execute(putRequest); - } catch (Exception e) { - System.out.println("Exception: " + e.getMessage()); - } + final JavascriptExecutor jse = (JavascriptExecutor) webDriver; + JSONObject executorObject = new JSONObject(); + JSONObject argumentsObject = new JSONObject(); + argumentsObject.put("status", status); + argumentsObject.put("reason", reason); + executorObject.put("action", "setSessionStatus"); + executorObject.put("arguments", argumentsObject); + jse.executeScript(String.format("browserstack_executor: %s", executorObject)); } } diff --git a/junit-5/src/test/java/utils/SetupLocalTesting.java b/junit-5/src/test/java/utils/SetupLocalTesting.java deleted file mode 100644 index 149d939..0000000 --- a/junit-5/src/test/java/utils/SetupLocalTesting.java +++ /dev/null @@ -1,53 +0,0 @@ -package utils; - -import com.browserstack.local.Local; - -import java.util.Map; - -public class SetupLocalTesting { - private static volatile SetupLocalTesting instance; - - private final Local local = new Local(); - - private SetupLocalTesting(Map localOptions) { - try { - local.start(localOptions); - } catch (Exception e) { - throw new RuntimeException("Initialization of BrowserStack Local failed.", e); - } - } - - public static void createInstance(Map args) { - if (instance == null) { - synchronized (SetupLocalTesting.class) { - if (instance == null) { - instance = new SetupLocalTesting(args); - Runtime.getRuntime().addShutdownHook(new Closer(instance.local)); - } - } - } - } - - public static SetupLocalTesting getInstance() { - return instance; - } - - private static class Closer extends Thread { - private final Local local; - - public Closer(Local local) { - this.local = local; - } - - @Override - public void run() { - try { - if (local.isRunning()) { - local.stop(); - } - } catch (Exception e) { - System.out.println("Error encountered while stopping BrowserStack Local { }" + e); - } - } - } -} diff --git a/junit-5/src/test/resources/caps.json b/junit-5/src/test/resources/caps.json deleted file mode 100644 index 902a421..0000000 --- a/junit-5/src/test/resources/caps.json +++ /dev/null @@ -1,128 +0,0 @@ -{ - "server": "hub.browserstack.com", - "userName": "BROWSERSTACK_USERNAME", - "accessKey": "BROWSERSTACK_ACCESS_KEY", - "tests": { - "single": { - "common_caps": { - "bstack:options": { - "buildName": "junit5-browserstack", - "sessionName": "single-test", - "seleniumVersion": "4.0.0", - "networkLogs": "true", - "consoleLogs": "verbose", - "debug": "true" - } - }, - "platform": { - "chrome": { - "bstack:options": { - "os": "Windows", - "osVersion": "10" - }, - "browserName": "chrome", - "browserVersion": "latest" - } - } - }, - "local": { - "common_caps": { - "bstack:options": { - "buildName": "junit5-browserstack", - "sessionName": "local-test", - "seleniumVersion": "4.0.0", - "consoleLogs": "verbose", - "debug": "true", - "local": "true" - } - }, - "platform": { - "chrome": { - "bstack:options": { - "os": "Windows", - "osVersion": "11" - }, - "browserName": "chrome", - "browserVersion": "latest" - } - } - }, - "parallel": { - "common_caps": { - "bstack:options": { - "buildName": "junit5-browserstack", - "sessionName": "parallel-test", - "seleniumVersion": "4.0.0", - "consoleLogs": "verbose", - "debug": "true" - } - }, - "platform": { - "chrome": { - "bstack:options": { - "os": "Windows", - "osVersion": "10" - }, - "browser": "chrome", - "browserVersion": "latest-1" - }, - "safari": { - "bstack:options": { - "os": "OS X", - "osVersion": "Big Sur" - }, - "browser": "safari", - "browserVersion": "latest" - }, - "edge": { - "bstack:options": { - "os": "Windows", - "osVersion": "11" - }, - "browser": "edge", - "browserVersion": "latest-2" - }, - "firefox": { - "bstack:options": { - "os": "OS X", - "osVersion": "Monterey" - }, - "browser": "firefox", - "browserVersion": "latest" - }, - "android": { - "bstack:options": { - "deviceName": "Samsung Galaxy S21", - "osVersion": "11.0" - } - }, - "ios": { - "bstack:options": { - "deviceName": "iPhone 12 Mini", - "osVersion": "14" - } - }, - "tab": { - "bstack:options": { - "deviceName": "Samsung Galaxy Tab S7" - } - }, - "ipad": { - "bstack:options": { - "deviceName": "iPad Mini 2019" - } - }, - "xiaomi": { - "bstack:options": { - "deviceName": "Xiaomi Redmi Note 9" - } - }, - "oneplus": { - "bstack:options": { - "deviceName": "OnePlus 9" - } - } - } - } - } -} From 4f2b0eb20614338ec5582ca494edb9f8d022c293 Mon Sep 17 00:00:00 2001 From: Karan Shah <64479353+karanshah-browserstack@users.noreply.github.com> Date: Thu, 25 Aug 2022 00:07:47 +0530 Subject: [PATCH 02/50] Update sdk sample --- .gitignore | 2 +- junit-4/README.md | 5 +- junit-4/browserstack.yml | 4 +- junit-4/pom.xml | 16 +++-- .../browserstack/BrowserStackJUnitTest.java | 49 +++++++++++++-- .../{SingleTest.java => SampleTest.java} | 6 +- junit-5/browserstack.yml | 4 +- junit-5/pom.xml | 9 ++- .../src/test/java/runners/BstackRunner.java | 60 ++++++++++++++----- 9 files changed, 114 insertions(+), 41 deletions(-) rename junit-4/src/test/java/com/browserstack/{SingleTest.java => SampleTest.java} (88%) diff --git a/.gitignore b/.gitignore index c3103ae..87f8a89 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ browserstack.err local.log *.png *.txt -**/logs \ No newline at end of file +**/logs diff --git a/junit-4/README.md b/junit-4/README.md index 41fee22..8d916ad 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -8,12 +8,11 @@ ## Setup * Clone the repo * Install dependencies `mvn install` -* Update *.conf.json files inside the `src/test/resources/conf` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). +* Update `browserstack.yml` files inside the root 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 a parallel test, run `mvn test -P sample` * 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/browserstack.yml b/junit-4/browserstack.yml index 9c7f077..687e87c 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -34,7 +34,7 @@ platforms: osVersion: 10 browserName: Edge browserVersion: latest - - device: Samsung Galaxy S22 Ultra + - deviceName: Samsung Galaxy S22 Ultra browserName: chrome # Try 'samsung' for Samsung browser osVersion: 12.0 @@ -44,7 +44,7 @@ platforms: # ========================================== # 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) +browserstackLocal: false # (Default false) # browserStackLocalOptions: # Options to be passed to BrowserStack local in-case of advanced configurations # - localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. diff --git a/junit-4/pom.xml b/junit-4/pom.xml index 7ab6f3e..a85d262 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -38,6 +38,11 @@ selenium-java 4.1.0 + + com.googlecode.json-simple + json-simple + 1.1.1 + org.yaml snakeyaml @@ -54,6 +59,7 @@ + org.apache.maven.plugins maven-dependency-plugin @@ -68,11 +74,6 @@ org.apache.maven.plugins maven-surefire-plugin ${surefire.version} - - - -javaagent:${com.browserstack:browserstack-java-sdk:jar} - - @@ -87,7 +88,7 @@ maven-surefire-plugin - com/browserstack/SingleTest.java + com/browserstack/SampleTest.java @@ -106,6 +107,9 @@ com/browserstack/LocalTest.java + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 3d3469c..2c09b92 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -1,5 +1,6 @@ package com.browserstack; +import com.fasterxml.jackson.databind.ObjectMapper; import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; @@ -7,8 +8,8 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.yaml.snakeyaml.Yaml; @@ -20,7 +21,7 @@ @RunWith(Parallelized.class) public class BrowserStackJUnitTest { - public static String username, accessKey; + public static String userName, accessKey; private static Map browserstackYamlMap; public WebDriver driver; @Parameter(value = 0) @@ -62,9 +63,49 @@ public void setUp() throws Exception { browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); } Thread.currentThread().setName(this.getClass().getName() + "@" + taskID); - DesiredCapabilities capabilities = new DesiredCapabilities(); + MutableCapabilities capabilities = new MutableCapabilities(); + HashMap bStackOptions = new HashMap<>(); + browserstackYamlMap.forEach((key, value) -> { + if (key.equalsIgnoreCase("userName")) { + userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) value; + } else if (key.equalsIgnoreCase("accessKey")) { + accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) value; + } else if (key.equalsIgnoreCase("platforms")) { + ArrayList> platformsArrayList = (ArrayList>) value; + platformsArrayList.get(taskID).forEach((k, v) -> { + if (k.equalsIgnoreCase("browserName") || k.equalsIgnoreCase("browserVersion")) { + capabilities.setCapability(k, v.toString()); + } else { + bStackOptions.put(k, v.toString()); + } + }); + } else if (key.equalsIgnoreCase("browserstackLocal") || + key.equalsIgnoreCase("local")) { + bStackOptions.put("local", value); + } else if (key.equalsIgnoreCase("browserStackLocalOptions") || + key.equalsIgnoreCase("localOptions")) { + if (value instanceof LinkedHashMap) { + ArrayList> localOptionsArrayList = (ArrayList>) value; + localOptionsArrayList.forEach(localOptionsMap -> { + if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) + && localOptionsMap.containsKey("localIdentifier")) { + bStackOptions.put("localIdentifier", localOptionsMap.get("localIdentifier").toString()); + } + }); + } else if (value instanceof HashMap) { + HashMap localOptionsHashMap = (HashMap) new ObjectMapper().convertValue(value, HashMap.class); + if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) + && localOptionsHashMap.containsKey("localIdentifier")) { + bStackOptions.put("localIdentifier", localOptionsHashMap.get("localIdentifier").toString()); + } + } + } else { + bStackOptions.put(key, value); + } + }); + capabilities.setCapability("bstack:options", bStackOptions); this.driver = new RemoteWebDriver( - new URL("https://" + username + ":" + accessKey + "@hub.browserstack.com/wd/hub"), capabilities); + new URL("https://" + userName + ":" + accessKey + "@hub.browserstack.com/wd/hub"), capabilities); } private static String getUserDir() { diff --git a/junit-4/src/test/java/com/browserstack/SingleTest.java b/junit-4/src/test/java/com/browserstack/SampleTest.java similarity index 88% rename from junit-4/src/test/java/com/browserstack/SingleTest.java rename to junit-4/src/test/java/com/browserstack/SampleTest.java index 7e9eb07..d9c1005 100644 --- a/junit-4/src/test/java/com/browserstack/SingleTest.java +++ b/junit-4/src/test/java/com/browserstack/SampleTest.java @@ -6,16 +6,14 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -import java.io.IOException; -import java.net.URISyntaxException; import java.time.Duration; import static org.junit.Assert.assertTrue; -public class SingleTest extends BrowserStackJUnitTest { +public class SampleTest extends BrowserStackJUnitTest { @Test - public void test() throws URISyntaxException, IOException { + public void test() { try { driver.get("https://bstackdemo.com/"); final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index 78d45f0..75471dd 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -34,7 +34,7 @@ platforms: osVersion: 10 browserName: Edge browserVersion: latest - - device: Samsung Galaxy S22 Ultra + - deviceName: Samsung Galaxy S22 Ultra browserName: chrome # Try 'samsung' for Samsung browser osVersion: 12.0 @@ -44,7 +44,7 @@ platforms: # ========================================== # 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) +browserstackLocal: false # (Default false) # browserStackLocalOptions: # Options to be passed to BrowserStack local in-case of advanced configurations # - localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 9e36e4c..3d24f95 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -68,6 +68,7 @@ + org.apache.maven.plugins maven-dependency-plugin @@ -82,11 +83,6 @@ org.apache.maven.plugins maven-surefire-plugin ${maven-surefire-plugin} - - - -javaagent:${com.browserstack:browserstack-java-sdk:jar} - - @@ -121,6 +117,9 @@ ${tests.local} + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + false diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index 0080dc6..1a64b90 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -1,8 +1,9 @@ package runners; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.extension.*; +import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.yaml.snakeyaml.Yaml; @@ -16,8 +17,7 @@ public class BstackRunner implements TestTemplateInvocationContextProvider { public WebDriver driver; - public DesiredCapabilities capabilities; - public String username, accesskey; + public String userName, accessKey; private static Map browserstackYamlMap; public static final String USER_DIR = "user.dir"; @@ -30,14 +30,6 @@ public Map setupCredsAndServer() { File file = new File(getUserDir() + "/browserstack.yml"); browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); - username = System.getenv("BROWSERSTACK_USERNAME"); - if (username == null) { - username = browserstackYamlMap.get("userName").toString(); - } - accesskey = System.getenv("BROWSERSTACK_ACCESS_KEY"); - if (accesskey == null) { - accesskey = browserstackYamlMap.get("accessKey").toString(); - } return browserstackYamlMap; } @@ -52,7 +44,47 @@ public Stream provideTestTemplateInvocationContex ArrayList> browserStackPlatforms = (ArrayList>) browserstackYamlMap.get("platforms"); int platformSize = browserStackPlatforms.size(); for (int i = 0; i < platformSize; i++) { - capabilities = new DesiredCapabilities(); + MutableCapabilities capabilities = new MutableCapabilities(); + HashMap bStackOptions = new HashMap<>(); + int platform = i; + browserstackYamlMap.forEach((key, value) -> { + if (key.equalsIgnoreCase("userName")) { + userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) value; + } else if (key.equalsIgnoreCase("accessKey")) { + accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) value; + } else if (key.equalsIgnoreCase("platforms")) { + browserStackPlatforms.get(platform).forEach((k, v) -> { + if (k.equalsIgnoreCase("browserName") || k.equalsIgnoreCase("browserVersion")) { + capabilities.setCapability(k, v.toString()); + } else { + bStackOptions.put(k, v.toString()); + } + }); + } else if (key.equalsIgnoreCase("browserstackLocal") || + key.equalsIgnoreCase("local")) { + bStackOptions.put("local", value); + } else if (key.equalsIgnoreCase("browserStackLocalOptions") || + key.equalsIgnoreCase("localOptions")) { + if (value instanceof LinkedHashMap) { + ArrayList> localOptionsArrayList = (ArrayList>) value; + localOptionsArrayList.forEach(localOptionsMap -> { + if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) + && localOptionsMap.containsKey("localIdentifier")) { + bStackOptions.put("localIdentifier", localOptionsMap.get("localIdentifier").toString()); + } + }); + } else if (value instanceof HashMap) { + HashMap localOptionsHashMap = (HashMap) new ObjectMapper().convertValue(value, HashMap.class); + if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) + && localOptionsHashMap.containsKey("localIdentifier")) { + bStackOptions.put("localIdentifier", localOptionsHashMap.get("localIdentifier").toString()); + } + } + } else { + bStackOptions.put(key, value); + } + }); + capabilities.setCapability("bstack:options", bStackOptions); desiredCapsInvocationContexts.add(invocationContext(capabilities, i)); } return desiredCapsInvocationContexts.stream(); @@ -74,7 +106,7 @@ private Map convertYamlFileToMap(File yamlFile, Map Date: Mon, 29 Aug 2022 12:40:36 +0530 Subject: [PATCH 03/50] Update Readme.md for sdk samples --- README.md | 2 +- junit-4/README.md | 8 +------- junit-4/browserstack.yml | 10 +++++----- junit-5/README.md | 10 +--------- junit-5/browserstack.yml | 8 ++++---- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index dce7f1c..265a739 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780) -This repo covers BrowserStack integration with the JUnit frameworks using Selenium 4. More details in the README.md file of the individual frameworks. +This repo covers BrowserStack integration with the JUnit frameworks using Selenium 4 and BrowserStack SDK. More details in the README.md file of the individual frameworks. * [JUnit 4](https://github.com/browserstack/junit-browserstack/blob/master/junit-4/README.md) * [JUnit 5](https://github.com/browserstack/junit-browserstack/blob/master/junit-5/README.md) diff --git a/junit-4/README.md b/junit-4/README.md index 8d916ad..856f86c 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -12,7 +12,7 @@ ## Running your tests * To run a parallel test, run `mvn test -P sample` -* To run local tests, run `mvn test -P local` +* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `mvn test -P local` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) @@ -32,9 +32,3 @@ set BROWSERSTACK_USERNAME= set BROWSERSTACK_ACCESS_KEY= ``` - -## Addtional Resources -* [Documentation for writing Automate test scripts in Java](https://www.browserstack.com/automate/java) -* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities) -* [Browsers & mobile devices for selenium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate) -* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api) diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index 687e87c..af74936 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -44,11 +44,11 @@ platforms: # ========================================== # 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: false # (Default false) - # browserStackLocalOptions: - # Options to be passed to BrowserStack local in-case of advanced configurations - # - 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. +browserStackLocal: false # (Default false) +# browserStackLocalOptions: +# Options to be passed to BrowserStack local in-case of advanced configurations +# 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 # =================== diff --git a/junit-5/README.md b/junit-5/README.md index f402221..5f79552 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -7,8 +7,7 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3** ## Setup * Clone the repo * Install dependencies `mvn install` -* Update credentials in the `/src/test/resources/caps.json` file with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). -* The platform details can be modified in the `/src/test/resources/caps.json` file within the respective profile i.e. `single`, `local`, `parallel`. Refer to our [Capabilities Generator](https://www.browserstack.com/automate/capabilities?tag=selenium-4) page for all platform and capabilities related information. +* Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). * For parallel testing, control the concurrency by setting the value for `parallel.count`. Junit 5 uses the following properties for parallelism: ``` junit.jupiter.execution.parallel.enabled = true @@ -40,13 +39,6 @@ Understand how many parallel sessions you need by using our [Parallel Test Calcu set BROWSERSTACK_ACCESS_KEY= ``` - -## Additional Resources -* [Documentation for writing Automate test scripts in Java](https://www.browserstack.com/automate/java) -* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities) -* [Browsers & mobile devices for selenium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate) -* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api) - ## Open Issues * Value for `junit.jupiter.execution.parallel.config.fixed.parallelism` gets multiplied in selenium versions above `4.0.0-alpha-3`. Github issue: diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index 75471dd..c18c565 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -45,10 +45,10 @@ platforms: # 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: false # (Default false) - # browserStackLocalOptions: - # Options to be passed to BrowserStack local in-case of advanced configurations -# - 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. +# browserStackLocalOptions: +# Options to be passed to BrowserStack local in-case of advanced configurations + # 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 # =================== From 993ac00909c988ebce641887edad76fe2701880e Mon Sep 17 00:00:00 2001 From: kamal-kaur04 <38219887+kamal-kaur04@users.noreply.github.com> Date: Mon, 5 Sep 2022 19:14:46 +0530 Subject: [PATCH 04/50] change junit samples to use java-sdk for parallelism --- junit-4/browserstack.yml | 2 +- junit-4/pom.xml | 21 ++-- .../browserstack/BrowserStackJUnitTest.java | 97 +----------------- .../java/com/browserstack/Parallelized.java | 42 -------- junit-5/README.md | 9 +- junit-5/browserstack.yml | 2 +- junit-5/pom.xml | 43 +++----- .../src/test/java/runners/BstackRunner.java | 98 +++---------------- 8 files changed, 43 insertions(+), 271 deletions(-) delete mode 100644 junit-4/src/test/java/com/browserstack/Parallelized.java diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index af74936..69eb727 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -44,7 +44,7 @@ platforms: # ========================================== # 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: false # (Default false) +browserStackLocal: true # (Default false) # browserStackLocalOptions: # Options to be passed to BrowserStack local in-case of advanced configurations # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. diff --git a/junit-4/pom.xml b/junit-4/pom.xml index a85d262..5b2f3b0 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -12,10 +12,7 @@ UTF-8 - 2.19.1 - 1.30 - - + 3.0.0-M5 default 1.8 @@ -43,11 +40,6 @@ json-simple 1.1.1 - - org.yaml - snakeyaml - ${snakeyml.version} - com.browserstack browserstack-java-sdk @@ -74,6 +66,14 @@ org.apache.maven.plugins maven-surefire-plugin ${surefire.version} + + + com/browserstack/SampleTest.java + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + @@ -90,6 +90,9 @@ com/browserstack/SampleTest.java + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 2c09b92..1fe6afd 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -5,13 +5,10 @@ import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.RemoteWebDriver; -import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.InputStream; @@ -19,30 +16,14 @@ import java.nio.file.Files; import java.util.*; -@RunWith(Parallelized.class) public class BrowserStackJUnitTest { - public static String userName, accessKey; - private static Map browserstackYamlMap; public WebDriver driver; - @Parameter(value = 0) - public int taskID; - public static final String USER_DIR = "user.dir"; - @Parameters - public static Iterable data() { - List taskIDs = new ArrayList(); - if (browserstackYamlMap == null) { - File file = new File(getUserDir() + "/browserstack.yml"); - browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); - } - if (browserstackYamlMap != null) { - ArrayList> browserStackPlatforms = (ArrayList>) browserstackYamlMap.get("platforms"); - int envs = browserStackPlatforms.size(); - for (int i = 0; i < envs; i++) { - taskIDs.add(i); - } - } - return taskIDs; + @Before + public void setUp() throws Exception { + MutableCapabilities capabilities = new MutableCapabilities(); + this.driver = new RemoteWebDriver( + new URL("https://hub.browserstack.com/wd/hub"), capabilities); } public static void mark(WebDriver remoteDriver, String status, String reason) { @@ -56,74 +37,6 @@ public static void mark(WebDriver remoteDriver, String status, String reason) { jse.executeScript(String.format("browserstack_executor: %s", executorObject)); } - @Before - public void setUp() throws Exception { - if (browserstackYamlMap == null) { - File file = new File(getUserDir() + "/browserstack.yml"); - browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); - } - Thread.currentThread().setName(this.getClass().getName() + "@" + taskID); - MutableCapabilities capabilities = new MutableCapabilities(); - HashMap bStackOptions = new HashMap<>(); - browserstackYamlMap.forEach((key, value) -> { - if (key.equalsIgnoreCase("userName")) { - userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) value; - } else if (key.equalsIgnoreCase("accessKey")) { - accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) value; - } else if (key.equalsIgnoreCase("platforms")) { - ArrayList> platformsArrayList = (ArrayList>) value; - platformsArrayList.get(taskID).forEach((k, v) -> { - if (k.equalsIgnoreCase("browserName") || k.equalsIgnoreCase("browserVersion")) { - capabilities.setCapability(k, v.toString()); - } else { - bStackOptions.put(k, v.toString()); - } - }); - } else if (key.equalsIgnoreCase("browserstackLocal") || - key.equalsIgnoreCase("local")) { - bStackOptions.put("local", value); - } else if (key.equalsIgnoreCase("browserStackLocalOptions") || - key.equalsIgnoreCase("localOptions")) { - if (value instanceof LinkedHashMap) { - ArrayList> localOptionsArrayList = (ArrayList>) value; - localOptionsArrayList.forEach(localOptionsMap -> { - if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) - && localOptionsMap.containsKey("localIdentifier")) { - bStackOptions.put("localIdentifier", localOptionsMap.get("localIdentifier").toString()); - } - }); - } else if (value instanceof HashMap) { - HashMap localOptionsHashMap = (HashMap) new ObjectMapper().convertValue(value, HashMap.class); - if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) - && localOptionsHashMap.containsKey("localIdentifier")) { - bStackOptions.put("localIdentifier", localOptionsHashMap.get("localIdentifier").toString()); - } - } - } else { - bStackOptions.put(key, value); - } - }); - capabilities.setCapability("bstack:options", bStackOptions); - this.driver = new RemoteWebDriver( - new URL("https://" + userName + ":" + accessKey + "@hub.browserstack.com/wd/hub"), capabilities); - } - - private static String getUserDir() { - return System.getProperty(USER_DIR); - } - - private static Map convertYamlFileToMap(File yamlFile, Map map) { - try { - InputStream inputStream = Files.newInputStream(yamlFile.toPath()); - Yaml yaml = new Yaml(); - Map config = yaml.load(inputStream); - map.putAll(config); - } catch (Exception e) { - throw new RuntimeException(String.format("Malformed browserstack.yml file - %s.", e)); - } - return map; - } - @After public void tearDown() { this.driver.quit(); diff --git a/junit-4/src/test/java/com/browserstack/Parallelized.java b/junit-4/src/test/java/com/browserstack/Parallelized.java deleted file mode 100644 index 33a918b..0000000 --- a/junit-4/src/test/java/com/browserstack/Parallelized.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.browserstack; - -import org.junit.runners.Parameterized; -import org.junit.runners.model.RunnerScheduler; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -public class Parallelized extends Parameterized { - - @SuppressWarnings("rawtypes") - public Parallelized(Class klass) throws Throwable { - super(klass); - setScheduler(new ThreadPoolScheduler()); - } - - private static class ThreadPoolScheduler implements RunnerScheduler { - private final ExecutorService executor; - - public ThreadPoolScheduler() { - String threads = System.getProperty("junit.parallel.threads", "16"); - int numThreads = Integer.parseInt(threads); - executor = Executors.newFixedThreadPool(numThreads); - } - - @Override - public void finished() { - executor.shutdown(); - try { - executor.awaitTermination(10, TimeUnit.MINUTES); - } catch (InterruptedException exc) { - throw new RuntimeException(exc); - } - } - - @Override - public void schedule(Runnable childStatement) { - executor.submit(childStatement); - } - } -} diff --git a/junit-5/README.md b/junit-5/README.md index 5f79552..bd917a0 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -8,17 +8,10 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3** * Clone the repo * Install dependencies `mvn install` * Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). -* For parallel testing, control the concurrency by setting the value for `parallel.count`. Junit 5 uses the following properties for parallelism: - ``` - 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} - ``` + ## Running your tests * To run a single test, run `mvn test -P single` * 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/browserstack.yml b/junit-5/browserstack.yml index c18c565..e311c46 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -44,7 +44,7 @@ platforms: # ========================================== # 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: false # (Default false) +browserstackLocal: true # (Default false) # browserStackLocalOptions: # Options to be passed to BrowserStack local in-case of advanced configurations # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 3d24f95..2660d64 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -53,11 +53,6 @@ httpclient ${httpclient} - - org.yaml - snakeyaml - ${snakeyml.version} - com.browserstack browserstack-java-sdk @@ -83,6 +78,15 @@ org.apache.maven.plugins maven-surefire-plugin ${maven-surefire-plugin} + + + ${tests.single} + + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + + false + @@ -99,6 +103,9 @@ ${tests.single} + + -javaagent:${com.browserstack:browserstack-java-sdk:jar} + false @@ -126,31 +133,5 @@ - - parallel - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M5 - - - ${tests.single} - - - - 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 - - - - - diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index 1a64b90..b95e59c 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -1,37 +1,21 @@ package runners; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; import org.junit.jupiter.api.extension.*; -import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; -import org.yaml.snakeyaml.Yaml; -import java.io.File; -import java.io.InputStream; +import java.io.FileReader; import java.net.MalformedURLException; import java.net.URL; -import java.nio.file.Files; import java.util.*; import java.util.stream.Stream; public class BstackRunner implements TestTemplateInvocationContextProvider { public WebDriver driver; - public String userName, accessKey; - private static Map browserstackYamlMap; - public static final String USER_DIR = "user.dir"; - - - public BstackRunner() { - this.browserstackYamlMap = setupCredsAndServer(); - } - - public Map setupCredsAndServer() { - - File file = new File(getUserDir() + "/browserstack.yml"); - browserstackYamlMap = convertYamlFileToMap(file, new HashMap<>()); - return browserstackYamlMap; - } + public MutableCapabilities capabilities; @Override public boolean supportsTestTemplate(ExtensionContext extensionContext) { @@ -41,72 +25,13 @@ public boolean supportsTestTemplate(ExtensionContext extensionContext) { @Override public Stream provideTestTemplateInvocationContexts(ExtensionContext extensionContext) { List desiredCapsInvocationContexts = new ArrayList<>(); - ArrayList> browserStackPlatforms = (ArrayList>) browserstackYamlMap.get("platforms"); - int platformSize = browserStackPlatforms.size(); - for (int i = 0; i < platformSize; i++) { - MutableCapabilities capabilities = new MutableCapabilities(); - HashMap bStackOptions = new HashMap<>(); - int platform = i; - browserstackYamlMap.forEach((key, value) -> { - if (key.equalsIgnoreCase("userName")) { - userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) value; - } else if (key.equalsIgnoreCase("accessKey")) { - accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) value; - } else if (key.equalsIgnoreCase("platforms")) { - browserStackPlatforms.get(platform).forEach((k, v) -> { - if (k.equalsIgnoreCase("browserName") || k.equalsIgnoreCase("browserVersion")) { - capabilities.setCapability(k, v.toString()); - } else { - bStackOptions.put(k, v.toString()); - } - }); - } else if (key.equalsIgnoreCase("browserstackLocal") || - key.equalsIgnoreCase("local")) { - bStackOptions.put("local", value); - } else if (key.equalsIgnoreCase("browserStackLocalOptions") || - key.equalsIgnoreCase("localOptions")) { - if (value instanceof LinkedHashMap) { - ArrayList> localOptionsArrayList = (ArrayList>) value; - localOptionsArrayList.forEach(localOptionsMap -> { - if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) - && localOptionsMap.containsKey("localIdentifier")) { - bStackOptions.put("localIdentifier", localOptionsMap.get("localIdentifier").toString()); - } - }); - } else if (value instanceof HashMap) { - HashMap localOptionsHashMap = (HashMap) new ObjectMapper().convertValue(value, HashMap.class); - if (((Boolean) browserstackYamlMap.get("browserstackLocal") || (Boolean) browserstackYamlMap.get("local")) - && localOptionsHashMap.containsKey("localIdentifier")) { - bStackOptions.put("localIdentifier", localOptionsHashMap.get("localIdentifier").toString()); - } - } - } else { - bStackOptions.put(key, value); - } - }); - capabilities.setCapability("bstack:options", bStackOptions); - desiredCapsInvocationContexts.add(invocationContext(capabilities, i)); - } - return desiredCapsInvocationContexts.stream(); - } - - private String getUserDir() { - return System.getProperty(USER_DIR); - } - private Map convertYamlFileToMap(File yamlFile, Map map) { - try { - InputStream inputStream = Files.newInputStream(yamlFile.toPath()); - Yaml yaml = new Yaml(); - Map config = yaml.load(inputStream); - map.putAll(config); - } catch (Exception e) { - throw new RuntimeException(String.format("Malformed browserstack.yml file - %s.", e)); - } - return map; + capabilities = new MutableCapabilities(); + desiredCapsInvocationContexts.add(invocationContext(capabilities)); + return desiredCapsInvocationContexts.stream(); } - private TestTemplateInvocationContext invocationContext(MutableCapabilities caps, int i) { + private TestTemplateInvocationContext invocationContext(MutableCapabilities caps) { return new TestTemplateInvocationContext() { @Override @@ -123,8 +48,7 @@ public boolean supportsParameter(ParameterContext parameterContext, public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { try { - Thread.currentThread().setName("Junit5@"+i); - driver = new RemoteWebDriver(new URL("https://" + userName + ":" + accessKey + "@hub.browserstack.com/wd/hub"), caps); + driver = new RemoteWebDriver(new URL("https://hub.browserstack.com/wd/hub"), caps); } catch (MalformedURLException e) { e.printStackTrace(); } @@ -134,4 +58,4 @@ public Object resolveParameter(ParameterContext parameterContext, } }; } -} +} \ No newline at end of file From 1f6a2c2a2d4d2ea4bdf82c3fa3c316c9a06eafdc Mon Sep 17 00:00:00 2001 From: kamal-kaur04 <38219887+kamal-kaur04@users.noreply.github.com> Date: Mon, 5 Sep 2022 19:16:51 +0530 Subject: [PATCH 05/50] add new line --- junit-5/src/test/java/runners/BstackRunner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index b95e59c..f3b352b 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -58,4 +58,4 @@ public Object resolveParameter(ParameterContext parameterContext, } }; } -} \ No newline at end of file +} From 873930a7ff7f752d7ca02a1caf3fbd7bd0dcc3ff Mon Sep 17 00:00:00 2001 From: Karan Shah <64479353+karanshah-browserstack@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:36:00 +0530 Subject: [PATCH 06/50] Add userName and accessKey inside url --- .../browserstack/BrowserStackJUnitTest.java | 34 +++++++++++++++--- .../src/test/java/runners/BstackRunner.java | 35 ++++++++++++++++--- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 1fe6afd..a0464da 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -1,29 +1,39 @@ package com.browserstack; -import com.fasterxml.jackson.databind.ObjectMapper; import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; -import org.junit.runner.RunWith; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.RemoteWebDriver; +import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.InputStream; import java.net.URL; import java.nio.file.Files; -import java.util.*; +import java.util.HashMap; +import java.util.Map; public class BrowserStackJUnitTest { public WebDriver driver; + public static String userName, accessKey; + public static Map browserStackYamlMap; + public static final String USER_DIR = "user.dir"; + + public BrowserStackJUnitTest() { + File file = new File(getUserDir() + "/browserstack.yml"); + this.browserStackYamlMap = convertYamlFileToMap(file, new HashMap<>()); + } @Before public void setUp() throws Exception { MutableCapabilities capabilities = new MutableCapabilities(); + userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); + accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); this.driver = new RemoteWebDriver( - new URL("https://hub.browserstack.com/wd/hub"), capabilities); + new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName , accessKey)), capabilities); } public static void mark(WebDriver remoteDriver, String status, String reason) { @@ -41,4 +51,20 @@ public static void mark(WebDriver remoteDriver, String status, String reason) { public void tearDown() { this.driver.quit(); } + + private String getUserDir() { + return System.getProperty(USER_DIR); + } + + private Map convertYamlFileToMap(File yamlFile, Map map) { + try { + InputStream inputStream = Files.newInputStream(yamlFile.toPath()); + Yaml yaml = new Yaml(); + Map config = yaml.load(inputStream); + map.putAll(config); + } catch (Exception e) { + throw new RuntimeException(String.format("Malformed browserstack.yml file - %s.", e)); + } + return map; + } } diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index f3b352b..2c60553 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -1,21 +1,32 @@ package runners; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.junit.jupiter.api.extension.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.yaml.snakeyaml.Yaml; -import java.io.FileReader; +import java.io.File; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; import java.util.*; import java.util.stream.Stream; public class BstackRunner implements TestTemplateInvocationContextProvider { public WebDriver driver; public MutableCapabilities capabilities; + public static String userName, accessKey; + public static Map browserStackYamlMap; + public static final String USER_DIR = "user.dir"; + + public BstackRunner() { + File file = new File(getUserDir() + "/browserstack.yml"); + this.browserStackYamlMap = convertYamlFileToMap(file, new HashMap<>()); + userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); + accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); + } @Override public boolean supportsTestTemplate(ExtensionContext extensionContext) { @@ -48,7 +59,7 @@ public boolean supportsParameter(ParameterContext parameterContext, public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { try { - driver = new RemoteWebDriver(new URL("https://hub.browserstack.com/wd/hub"), caps); + driver = new RemoteWebDriver(new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName, accessKey)), caps); } catch (MalformedURLException e) { e.printStackTrace(); } @@ -58,4 +69,20 @@ public Object resolveParameter(ParameterContext parameterContext, } }; } + + private String getUserDir() { + return System.getProperty(USER_DIR); + } + + private Map convertYamlFileToMap(File yamlFile, Map map) { + try { + InputStream inputStream = Files.newInputStream(yamlFile.toPath()); + Yaml yaml = new Yaml(); + Map config = yaml.load(inputStream); + map.putAll(config); + } catch (Exception e) { + throw new RuntimeException(String.format("Malformed browserstack.yml file - %s.", e)); + } + return map; + } } From 594d229b38069bc3ec3c42f6067df42ac910a3db Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Tue, 1 Nov 2022 14:26:14 +0530 Subject: [PATCH 07/50] add framework key in browserstack.yml --- junit-4/browserstack.yml | 1 + junit-5/browserstack.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index 69eb727..0cd1f98 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -19,6 +19,7 @@ accessKey: BROWSERSTACK_ACCESS_KEY buildName: browserstack-build-1 # Use `projectName` to set the name of your project. Example, Marketing Website projectName: BrowserStack Samples +framework: junit4 # ======================================= # Platforms (Browsers / Devices to test) diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index e311c46..5394dd0 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -19,6 +19,7 @@ accessKey: BROWSERSTACK_ACCESS_KEY buildName: browserstack-build-1 # Use `projectName` to set the name of your project. Example, Marketing Website projectName: BrowserStack Samples +framework: junit5 # ======================================= # Platforms (Browsers / Devices to test) From 3257f4c37c5086a930d5c0be3281da6308ba7078 Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Wed, 9 Nov 2022 17:24:57 +0530 Subject: [PATCH 08/50] change sample local test for junit-4,5 --- junit-4/browserstack.yml | 1 + junit-4/src/test/java/com/browserstack/LocalTest.java | 4 ++-- junit-5/browserstack.yml | 1 + junit-5/src/test/java/tests/LocalTest.java | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index 69eb727..0cd1f98 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -19,6 +19,7 @@ accessKey: BROWSERSTACK_ACCESS_KEY buildName: browserstack-build-1 # Use `projectName` to set the name of your project. Example, Marketing Website projectName: BrowserStack Samples +framework: junit4 # ======================================= # Platforms (Browsers / Devices to test) diff --git a/junit-4/src/test/java/com/browserstack/LocalTest.java b/junit-4/src/test/java/com/browserstack/LocalTest.java index 8c7bee0..1041e5b 100644 --- a/junit-4/src/test/java/com/browserstack/LocalTest.java +++ b/junit-4/src/test/java/com/browserstack/LocalTest.java @@ -12,9 +12,9 @@ public class LocalTest extends BrowserStackJUnitTest { @Test public void test() throws URISyntaxException, IOException { try { - driver.get("http://bs-local.com:45691/check"); + driver.get("http://bs-local.com:45454/"); - assertTrue(driver.getPageSource().contains("Up and running")); + assertTrue(driver.getTitle().contains("BrowserStack Local")); mark(driver, "passed", "Local content validated!"); } catch (Throwable t) { diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index e311c46..5394dd0 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -19,6 +19,7 @@ accessKey: BROWSERSTACK_ACCESS_KEY buildName: browserstack-build-1 # Use `projectName` to set the name of your project. Example, Marketing Website projectName: BrowserStack Samples +framework: junit5 # ======================================= # Platforms (Browsers / Devices to test) diff --git a/junit-5/src/test/java/tests/LocalTest.java b/junit-5/src/test/java/tests/LocalTest.java index ba01b37..4c4ea18 100644 --- a/junit-5/src/test/java/tests/LocalTest.java +++ b/junit-5/src/test/java/tests/LocalTest.java @@ -13,9 +13,9 @@ void localTest(WebDriver driver) { MarkSessionStatus sessionStatus = new MarkSessionStatus(driver); try { - driver.get("http://localhost:45691/check"); - String validateContent = driver.findElement(By.cssSelector("body")).getText(); - if (validateContent.contains("Up and running")) { + driver.get("http://bs-local.com:45454/"); + String validateContent = driver.getTitle(); + if (validateContent.contains("BrowserStack Local")) { sessionStatus.markTestStatus("passed", "Local content validated!"); } else { sessionStatus.markTestStatus("failed", "Local content not validated!"); From 37e17375d9e8e1d4020fd7982a791eff0f546b9e Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Wed, 16 Nov 2022 20:24:15 +0530 Subject: [PATCH 09/50] fix browserstack config comment --- junit-4/browserstack.yml | 4 ++-- junit-5/browserstack.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index 0cd1f98..84a5300 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -45,8 +45,8 @@ platforms: # ========================================== # 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) -# browserStackLocalOptions: +browserstackLocal: true # (Default false) +#browserStackLocalOptions: # Options to be passed to BrowserStack local in-case of advanced configurations # 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. diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index 5394dd0..7087a78 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -46,7 +46,7 @@ platforms: # 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) -# browserStackLocalOptions: +#browserStackLocalOptions: # Options to be passed to BrowserStack local in-case of advanced configurations # 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. From 0672678815f7f7df5b09eaf5ed91bf032bf27bb7 Mon Sep 17 00:00:00 2001 From: Karan Shah <64479353+karanshah-browserstack@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:24:59 +0530 Subject: [PATCH 10/50] Adding buildIdentifier and source changes in yml --- junit-4/browserstack.yml | 46 +++++++++++++++++++++++----------------- junit-5/browserstack.yml | 42 ++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index 84a5300..0b43f6a 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -1,26 +1,31 @@ # ============================= # Set BrowserStack Credentials # ============================= -# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and # BROWSERSTACK_ACCESS_KEY as env variables -userName: BROWSERSTACK_USERNAME -accessKey: BROWSERSTACK_ACCESS_KEY +userName: YOUR_USERNAME +accessKey: YOUR_ACCESS_KEY # ====================== -# Organizing your tests +# BrowserStack Reporting # ====================== -# Use `projectName`, `buildName`, `name` capabilities to organise your tests -# `name` is the name of your test sessions and is automatically picked from your -# test name and doesn't need to be set manually when using BrowserStack SDK -# `buildName` is used to name your CI/CD job or the execution of your test suite. -# Ensure you add a dynamic identifier, like an incremental build number from your -# CI/CD or timestamp at the end of every build; otherwise tests from different -# executions will be grouped together on BrowserStack -buildName: browserstack-build-1 -# Use `projectName` to set the name of your project. Example, Marketing Website -projectName: BrowserStack Samples +# 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 +# `buildIdentifer` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the 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) framework: junit4 +source: junit4:sample-sdk:v1.0 + # ======================================= # Platforms (Browsers / Devices to test) # ======================================= @@ -46,16 +51,17 @@ platforms: # 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) -#browserStackLocalOptions: -# Options to be passed to BrowserStack local in-case of advanced configurations -# 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 +# 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) \ No newline at end of file +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index 7087a78..e8011fb 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -1,26 +1,31 @@ # ============================= # Set BrowserStack Credentials # ============================= -# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and # BROWSERSTACK_ACCESS_KEY as env variables -userName: BROWSERSTACK_USERNAME -accessKey: BROWSERSTACK_ACCESS_KEY +userName: YOUR_USERNAME +accessKey: YOUR_ACCESS_KEY # ====================== -# Organizing your tests +# BrowserStack Reporting # ====================== -# Use `projectName`, `buildName`, `name` capabilities to organise your tests -# `name` is the name of your test sessions and is automatically picked from your -# test name and doesn't need to be set manually when using BrowserStack SDK -# `buildName` is used to name your CI/CD job or the execution of your test suite. -# Ensure you add a dynamic identifier, like an incremental build number from your -# CI/CD or timestamp at the end of every build; otherwise tests from different -# executions will be grouped together on BrowserStack -buildName: browserstack-build-1 -# Use `projectName` to set the name of your project. Example, Marketing Website -projectName: BrowserStack Samples +# 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 +# `buildIdentifer` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the 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) framework: junit5 +source: junit5:sample-sdk:v1.0 + # ======================================= # Platforms (Browsers / Devices to test) # ======================================= @@ -46,16 +51,17 @@ platforms: # 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) -#browserStackLocalOptions: + # 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 - + # 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) \ No newline at end of file +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) From 5b7503eb548c3fa0d5f5474eb046e35216a0f913 Mon Sep 17 00:00:00 2001 From: Karan Shah <64479353+karanshah-browserstack@users.noreply.github.com> Date: Tue, 13 Dec 2022 21:32:53 +0530 Subject: [PATCH 11/50] Fix typo changes --- junit-4/browserstack.yml | 4 ++-- junit-5/browserstack.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index 0b43f6a..d19574a 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -14,8 +14,8 @@ accessKey: YOUR_ACCESS_KEY projectName: BrowserStack Samples # Set `buildName` as the name of the job / testsuite being run buildName: browserstack build -# `buildIdentifer` is a unique id to differentiate every execution that gets appended to -# buildName. Choose your buildIdentifier format from the the available expressions: +# `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 diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index e8011fb..7fed6eb 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -14,8 +14,8 @@ accessKey: YOUR_ACCESS_KEY projectName: BrowserStack Samples # Set `buildName` as the name of the job / testsuite being run buildName: browserstack build -# `buildIdentifer` is a unique id to differentiate every execution that gets appended to -# buildName. Choose your buildIdentifier format from the the available expressions: +# `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 From 0183a4250a24a83dfa6d336f4413df9d5abd2008 Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Fri, 30 Dec 2022 12:57:07 +0530 Subject: [PATCH 12/50] update: junit4 sample changes to support test context out of the box --- junit-4/browserstack.yml | 11 +++++++++ junit-4/pom.xml | 9 ++++++- .../browserstack/BrowserStackJUnitTest.java | 17 ++----------- .../test/java/com/browserstack/LocalTest.java | 14 +++-------- .../java/com/browserstack/SampleTest.java | 24 +++++++------------ 5 files changed, 33 insertions(+), 42 deletions(-) diff --git a/junit-4/browserstack.yml b/junit-4/browserstack.yml index d19574a..2d769ca 100644 --- a/junit-4/browserstack.yml +++ b/junit-4/browserstack.yml @@ -44,6 +44,17 @@ platforms: 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 + # ========================================== # BrowserStack Local # (For localhost, staging/private websites) diff --git a/junit-4/pom.xml b/junit-4/pom.xml index 5b2f3b0..3e79680 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -23,7 +23,7 @@ junit junit - 4.13.1 + 4.13.2 commons-io @@ -66,6 +66,13 @@ org.apache.maven.plugins maven-surefire-plugin ${surefire.version} + + + org.apache.maven.surefire + surefire-junit47 + ${surefire.version} + + com/browserstack/SampleTest.java diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index a0464da..cac0d42 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -1,9 +1,7 @@ package com.browserstack; -import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; -import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.RemoteWebDriver; @@ -32,24 +30,13 @@ public void setUp() throws Exception { MutableCapabilities capabilities = new MutableCapabilities(); userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); - this.driver = new RemoteWebDriver( + driver = new RemoteWebDriver( new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName , accessKey)), capabilities); } - public static void mark(WebDriver remoteDriver, String status, String reason) { - final JavascriptExecutor jse = (JavascriptExecutor) remoteDriver; - JSONObject executorObject = new JSONObject(); - JSONObject argumentsObject = new JSONObject(); - argumentsObject.put("status", status); - argumentsObject.put("reason", reason); - executorObject.put("action", "setSessionStatus"); - executorObject.put("arguments", argumentsObject); - jse.executeScript(String.format("browserstack_executor: %s", executorObject)); - } - @After public void tearDown() { - this.driver.quit(); + driver.quit(); } private String getUserDir() { diff --git a/junit-4/src/test/java/com/browserstack/LocalTest.java b/junit-4/src/test/java/com/browserstack/LocalTest.java index 1041e5b..71d476c 100644 --- a/junit-4/src/test/java/com/browserstack/LocalTest.java +++ b/junit-4/src/test/java/com/browserstack/LocalTest.java @@ -10,16 +10,8 @@ public class LocalTest extends BrowserStackJUnitTest { @Test - public void test() throws URISyntaxException, IOException { - try { - driver.get("http://bs-local.com:45454/"); - - assertTrue(driver.getTitle().contains("BrowserStack Local")); - mark(driver, "passed", "Local content validated!"); - - } catch (Throwable t) { - mark(driver, "failed", "Local content not validated!"); - System.out.println("Exception: " + t); - } + public void test() { + driver.get("http://bs-local.com:45454/"); + assertTrue("Local content not validated!", driver.getTitle().contains("BrowserStack Local")); } } diff --git a/junit-4/src/test/java/com/browserstack/SampleTest.java b/junit-4/src/test/java/com/browserstack/SampleTest.java index d9c1005..ac68112 100644 --- a/junit-4/src/test/java/com/browserstack/SampleTest.java +++ b/junit-4/src/test/java/com/browserstack/SampleTest.java @@ -14,20 +14,14 @@ public class SampleTest extends BrowserStackJUnitTest { @Test public void test() { - try { - driver.get("https://bstackdemo.com/"); - final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); - wait.until(ExpectedConditions.titleIs("StackDemo")); - 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"))); - 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(driver, "passed", "Product has been successfully added to the cart!"); - } catch (Throwable t) { - mark(driver, "failed", "There was some issue!"); - System.out.println("Exception: " + t); - } + driver.get("https://bstackdemo.com/"); + final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + wait.until(ExpectedConditions.titleIs("StackDemo")); + 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"))); + 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 add to the cart - Failed!", product_name.matches(product_in_cart)); } } From 8409313aaacb902eeb746a1d37e6a4e5f3a5e5a9 Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Fri, 30 Dec 2022 13:40:06 +0530 Subject: [PATCH 13/50] update: junit5 sample changes to support test context out of the box --- junit-4/pom.xml | 2 +- junit-5/browserstack.yml | 11 ++++ junit-5/pom.xml | 17 +++--- .../src/test/java/runners/BstackRunner.java | 59 +++++-------------- .../src/test/java/runners/WebDriverTest.java | 18 ------ junit-5/src/test/java/tests/LocalTest.java | 31 +++------- junit-5/src/test/java/tests/SingleTest.java | 42 +++++-------- .../test/java/utils/MarkSessionStatus.java | 25 -------- 8 files changed, 57 insertions(+), 148 deletions(-) delete mode 100644 junit-5/src/test/java/runners/WebDriverTest.java delete mode 100644 junit-5/src/test/java/utils/MarkSessionStatus.java diff --git a/junit-4/pom.xml b/junit-4/pom.xml index 3e79680..e4fe1ba 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -33,7 +33,7 @@ org.seleniumhq.selenium selenium-java - 4.1.0 + 4.1.4 com.googlecode.json-simple diff --git a/junit-5/browserstack.yml b/junit-5/browserstack.yml index 7fed6eb..071d85a 100644 --- a/junit-5/browserstack.yml +++ b/junit-5/browserstack.yml @@ -44,6 +44,17 @@ platforms: 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 + # ========================================== # BrowserStack Local # (For localhost, staging/private websites) diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 2660d64..73efdf5 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -8,28 +8,25 @@ 8 8 - 5.8.1 - 5.4.0 + 5.9.1 1.1 - 4.1.0 + 4.1.4 3.0.0-M5 - 1.30 4.5.13 - 5 **/tests.SingleTest.java **/tests.LocalTest.java org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter-engine} + junit-jupiter-api + ${junit-jupiter.version} test - org.junit.vintage - junit-vintage-engine - ${junit-vintage-engine} + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} test diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index 2c60553..6724ab9 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -1,6 +1,7 @@ package runners; -import org.junit.jupiter.api.extension.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.openqa.selenium.WebDriver; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; @@ -8,15 +9,13 @@ import java.io.File; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; import java.util.*; -import java.util.stream.Stream; -public class BstackRunner implements TestTemplateInvocationContextProvider { +public class BstackRunner { public WebDriver driver; - public MutableCapabilities capabilities; + public static String userName, accessKey; public static Map browserStackYamlMap; public static final String USER_DIR = "user.dir"; @@ -24,50 +23,20 @@ public class BstackRunner implements TestTemplateInvocationContextProvider { public BstackRunner() { File file = new File(getUserDir() + "/browserstack.yml"); this.browserStackYamlMap = convertYamlFileToMap(file, new HashMap<>()); - userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); - accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); } - @Override - public boolean supportsTestTemplate(ExtensionContext extensionContext) { - return true; - } - - @Override - public Stream provideTestTemplateInvocationContexts(ExtensionContext extensionContext) { - List desiredCapsInvocationContexts = new ArrayList<>(); - - capabilities = new MutableCapabilities(); - desiredCapsInvocationContexts.add(invocationContext(capabilities)); - return desiredCapsInvocationContexts.stream(); + @BeforeEach + public void setUp() throws Exception { + MutableCapabilities capabilities = new MutableCapabilities(); + userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); + accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); + driver = new RemoteWebDriver( + new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName , accessKey)), capabilities); } - private TestTemplateInvocationContext invocationContext(MutableCapabilities caps) { - return new TestTemplateInvocationContext() { - - @Override - public List getAdditionalExtensions() { - - return Collections.singletonList(new ParameterResolver() { - @Override - public boolean supportsParameter(ParameterContext parameterContext, - ExtensionContext extensionContext) { - return parameterContext.getParameter().getType().equals(WebDriver.class); - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, - ExtensionContext extensionContext) { - try { - driver = new RemoteWebDriver(new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName, accessKey)), caps); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - return driver; - } - }); - } - }; + @AfterEach + public void tearDown() { + driver.quit(); } private String getUserDir() { diff --git a/junit-5/src/test/java/runners/WebDriverTest.java b/junit-5/src/test/java/runners/WebDriverTest.java deleted file mode 100644 index b68e0df..0000000 --- a/junit-5/src/test/java/runners/WebDriverTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package runners; - -import org.apiguardian.api.API; -import org.junit.jupiter.api.TestTemplate; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.platform.commons.annotation.Testable; - -import java.lang.annotation.*; - -@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@API(status = API.Status.STABLE) -@TestTemplate -@Testable -@ExtendWith(BstackRunner.class) -public @interface WebDriverTest { -} diff --git a/junit-5/src/test/java/tests/LocalTest.java b/junit-5/src/test/java/tests/LocalTest.java index 4c4ea18..4c0ae05 100644 --- a/junit-5/src/test/java/tests/LocalTest.java +++ b/junit-5/src/test/java/tests/LocalTest.java @@ -1,29 +1,16 @@ package tests; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import runners.WebDriverTest; -import utils.MarkSessionStatus; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import runners.BstackRunner; -public class LocalTest { +public class LocalTest extends BstackRunner { - @WebDriverTest - void localTest(WebDriver driver) { - MarkSessionStatus sessionStatus = new MarkSessionStatus(driver); - - try { - driver.get("http://bs-local.com:45454/"); - String validateContent = driver.getTitle(); - if (validateContent.contains("BrowserStack Local")) { - sessionStatus.markTestStatus("passed", "Local content validated!"); - } else { - sessionStatus.markTestStatus("failed", "Local content not validated!"); - } - } catch (Exception e) { - sessionStatus.markTestStatus("failed", "There was some issue!"); - System.out.println(e.getMessage()); - } - driver.quit(); + @Test + void localTest() { + driver.get("http://bs-local.com:45454/"); + String validateContent = driver.getTitle(); + Assertions.assertTrue(validateContent.contains("BrowserStack Local"), "Local content not validated!"); } } diff --git a/junit-5/src/test/java/tests/SingleTest.java b/junit-5/src/test/java/tests/SingleTest.java index 784fe96..68ba878 100644 --- a/junit-5/src/test/java/tests/SingleTest.java +++ b/junit-5/src/test/java/tests/SingleTest.java @@ -1,39 +1,27 @@ package tests; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -import runners.WebDriverTest; -import utils.MarkSessionStatus; +import runners.BstackRunner; import java.time.Duration; -public class SingleTest { +public class SingleTest extends BstackRunner { - @WebDriverTest - void singleTest(WebDriver driver) { - MarkSessionStatus sessionStatus = new MarkSessionStatus(driver); - - try { - driver.get("https://bstackdemo.com/"); - final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); - wait.until(ExpectedConditions.titleIs("StackDemo")); - 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"))); - 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!"); - } else { - sessionStatus.markTestStatus("failed", "There was some issue!"); - } - } catch (Exception e) { - sessionStatus.markTestStatus("failed", "There was some issue!"); - System.out.println("Exception: " + e.getMessage()); - } - driver.quit(); + @Test + void singleTest() { + driver.get("https://bstackdemo.com/"); + final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + wait.until(ExpectedConditions.titleIs("StackDemo")); + 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"))); + 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(); + Assertions.assertTrue(product_name.matches(product_in_cart), "Product add to the cart - Failed!"); } } diff --git a/junit-5/src/test/java/utils/MarkSessionStatus.java b/junit-5/src/test/java/utils/MarkSessionStatus.java deleted file mode 100644 index a106cf4..0000000 --- a/junit-5/src/test/java/utils/MarkSessionStatus.java +++ /dev/null @@ -1,25 +0,0 @@ -package utils; - -import org.json.simple.JSONObject; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import runners.BstackRunner; - -public class MarkSessionStatus extends BstackRunner { - WebDriver webDriver; - - public MarkSessionStatus(WebDriver webDriver) { - this.webDriver = webDriver; - } - - public void markTestStatus(String status, String reason) { - final JavascriptExecutor jse = (JavascriptExecutor) webDriver; - JSONObject executorObject = new JSONObject(); - JSONObject argumentsObject = new JSONObject(); - argumentsObject.put("status", status); - argumentsObject.put("reason", reason); - executorObject.put("action", "setSessionStatus"); - executorObject.put("arguments", argumentsObject); - jse.executeScript(String.format("browserstack_executor: %s", executorObject)); - } -} From bcf8a7ac61ea87472f9355cb81fa44c3ab771c8e Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Fri, 30 Dec 2022 13:50:20 +0530 Subject: [PATCH 14/50] add: source info --- .../src/test/java/com/browserstack/BrowserStackJUnitTest.java | 3 +++ junit-5/src/test/java/runners/BstackRunner.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index cac0d42..12caed8 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -30,6 +30,9 @@ public void setUp() throws Exception { MutableCapabilities capabilities = new MutableCapabilities(); userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); + HashMap bStackOptions = new HashMap<>(); + bStackOptions.put("source", "junit4:sample-sdk:v1.1"); + capabilities.setCapability("bstack:options", bStackOptions); driver = new RemoteWebDriver( new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName , accessKey)), capabilities); } diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index 6724ab9..d60c3f9 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -30,6 +30,9 @@ public void setUp() throws Exception { MutableCapabilities capabilities = new MutableCapabilities(); userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); + HashMap bStackOptions = new HashMap<>(); + bStackOptions.put("source", "junit5:sample-sdk:v1.1"); + capabilities.setCapability("bstack:options", bStackOptions); driver = new RemoteWebDriver( new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName , accessKey)), capabilities); } From 28099bb8bd1ef0e68f4c15f597709c536cc3c5cd Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Wed, 12 Apr 2023 13:44:00 +0530 Subject: [PATCH 15/50] update: source key --- .../src/test/java/com/browserstack/BrowserStackJUnitTest.java | 2 +- junit-5/src/test/java/runners/BstackRunner.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java index 12caed8..f29a840 100644 --- a/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java +++ b/junit-4/src/test/java/com/browserstack/BrowserStackJUnitTest.java @@ -31,7 +31,7 @@ public void setUp() throws Exception { userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); HashMap bStackOptions = new HashMap<>(); - bStackOptions.put("source", "junit4:sample-sdk:v1.1"); + bStackOptions.put("source", "junit4:sample-master:v1.2"); capabilities.setCapability("bstack:options", bStackOptions); driver = new RemoteWebDriver( new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName , accessKey)), capabilities); diff --git a/junit-5/src/test/java/runners/BstackRunner.java b/junit-5/src/test/java/runners/BstackRunner.java index d60c3f9..a759228 100644 --- a/junit-5/src/test/java/runners/BstackRunner.java +++ b/junit-5/src/test/java/runners/BstackRunner.java @@ -31,7 +31,7 @@ public void setUp() throws Exception { userName = System.getenv("BROWSERSTACK_USERNAME") != null ? System.getenv("BROWSERSTACK_USERNAME") : (String) browserStackYamlMap.get("userName"); accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY") != null ? System.getenv("BROWSERSTACK_ACCESS_KEY") : (String) browserStackYamlMap.get("accessKey"); HashMap bStackOptions = new HashMap<>(); - bStackOptions.put("source", "junit5:sample-sdk:v1.1"); + bStackOptions.put("source", "junit5:sample-master:v1.2"); capabilities.setCapability("bstack:options", bStackOptions); driver = new RemoteWebDriver( new URL(String.format("https://%s:%s@hub.browserstack.com/wd/hub", userName , accessKey)), capabilities); From aa05fb22bd8c0ed4424be85ef6164c6dd4c49fe8 Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Mon, 10 Apr 2023 19:47:27 +0530 Subject: [PATCH 16/50] add: event workflow dispatch --- .github/CODEOWNERS | 1 + .github/workflows/maven-workflow-run.yml | 107 +++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/maven-workflow-run.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..7e1f1b4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +.github/* @browserstack/asi-devs diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml new file mode 100644 index 0000000..4920039 --- /dev/null +++ b/.github/workflows/maven-workflow-run.yml @@ -0,0 +1,107 @@ +# This job is to test different maven profiles in sdk branch again Pull Request raised +# This workflow targets Java with Maven execution + +name: Java SDK Test workflow for Maven on workflow_dispatch + +on: + workflow_dispatch: + inputs: + pull_request_number: + description: 'The pull request number to build' + required: true + +jobs: + comment-run: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + max-parallel: 3 + matrix: + java: [ '8', '11', '17' ] + os: [ 'macos-latest', 'windows-latest', 'ubuntu-latest' ] + name: JUnit Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample + env: + BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} + BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} + + steps: + - uses: actions/checkout@v3 + with: + ref: refs/pull/${{ github.event.inputs.pull_request_number }}/head + - name: Fetch Commit SHA + run: | + git log -1 --format='%H' + echo "commit_sha=$(git log -1 --format='%H')" >> $GITHUB_ENV + echo "commit_sha=$(git log -1 --format='%H')" >> $env:GITHUB_ENV + - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 + id: status-check-in-progress + env: + job_name: JUnit Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample + with: + github-token: ${{ github.token }} + script: | + const result = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.job_name, + head_sha: process.env.commit_sha, + status: 'in_progress' + }).catch((err) => ({status: err.status, response: err.response})); + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) + if (result.status !== 201) { + console.log('Failed to create check run') + } + - name: Set up Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} + - name: Change Directory to JUnit-4 + run: cd junit-4 + - name: Run mvn test + run: | + mvn compile + mvn test + - name: Run mvn profile sample + run: | + mvn compile + mvn test -P sample + - name: Run mvn profile local + run: | + mvn compile + mvn test -P local + - name: Change Directory to JUnit-5 + run: cd ../junit-5 + - name: Run mvn test + run: | + mvn compile + mvn test + - name: Run mvn profile single + run: | + mvn compile + mvn test -P single + - name: Run mvn profile local + run: | + mvn compile + mvn test -P local + - if: always() + uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 + id: status-check-completed + env: + conclusion: ${{ job.status }} + job_name: TestNG Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample + with: + github-token: ${{ github.token }} + script: | + const result = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.job_name, + head_sha: process.env.commit_sha, + status: 'completed', + conclusion: process.env.conclusion + }).catch((err) => ({status: err.status, response: err.response})); + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) + if (result.status !== 201) { + console.log('Failed to create check run') + } From 26b2e307ebcb4b2f992ca8b18e754ce3412bc58b Mon Sep 17 00:00:00 2001 From: Kamalpreet Kaur Date: Wed, 12 Apr 2023 12:39:40 +0530 Subject: [PATCH 17/50] fix: job_name --- .github/workflows/maven-workflow-run.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 4920039..e85b73f 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -89,7 +89,7 @@ jobs: id: status-check-completed env: conclusion: ${{ job.status }} - job_name: TestNG Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample + job_name: JUnit Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample with: github-token: ${{ github.token }} script: | From 8277847e589cfde42e57f20169972ce3ef21b6f5 Mon Sep 17 00:00:00 2001 From: bstack-security-github <116066275+bstack-security-github@users.noreply.github.com> Date: Wed, 21 Jun 2023 17:22:48 +0530 Subject: [PATCH 18/50] Adding Code Scanner Semgrep.yml workflow file --- .github/workflows/Semgrep.yml | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/Semgrep.yml diff --git a/.github/workflows/Semgrep.yml b/.github/workflows/Semgrep.yml new file mode 100644 index 0000000..0347afd --- /dev/null +++ b/.github/workflows/Semgrep.yml @@ -0,0 +1,48 @@ +# Name of this GitHub Actions workflow. +name: Semgrep + +on: + # Scan changed files in PRs (diff-aware scanning): + # The branches below must be a subset of the branches above + pull_request: + branches: ["master", "main"] + push: + branches: ["master", "main"] + schedule: + - cron: '0 6 * * *' + + +permissions: + contents: read + +jobs: + semgrep: + # User definable name of this GitHub Actions job. + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + name: semgrep/ci + # If you are self-hosting, change the following `runs-on` value: + runs-on: ubuntu-latest + + container: + # A Docker image with Semgrep installed. Do not change this. + image: returntocorp/semgrep + + # Skip any PR created by dependabot to avoid permission issues: + if: (github.actor != 'dependabot[bot]') + + steps: + # Fetch project source with GitHub Actions Checkout. + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + # Run the "semgrep ci" command on the command line of the docker image. + - run: semgrep ci --sarif --output=semgrep.sarif + env: + # Add the rules that Semgrep uses by setting the SEMGREP_RULES environment variable. + SEMGREP_RULES: p/default # more at semgrep.dev/explore + + - name: Upload SARIF file for GitHub Advanced Security Dashboard + uses: github/codeql-action/upload-sarif@6c089f53dd51dc3fc7e599c3cb5356453a52ca9e # v2.20.0 + with: + sarif_file: semgrep.sarif + if: always() \ No newline at end of file From ff62105461867dec7312b39dda7c8908ad431b15 Mon Sep 17 00:00:00 2001 From: bstack-security-github <116066275+bstack-security-github@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:32:28 +0530 Subject: [PATCH 19/50] Adding CODEOWNERS file --- .github/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7e1f1b4..09a587d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,3 @@ .github/* @browserstack/asi-devs + +* @browserstack/automate-public-repos From 4e6913168fa325a34b208c37496867a992056dec Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 7 Jul 2023 16:30:11 +0530 Subject: [PATCH 20/50] Fix workflow file --- .github/workflows/maven-workflow-run.yml | 35 ++++++++++++------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index e85b73f..8bd8997 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -6,8 +6,8 @@ name: Java SDK Test workflow for Maven on workflow_dispatch on: workflow_dispatch: inputs: - pull_request_number: - description: 'The pull request number to build' + commit_sha: + description: 'The commit id to build' required: true jobs: @@ -27,16 +27,12 @@ jobs: steps: - uses: actions/checkout@v3 with: - ref: refs/pull/${{ github.event.inputs.pull_request_number }}/head - - name: Fetch Commit SHA - run: | - git log -1 --format='%H' - echo "commit_sha=$(git log -1 --format='%H')" >> $GITHUB_ENV - echo "commit_sha=$(git log -1 --format='%H')" >> $env:GITHUB_ENV + ref: ${{ github.event.inputs.commit_sha }} - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 id: status-check-in-progress env: job_name: JUnit Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample + commit_sha: ${{ github.event.inputs.commit_sha }} with: github-token: ${{ github.token }} script: | @@ -56,32 +52,34 @@ jobs: with: distribution: 'temurin' java-version: ${{ matrix.java }} - - name: Change Directory to JUnit-4 - run: cd junit-4 - - name: Run mvn test + - name: Run mvn test for junit-4 run: | + cd junit-4 mvn compile mvn test - - name: Run mvn profile sample + - name: Run mvn profile sample for junit-4 run: | + cd junit-4 mvn compile mvn test -P sample - - name: Run mvn profile local + - name: Run mvn profile local for junit-4 run: | + cd junit-4 mvn compile mvn test -P local - - name: Change Directory to JUnit-5 - run: cd ../junit-5 - - name: Run mvn test + - name: Run mvn test for junit-5 run: | + cd junit-5 mvn compile mvn test - - name: Run mvn profile single + - name: Run mvn profile single for junit-5 run: | + cd junit-5 mvn compile mvn test -P single - - name: Run mvn profile local + - name: Run mvn profile local for junit-5 run: | + cd junit-5 mvn compile mvn test -P local - if: always() @@ -90,6 +88,7 @@ jobs: env: conclusion: ${{ job.status }} job_name: JUnit Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample + commit_sha: ${{ github.event.inputs.commit_sha }} with: github-token: ${{ github.token }} script: | From bef1ef8b9db6249ebe46c27f2d2776ebbdc0e390 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 10 Jul 2023 12:58:44 +0530 Subject: [PATCH 21/50] Fix workflow file --- .github/workflows/maven-workflow-run.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 8bd8997..7c9a66c 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: inputs: commit_sha: - description: 'The commit id to build' + description: 'The full commit id to build' required: true jobs: From 87965cb061b71ee00325c8d9d2abbbc4131d9592 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Thu, 15 Jun 2023 18:08:20 +0530 Subject: [PATCH 22/50] Added BStack to files to add to session name --- junit-4/README.md | 4 ++-- junit-4/pom.xml | 10 +++++----- .../{LocalTest.java => BStackLocalTest.java} | 2 +- .../{SampleTest.java => BStackSampleTest.java} | 2 +- junit-5/README.md | 4 ++-- junit-5/pom.xml | 8 ++++---- .../tests/{LocalTest.java => BStackLocalTest.java} | 2 +- .../tests/{SingleTest.java => BStackSampleTest.java} | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) rename junit-4/src/test/java/com/browserstack/{LocalTest.java => BStackLocalTest.java} (85%) rename junit-4/src/test/java/com/browserstack/{SampleTest.java => BStackSampleTest.java} (95%) rename junit-5/src/test/java/tests/{LocalTest.java => BStackLocalTest.java} (87%) rename junit-5/src/test/java/tests/{SingleTest.java => BStackSampleTest.java} (94%) diff --git a/junit-4/README.md b/junit-4/README.md index 856f86c..829102a 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -11,8 +11,8 @@ * Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). ## Running your tests -* To run a parallel test, run `mvn test -P sample` -* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `mvn test -P local` +* To run a parallel test, run `mvn test -P sample-test` +* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and 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) diff --git a/junit-4/pom.xml b/junit-4/pom.xml index e4fe1ba..3e97378 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -75,7 +75,7 @@ - com/browserstack/SampleTest.java + com/browserstack/BStackSampleTest.java -javaagent:${com.browserstack:browserstack-java-sdk:jar} @@ -87,7 +87,7 @@ - sample + sample-test @@ -95,7 +95,7 @@ maven-surefire-plugin - com/browserstack/SampleTest.java + com/browserstack/BStackSampleTest.java -javaagent:${com.browserstack:browserstack-java-sdk:jar} @@ -107,7 +107,7 @@ - local + sample-local-test @@ -115,7 +115,7 @@ maven-surefire-plugin - com/browserstack/LocalTest.java + com/browserstack/BStackLocalTest.java -javaagent:${com.browserstack:browserstack-java-sdk:jar} diff --git a/junit-4/src/test/java/com/browserstack/LocalTest.java b/junit-4/src/test/java/com/browserstack/BStackLocalTest.java similarity index 85% rename from junit-4/src/test/java/com/browserstack/LocalTest.java rename to junit-4/src/test/java/com/browserstack/BStackLocalTest.java index 71d476c..d57f90c 100644 --- a/junit-4/src/test/java/com/browserstack/LocalTest.java +++ b/junit-4/src/test/java/com/browserstack/BStackLocalTest.java @@ -7,7 +7,7 @@ import static org.junit.Assert.assertTrue; -public class LocalTest extends BrowserStackJUnitTest { +public class BStackLocalTest extends BrowserStackJUnitTest { @Test public void test() { diff --git a/junit-4/src/test/java/com/browserstack/SampleTest.java b/junit-4/src/test/java/com/browserstack/BStackSampleTest.java similarity index 95% rename from junit-4/src/test/java/com/browserstack/SampleTest.java rename to junit-4/src/test/java/com/browserstack/BStackSampleTest.java index ac68112..f8535f4 100644 --- a/junit-4/src/test/java/com/browserstack/SampleTest.java +++ b/junit-4/src/test/java/com/browserstack/BStackSampleTest.java @@ -10,7 +10,7 @@ import static org.junit.Assert.assertTrue; -public class SampleTest extends BrowserStackJUnitTest { +public class BStackSampleTest extends BrowserStackJUnitTest { @Test public void test() { diff --git a/junit-5/README.md b/junit-5/README.md index bd917a0..06bb5be 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -10,8 +10,8 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3** * Update `browserstack.yml` files inside the root 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 local tests, run `mvn test -P local` +* To run a single test, 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) diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 73efdf5..1b24d92 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -13,8 +13,8 @@ 4.1.4 3.0.0-M5 4.5.13 - **/tests.SingleTest.java - **/tests.LocalTest.java + **/tests.BStackSampleTest.java + **/tests.BStackLocalTest.java @@ -89,7 +89,7 @@ - single + sample-test @@ -110,7 +110,7 @@ - local + sample-local-test diff --git a/junit-5/src/test/java/tests/LocalTest.java b/junit-5/src/test/java/tests/BStackLocalTest.java similarity index 87% rename from junit-5/src/test/java/tests/LocalTest.java rename to junit-5/src/test/java/tests/BStackLocalTest.java index 4c0ae05..75a4872 100644 --- a/junit-5/src/test/java/tests/LocalTest.java +++ b/junit-5/src/test/java/tests/BStackLocalTest.java @@ -5,7 +5,7 @@ import runners.BstackRunner; -public class LocalTest extends BstackRunner { +public class BStackLocalTest extends BstackRunner { @Test void localTest() { diff --git a/junit-5/src/test/java/tests/SingleTest.java b/junit-5/src/test/java/tests/BStackSampleTest.java similarity index 94% rename from junit-5/src/test/java/tests/SingleTest.java rename to junit-5/src/test/java/tests/BStackSampleTest.java index 68ba878..c9e8303 100644 --- a/junit-5/src/test/java/tests/SingleTest.java +++ b/junit-5/src/test/java/tests/BStackSampleTest.java @@ -10,10 +10,10 @@ import java.time.Duration; -public class SingleTest extends BstackRunner { +public class BStackSampleTest extends BstackRunner { @Test - void singleTest() { + void sampleTest() { driver.get("https://bstackdemo.com/"); final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.titleIs("StackDemo")); From a374877dc6ae304ef0a6826a45aa2f99fe9634bf Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Thu, 15 Jun 2023 18:28:55 +0530 Subject: [PATCH 23/50] Fix --- junit-5/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/junit-5/pom.xml b/junit-5/pom.xml index 1b24d92..a37d797 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -13,7 +13,7 @@ 4.1.4 3.0.0-M5 4.5.13 - **/tests.BStackSampleTest.java + **/tests.BStackSampleTest.java **/tests.BStackLocalTest.java @@ -77,7 +77,7 @@ ${maven-surefire-plugin} - ${tests.single} + ${tests.sample} -javaagent:${com.browserstack:browserstack-java-sdk:jar} @@ -98,7 +98,7 @@ 3.0.0-M5 - ${tests.single} + ${tests.sample} -javaagent:${com.browserstack:browserstack-java-sdk:jar} From cf99377f4ef4397b72c0e6e6d03ca9b271316ee6 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 23 Jun 2023 17:10:02 +0530 Subject: [PATCH 24/50] name fixes --- junit-4/README.md | 4 ++-- junit-4/pom.xml | 4 ++-- junit-5/README.md | 4 ++-- junit-5/pom.xml | 8 ++++---- junit-5/src/test/java/tests/BStackSampleTest.java | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/junit-4/README.md b/junit-4/README.md index 829102a..856f86c 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -11,8 +11,8 @@ * Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). ## Running your tests -* To run a parallel test, run `mvn test -P sample-test` -* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `mvn test -P sample-local-test` +* To run a parallel test, run `mvn test -P sample` +* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `mvn test -P local` 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 3e97378..4919171 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -87,7 +87,7 @@ - sample-test + sample @@ -107,7 +107,7 @@ - sample-local-test + local diff --git a/junit-5/README.md b/junit-5/README.md index 06bb5be..bd917a0 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -10,8 +10,8 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3** * Update `browserstack.yml` files inside the root 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 sample-test` -* To run local tests, run `mvn test -P sample-local-test` +* To run a single test, run `mvn test -P single` +* To run local tests, run `mvn test -P local` 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 a37d797..ddb31e1 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -13,7 +13,7 @@ 4.1.4 3.0.0-M5 4.5.13 - **/tests.BStackSampleTest.java + **/tests.BStackSampleTest.java **/tests.BStackLocalTest.java @@ -89,7 +89,7 @@ - sample-test + single @@ -98,7 +98,7 @@ 3.0.0-M5 - ${tests.sample} + ${tests.single} -javaagent:${com.browserstack:browserstack-java-sdk:jar} @@ -110,7 +110,7 @@ - sample-local-test + local diff --git a/junit-5/src/test/java/tests/BStackSampleTest.java b/junit-5/src/test/java/tests/BStackSampleTest.java index c9e8303..74f55ce 100644 --- a/junit-5/src/test/java/tests/BStackSampleTest.java +++ b/junit-5/src/test/java/tests/BStackSampleTest.java @@ -13,7 +13,7 @@ public class BStackSampleTest extends BstackRunner { @Test - void sampleTest() { + void singleTest() { driver.get("https://bstackdemo.com/"); final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.titleIs("StackDemo")); From 1700e8babc45d245f573eb17cc7a5fbcaa184747 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 23 Jun 2023 17:10:55 +0530 Subject: [PATCH 25/50] name fixes --- junit-5/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit-5/pom.xml b/junit-5/pom.xml index ddb31e1..ed36d6e 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -77,7 +77,7 @@ ${maven-surefire-plugin} - ${tests.sample} + ${tests.single} -javaagent:${com.browserstack:browserstack-java-sdk:jar} From e2e76cbb1fe76f661851f605571735c65f57d16f Mon Sep 17 00:00:00 2001 From: Shirish Kamath Date: Thu, 25 Apr 2024 21:52:54 +0530 Subject: [PATCH 26/50] Added snakeyaml dependency --- junit-4/pom.xml | 6 ++++++ junit-5/pom.xml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/junit-4/pom.xml b/junit-4/pom.xml index 4919171..7841694 100644 --- a/junit-4/pom.xml +++ b/junit-4/pom.xml @@ -14,6 +14,7 @@ UTF-8 3.0.0-M5 default + 2.2 1.8 1.8 @@ -40,6 +41,11 @@ json-simple 1.1.1 + + org.yaml + snakeyaml + ${snakeyaml.version} + com.browserstack browserstack-java-sdk diff --git a/junit-5/pom.xml b/junit-5/pom.xml index ed36d6e..871c15e 100644 --- a/junit-5/pom.xml +++ b/junit-5/pom.xml @@ -13,6 +13,7 @@ 4.1.4 3.0.0-M5 4.5.13 + 2.2 **/tests.BStackSampleTest.java **/tests.BStackLocalTest.java @@ -50,6 +51,11 @@ httpclient ${httpclient} + + org.yaml + snakeyaml + ${snakeyaml.version} + com.browserstack browserstack-java-sdk From ac26750923f3e21f7fb29d1fb9c9d898ecb06ec0 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 23 Aug 2024 11:41:52 +0530 Subject: [PATCH 27/50] SDKAD-153 Added gradle config for JUnit5 --- junit-5/README.md | 40 +++++++++++++++++++++++++++++++++++++-- junit-5/build.gradle | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 junit-5/build.gradle diff --git a/junit-5/README.md b/junit-5/README.md index bd917a0..2cb99ce 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -4,16 +4,52 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3** -## Setup +## Using Maven +### Setup * Clone the repo * Install dependencies `mvn install` * Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). -## Running your tests +### Running your tests * To run a single test, run `mvn test -P single` * To run local tests, run `mvn test -P local` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) +## Using Gradle + +### Prerequisites +- If using Gradle, Java v9+ is required. + +### Setup +- Clone the repository +- Install dependencies `gradle build` + +### Running your tests +- To run the single test, run `gradle single` +- To run local tests, run `gradle local` + +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) + +### Integrate your test suite + +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: + +* Following are the changes required in `gradle.build` - + * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies + * Fetch Artifact Information and add `jvmArgs` property in tasks *SingleTest* and *LocalTest* : + ``` + def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + + task single(type: Test) { + dependsOn cleanTest + include '**/*BStackSampleTest.*' + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + useJUnitPlatform() + } + ``` + +* Install dependencies `gradle build` + ## Notes * You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) diff --git a/junit-5/build.gradle b/junit-5/build.gradle new file mode 100644 index 0000000..47da4b3 --- /dev/null +++ b/junit-5/build.gradle @@ -0,0 +1,45 @@ +plugins { + id 'java' +} + +repositories { mavenCentral() } + +dependencies { + implementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' + implementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1' + implementation 'org.junit.platform:junit-platform-console:1.8.1' + implementation 'org.seleniumhq.selenium:selenium-java:4.22.0' + implementation 'com.browserstack:browserstack-local-java:1.0.6' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' + implementation 'org.yaml:snakeyaml:2.2' + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'junit-browserstack' +sourceCompatibility = '1.8' + +def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Test) { + systemProperties = System.properties +} + +task single(type: Test) { + dependsOn cleanTest + include '**/*BStackSampleTest.*' + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + useJUnitPlatform() +} + +task local(type: Test) { + dependsOn cleanTest + include '**/*BStackLocalTest.*' + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + useJUnitPlatform() +} From d8cf4830f4dcbda1fd17dcf8b2b3143ed85b4f2e Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 23 Aug 2024 12:00:11 +0530 Subject: [PATCH 28/50] SDKAD-153 Removed implementation 'com.browserstack:browserstack-local-java:1.0.6' dependency --- junit-5/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/junit-5/build.gradle b/junit-5/build.gradle index 47da4b3..aa95a68 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -9,7 +9,6 @@ dependencies { implementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1' implementation 'org.junit.platform:junit-platform-console:1.8.1' implementation 'org.seleniumhq.selenium:selenium-java:4.22.0' - implementation 'com.browserstack:browserstack-local-java:1.0.6' implementation 'com.googlecode.json-simple:json-simple:1.1.1' implementation 'org.yaml:snakeyaml:2.2' implementation 'com.browserstack:browserstack-java-sdk:latest.release' From 8773751b2c44896fc3d876c78c33933900b5ea1f Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 23 Aug 2024 13:12:50 +0530 Subject: [PATCH 29/50] SDKAD-153 Removed dependencies that are not needed --- junit-5/build.gradle | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/junit-5/build.gradle b/junit-5/build.gradle index aa95a68..a9f0412 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -7,10 +7,7 @@ repositories { mavenCentral() } dependencies { implementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' implementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1' - implementation 'org.junit.platform:junit-platform-console:1.8.1' implementation 'org.seleniumhq.selenium:selenium-java:4.22.0' - implementation 'com.googlecode.json-simple:json-simple:1.1.1' - implementation 'org.yaml:snakeyaml:2.2' implementation 'com.browserstack:browserstack-java-sdk:latest.release' } @@ -19,8 +16,6 @@ version = '1.0-SNAPSHOT' description = 'junit-browserstack' sourceCompatibility = '1.8' -def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } - tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } @@ -29,16 +24,22 @@ tasks.withType(Test) { systemProperties = System.properties } +tasks.withType(Test).configureEach { task -> + doFirst { + configurations.testRuntimeClasspath + ?.find { it.name.startsWith("browserstack-java-sdk") } + ?.with { task.jvmArgs += "-javaagent:$it" } + } +} + task single(type: Test) { dependsOn cleanTest include '**/*BStackSampleTest.*' - jvmArgs "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } task local(type: Test) { dependsOn cleanTest include '**/*BStackLocalTest.*' - jvmArgs "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } From 75b4d6b08615cede8b977288c11bb2af26d33d7d Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 23 Aug 2024 14:41:46 +0530 Subject: [PATCH 30/50] SDKAD-153 Made gradle config similar to TestNg config --- junit-5/build.gradle | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/junit-5/build.gradle b/junit-5/build.gradle index a9f0412..090b079 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -16,6 +16,8 @@ version = '1.0-SNAPSHOT' description = 'junit-browserstack' sourceCompatibility = '1.8' +def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } @@ -24,22 +26,16 @@ tasks.withType(Test) { systemProperties = System.properties } -tasks.withType(Test).configureEach { task -> - doFirst { - configurations.testRuntimeClasspath - ?.find { it.name.startsWith("browserstack-java-sdk") } - ?.with { task.jvmArgs += "-javaagent:$it" } - } -} - task single(type: Test) { dependsOn cleanTest include '**/*BStackSampleTest.*' + jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } task local(type: Test) { dependsOn cleanTest include '**/*BStackLocalTest.*' + jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } From 1fc0bab799a623491c487a98c33cfd36b5182ec5 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 23 Aug 2024 16:33:26 +0530 Subject: [PATCH 31/50] SDKAD-153 Updated gradle config --- junit-5/build.gradle | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/junit-5/build.gradle b/junit-5/build.gradle index 090b079..02cee56 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -16,26 +16,27 @@ version = '1.0-SNAPSHOT' description = 'junit-browserstack' sourceCompatibility = '1.8' -def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } +def browserstackSDKArtifact = configurations?.compileClasspath?.resolvedConfiguration?.resolvedArtifacts?.find { it.name == 'browserstack-java-sdk' } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -tasks.withType(Test) { - systemProperties = System.properties +tasks.withType(Test).configureEach { task -> + browserstackSDKArtifact?.file?.with { + task.systemProperties = System.properties + task.jvmArgs += "-javaagent:$it" + } } task single(type: Test) { dependsOn cleanTest include '**/*BStackSampleTest.*' - jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } task local(type: Test) { dependsOn cleanTest include '**/*BStackLocalTest.*' - jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } From 066f358a79bc9839e848fee4cb91fee3cb6d0362 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 23 Aug 2024 16:35:34 +0530 Subject: [PATCH 32/50] SDKAD-153 Updated gradle config in readme --- junit-5/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/junit-5/README.md b/junit-5/README.md index 2cb99ce..2ac58cf 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -39,11 +39,15 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t * Fetch Artifact Information and add `jvmArgs` property in tasks *SingleTest* and *LocalTest* : ``` def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } - + tasks.withType(Test).configureEach { task -> + browserstackSDKArtifact?.file?.with { + task.systemProperties = System.properties + task.jvmArgs += "-javaagent:$it" + } + } task single(type: Test) { dependsOn cleanTest include '**/*BStackSampleTest.*' - jvmArgs "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } ``` From 9301ae22f52b459e3194cf6dfb14c1ce5ebfb7c5 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Mon, 26 Aug 2024 18:07:49 +0530 Subject: [PATCH 33/50] SDKAD-153 Added gradle config for junit4 --- junit-4/README.md | 43 +++++++++++++++++++++++++++++++++++++++++-- junit-4/build.gradle | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 junit-4/build.gradle diff --git a/junit-4/README.md b/junit-4/README.md index 856f86c..4c03a2b 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -5,17 +5,56 @@ ![JUnit](http://junit.org/junit4/images/junit-logo.png) -## Setup +## Using Maven + +### Setup * Clone the repo * Install dependencies `mvn install` * Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). -## Running your tests +### Running your tests * To run a parallel test, run `mvn test -P sample` * To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `mvn test -P local` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) + +## Using Gradle + +### Prerequisites +- If using Gradle, Java v9+ is required. + +### Setup +* Clone the repo +* Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). + +### Running your tests +* To run a parallel test, run `gradle sample` +* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `gradle local` + +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) + +### Integrate your test suite + +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: + +* Following are the changes required in `build.gradle` - + * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies + * Fetch Artifact Information and add `jvmArgs` property in tasks *Sample* and *Local* : + ``` + def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + + task sample(type: Test) { + useJUnit() { + dependsOn cleanTest + include '**/*BStackSampleTest.*' + jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" + } + } + ``` + +* Install dependencies and run the test `gradle sample` + ## Notes * You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) * To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser) diff --git a/junit-4/build.gradle b/junit-4/build.gradle new file mode 100644 index 0000000..8db08af --- /dev/null +++ b/junit-4/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'java' +} + +repositories { mavenCentral() } + +dependencies { + implementation 'junit:junit:4.13.2' + implementation 'org.seleniumhq.selenium:selenium-java:4.1.4' + implementation 'org.yaml:snakeyaml:2.2' + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'junit-browserstack' +sourceCompatibility = '1.8' + +def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Test) { + systemProperties = System.properties + jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" +} + +task sample(type: Test) { + useJUnit() { + dependsOn cleanTest + include '**/*BStackSampleTest.*' + } +} + +task local(type: Test) { + useJUnit() { + dependsOn cleanTest + include '**/*BStackLocalTest.*' + } +} From c07740e6edb200614bd9f4c7c76915650b40ad94 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Mon, 26 Aug 2024 18:18:19 +0530 Subject: [PATCH 34/50] SDKAD-153 Updated readme for gradle config for JUnit5 --- junit-5/README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/junit-5/README.md b/junit-5/README.md index 2ac58cf..6f1829b 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -5,6 +5,7 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3** ## Using Maven + ### Setup * Clone the repo * Install dependencies `mvn install` @@ -15,6 +16,7 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3** * To run local tests, run `mvn test -P local` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) + ## Using Gradle ### Prerequisites @@ -39,15 +41,11 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t * Fetch Artifact Information and add `jvmArgs` property in tasks *SingleTest* and *LocalTest* : ``` def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } - tasks.withType(Test).configureEach { task -> - browserstackSDKArtifact?.file?.with { - task.systemProperties = System.properties - task.jvmArgs += "-javaagent:$it" - } - } + task single(type: Test) { dependsOn cleanTest include '**/*BStackSampleTest.*' + jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" useJUnitPlatform() } ``` From 710f345cfcd628f1c06414cc5321d894f4b2f3d5 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 30 Aug 2024 18:13:21 +0530 Subject: [PATCH 35/50] SDKAD-153 Added gradle test run to github workflow --- .github/workflows/maven-workflow-run.yml | 8 ++++++++ junit-4/build.gradle | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 7c9a66c..2c1c32a 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -67,6 +67,14 @@ jobs: cd junit-4 mvn compile mvn test -P local + - name: Run gradle task sampleTest + run: | + cd junit-4 + gradle clean sampleTest + - name: Run gradle task sampleLocalTest + run: | + cd junit-4 + gradle clean sampleLocalTest - name: Run mvn test for junit-5 run: | cd junit-5 diff --git a/junit-4/build.gradle b/junit-4/build.gradle index 8db08af..7f0ab23 100644 --- a/junit-4/build.gradle +++ b/junit-4/build.gradle @@ -27,14 +27,14 @@ tasks.withType(Test) { jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" } -task sample(type: Test) { +task sampleTest(type: Test) { useJUnit() { dependsOn cleanTest include '**/*BStackSampleTest.*' } } -task local(type: Test) { +task sampleLocalTest(type: Test) { useJUnit() { dependsOn cleanTest include '**/*BStackLocalTest.*' From 6d784e97acd61bfb3056d6a6b754d2fbeaa4d498 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 30 Aug 2024 18:14:29 +0530 Subject: [PATCH 36/50] SDKAD-153 Added gradle test run to github workflow --- .github/workflows/maven-workflow-run.yml | 8 ++++++++ junit-5/build.gradle | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 7c9a66c..9ff52fc 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -82,6 +82,14 @@ jobs: cd junit-5 mvn compile mvn test -P local + - name: Run gradle task sampleTest + run: | + cd junit-5 + gradle clean sampleTest + - name: Run gradle task sampleLocalTest + run: | + cd junit-5 + gradle clean sampleLocalTest - if: always() uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 id: status-check-completed diff --git a/junit-5/build.gradle b/junit-5/build.gradle index 02cee56..07bd022 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -29,13 +29,13 @@ tasks.withType(Test).configureEach { task -> } } -task single(type: Test) { +task sampleTest(type: Test) { dependsOn cleanTest include '**/*BStackSampleTest.*' useJUnitPlatform() } -task local(type: Test) { +task sampleLocalTest(type: Test) { dependsOn cleanTest include '**/*BStackLocalTest.*' useJUnitPlatform() From d26e7ac80187be1be6b8ff6b93eceb2af471d813 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 30 Aug 2024 18:26:47 +0530 Subject: [PATCH 37/50] SDKAD-153 Updated task name in readme --- junit-5/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/junit-5/README.md b/junit-5/README.md index 6f1829b..9e8d805 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -27,8 +27,8 @@ Understand how many parallel sessions you need by using our [Parallel Test Calcu - Install dependencies `gradle build` ### Running your tests -- To run the single test, run `gradle single` -- To run local tests, run `gradle local` +- To run the single test, 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) @@ -42,7 +42,7 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t ``` def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } - task single(type: Test) { + task sampleTest(type: Test) { dependsOn cleanTest include '**/*BStackSampleTest.*' jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" From 7192a4d37816076354517788e43c5c8601940d49 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Fri, 30 Aug 2024 18:27:56 +0530 Subject: [PATCH 38/50] SDKAD-153 Updated task name in readme --- junit-4/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/junit-4/README.md b/junit-4/README.md index 4c03a2b..38e7da0 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -29,8 +29,8 @@ * Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). ### Running your tests -* To run a parallel test, run `gradle sample` -* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `gradle local` +* To run a parallel test, run `gradle sampleTest` +* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and 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) @@ -44,7 +44,7 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t ``` def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } - task sample(type: Test) { + task sampleTest(type: Test) { useJUnit() { dependsOn cleanTest include '**/*BStackSampleTest.*' From 0eb4c21e0c0c749a8e9e06ce7784c3c506f1c26a Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Tue, 8 Oct 2024 16:58:39 +0530 Subject: [PATCH 39/50] Added config for gradle plugin --- junit-5/build.gradle | 1 + junit-5/settings.gradle | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 junit-5/settings.gradle diff --git a/junit-5/build.gradle b/junit-5/build.gradle index 07bd022..a1dfffd 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'com.browserstack.gradle-sdk' version "1.0.0" // sdk plugin } repositories { mavenCentral() } diff --git a/junit-5/settings.gradle b/junit-5/settings.gradle new file mode 100644 index 0000000..2a39923 --- /dev/null +++ b/junit-5/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + gradlePluginPortal() + } + + resolutionStrategy { + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.0.0") + } + } + } +} From 41aa1cf7007e32e5f25b6d11e5a8173219b65556 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Tue, 8 Oct 2024 17:00:24 +0530 Subject: [PATCH 40/50] Added config for gradle plugin --- junit-4/build.gradle | 1 + junit-4/settings.gradle | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 junit-4/settings.gradle diff --git a/junit-4/build.gradle b/junit-4/build.gradle index 7f0ab23..d647536 100644 --- a/junit-4/build.gradle +++ b/junit-4/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'com.browserstack.gradle-sdk' version "1.0.0" // sdk plugin } repositories { mavenCentral() } diff --git a/junit-4/settings.gradle b/junit-4/settings.gradle new file mode 100644 index 0000000..2a39923 --- /dev/null +++ b/junit-4/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + gradlePluginPortal() + } + + resolutionStrategy { + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.0.0") + } + } + } +} From b30cb0c8e8dc2d6d5707d41df749a8c82d37d1b9 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Tue, 8 Oct 2024 17:11:51 +0530 Subject: [PATCH 41/50] Updated readme to add gradle plugin for integration --- junit-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/junit-4/README.md b/junit-4/README.md index 38e7da0..3979bb7 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -39,6 +39,7 @@ Understand how many parallel sessions you need by using our [Parallel Test Calcu 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: * Following are the changes required in `build.gradle` - + * Add `id 'com.browserstack.gradle-sdk' version "1.0.0"` in plugins * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies * Fetch Artifact Information and add `jvmArgs` property in tasks *Sample* and *Local* : ``` From 49710a3b237f6396f65b1c61ba65a6b914fc45ca Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Tue, 8 Oct 2024 17:13:06 +0530 Subject: [PATCH 42/50] Updated readme to add gradle plugin for integration --- junit-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/junit-5/README.md b/junit-5/README.md index 9e8d805..5750187 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -37,6 +37,7 @@ Understand how many parallel sessions you need by using our [Parallel Test Calcu 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: * Following are the changes required in `gradle.build` - + * Add `id 'com.browserstack.gradle-sdk' version "1.0.0"` in plugins * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies * Fetch Artifact Information and add `jvmArgs` property in tasks *SingleTest* and *LocalTest* : ``` From 7e03b8e742477e78463fc034e6f4c423dcd34f4b Mon Sep 17 00:00:00 2001 From: Aaryan Date: Wed, 22 Jan 2025 17:01:20 +0530 Subject: [PATCH 43/50] add gradle in gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 87f8a89..272a376 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ local.log *.png *.txt **/logs +bstack_* +gradlew* +gradle From d352b8a3ad676715d9c4d08c43e834d7e91f6813 Mon Sep 17 00:00:00 2001 From: Aaryan Date: Wed, 22 Jan 2025 17:01:38 +0530 Subject: [PATCH 44/50] exclude java 8 for mac os latest --- .github/workflows/maven-workflow-run.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 5b00b10..4f83b92 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -19,6 +19,9 @@ jobs: matrix: java: [ '8', '11', '17' ] os: [ 'macos-latest', 'windows-latest', 'ubuntu-latest' ] + exclude: + - java: '8' + os: 'macos-latest' name: JUnit Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample env: BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} From d821c4aeffb25e37fea2786aba189359ea5dae7a Mon Sep 17 00:00:00 2001 From: Aaryan Date: Wed, 22 Jan 2025 17:02:12 +0530 Subject: [PATCH 45/50] Fix gradle-sdk plugin version for junit4 --- junit-4/build.gradle | 2 +- junit-4/settings.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/junit-4/build.gradle b/junit-4/build.gradle index d647536..fce6feb 100644 --- a/junit-4/build.gradle +++ b/junit-4/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'com.browserstack.gradle-sdk' version "1.0.0" // sdk plugin + id 'com.browserstack.gradle-sdk' version "1.1.2" // sdk plugin } repositories { mavenCentral() } diff --git a/junit-4/settings.gradle b/junit-4/settings.gradle index 2a39923..3e5b662 100644 --- a/junit-4/settings.gradle +++ b/junit-4/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { resolutionStrategy { eachPlugin { if (requested.id.id == "com.browserstack.gradle-sdk") { - useModule("com.browserstack:gradle-sdk:1.0.0") + useModule("com.browserstack:gradle-sdk:1.1.2") } } } From e9f40cf12015d224c3c218e2144a8998de9c6f1b Mon Sep 17 00:00:00 2001 From: Aaryan Date: Wed, 22 Jan 2025 17:02:51 +0530 Subject: [PATCH 46/50] Fix gradle-sdk plugin version for junit5 --- junit-5/build.gradle | 2 +- junit-5/settings.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/junit-5/build.gradle b/junit-5/build.gradle index a1dfffd..36bda87 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'com.browserstack.gradle-sdk' version "1.0.0" // sdk plugin + id 'com.browserstack.gradle-sdk' version "1.1.2" // sdk plugin } repositories { mavenCentral() } diff --git a/junit-5/settings.gradle b/junit-5/settings.gradle index 2a39923..3e5b662 100644 --- a/junit-5/settings.gradle +++ b/junit-5/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { resolutionStrategy { eachPlugin { if (requested.id.id == "com.browserstack.gradle-sdk") { - useModule("com.browserstack:gradle-sdk:1.0.0") + useModule("com.browserstack:gradle-sdk:1.1.2") } } } From bd2b8d3348db2f049e5cc428fd149b6c6ec75907 Mon Sep 17 00:00:00 2001 From: Aaryan Date: Wed, 22 Jan 2025 17:03:26 +0530 Subject: [PATCH 47/50] fix readme for new plugin for junit 4 and 5 --- junit-4/README.md | 12 +++++++++++- junit-5/README.md | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/junit-4/README.md b/junit-4/README.md index 3979bb7..a118fd8 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -39,7 +39,7 @@ Understand how many parallel sessions you need by using our [Parallel Test Calcu 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: * Following are the changes required in `build.gradle` - - * Add `id 'com.browserstack.gradle-sdk' version "1.0.0"` in plugins + * Add `id 'com.browserstack.gradle-sdk' version "1.1.2"` in plugins * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies * Fetch Artifact Information and add `jvmArgs` property in tasks *Sample* and *Local* : ``` @@ -53,6 +53,16 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t } } ``` +* Following are the changes required in `settings.gradle` - + * Add `resolutionStrategy` inside `plugpluginManagement` + * Inside `resoluitonStrategy` add the plugin `id` as `com.browserstack.gradle-sdk` along with module `version` + ``` + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.1.2") + } + } + ``` * Install dependencies and run the test `gradle sample` diff --git a/junit-5/README.md b/junit-5/README.md index 5750187..f65fc84 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -37,7 +37,7 @@ Understand how many parallel sessions you need by using our [Parallel Test Calcu 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: * Following are the changes required in `gradle.build` - - * Add `id 'com.browserstack.gradle-sdk' version "1.0.0"` in plugins + * Add `id 'com.browserstack.gradle-sdk' version "1.1.2"` in plugins * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies * Fetch Artifact Information and add `jvmArgs` property in tasks *SingleTest* and *LocalTest* : ``` @@ -50,6 +50,16 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t useJUnitPlatform() } ``` + * Following are the changes required in `settings.gradle` - + * Add `resolutionStrategy` inside `plugpluginManagement` + * Inside `resoluitonStrategy` add the plugin `id` as `com.browserstack.gradle-sdk` along with module `version` + ``` + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.1.2") + } + } + ``` * Install dependencies `gradle build` From 55976879c9b0c6a16dade540827f35e9e6a16a11 Mon Sep 17 00:00:00 2001 From: Aaryan Date: Wed, 22 Jan 2025 17:49:43 +0530 Subject: [PATCH 48/50] fix selenium java version for supporting java 8 --- junit-5/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit-5/build.gradle b/junit-5/build.gradle index 36bda87..966f5ed 100644 --- a/junit-5/build.gradle +++ b/junit-5/build.gradle @@ -8,7 +8,7 @@ repositories { mavenCentral() } dependencies { implementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' implementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1' - implementation 'org.seleniumhq.selenium:selenium-java:4.22.0' + implementation 'org.seleniumhq.selenium:selenium-java:4.1.4' implementation 'com.browserstack:browserstack-java-sdk:latest.release' } From c6c9acf8dfab1e5ec4a88b46f24fc203f741b44f Mon Sep 17 00:00:00 2001 From: Aaryan Date: Wed, 22 Jan 2025 19:07:00 +0530 Subject: [PATCH 49/50] fix readme to match existing structure --- junit-4/README.md | 31 ------------------------------- junit-5/README.md | 31 ------------------------------- 2 files changed, 62 deletions(-) diff --git a/junit-4/README.md b/junit-4/README.md index a118fd8..4aa029c 100644 --- a/junit-4/README.md +++ b/junit-4/README.md @@ -34,37 +34,6 @@ Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) -### Integrate your test suite - -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: - -* Following are the changes required in `build.gradle` - - * Add `id 'com.browserstack.gradle-sdk' version "1.1.2"` in plugins - * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies - * Fetch Artifact Information and add `jvmArgs` property in tasks *Sample* and *Local* : - ``` - def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } - - task sampleTest(type: Test) { - useJUnit() { - dependsOn cleanTest - include '**/*BStackSampleTest.*' - jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" - } - } - ``` -* Following are the changes required in `settings.gradle` - - * Add `resolutionStrategy` inside `plugpluginManagement` - * Inside `resoluitonStrategy` add the plugin `id` as `com.browserstack.gradle-sdk` along with module `version` - ``` - eachPlugin { - if (requested.id.id == "com.browserstack.gradle-sdk") { - useModule("com.browserstack:gradle-sdk:1.1.2") - } - } - ``` - -* Install dependencies and run the test `gradle sample` ## Notes * You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) diff --git a/junit-5/README.md b/junit-5/README.md index f65fc84..bb68ee5 100644 --- a/junit-5/README.md +++ b/junit-5/README.md @@ -32,37 +32,6 @@ Understand how many parallel sessions you need by using our [Parallel Test Calcu Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) -### Integrate your test suite - -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: - -* Following are the changes required in `gradle.build` - - * Add `id 'com.browserstack.gradle-sdk' version "1.1.2"` in plugins - * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies - * Fetch Artifact Information and add `jvmArgs` property in tasks *SingleTest* and *LocalTest* : - ``` - def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } - - task sampleTest(type: Test) { - dependsOn cleanTest - include '**/*BStackSampleTest.*' - jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" - useJUnitPlatform() - } - ``` - * Following are the changes required in `settings.gradle` - - * Add `resolutionStrategy` inside `plugpluginManagement` - * Inside `resoluitonStrategy` add the plugin `id` as `com.browserstack.gradle-sdk` along with module `version` - ``` - eachPlugin { - if (requested.id.id == "com.browserstack.gradle-sdk") { - useModule("com.browserstack:gradle-sdk:1.1.2") - } - } - ``` - -* Install dependencies `gradle build` - ## Notes * You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) From 0f8836335502cef20746309de69ca379b9765c17 Mon Sep 17 00:00:00 2001 From: Aaryan Date: Fri, 24 Jan 2025 18:55:00 +0530 Subject: [PATCH 50/50] Empty-Commit