From 3fc63f932ab30112a0a47cf27b9d107bee0451d1 Mon Sep 17 00:00:00 2001 From: anup-nehe <117707464+anup-nehe@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:43:24 +0530 Subject: [PATCH] MOSIP-34140 inji-verify browser stack integration (#117) * MOSIP-34140 Signed-off-by: Anup Nehe * MOSIP-34140 Signed-off-by: Anup Nehe * resolve conflicts Signed-off-by: Anup Nehe --------- Signed-off-by: Anup Nehe --- ui-test/TestNg.xml | 9 +++ ui-test/browserstack.yml | 72 +++++++++++++++++++++++ ui-test/pom.xml | 10 +++- ui-test/src/test/java/utils/BaseTest.java | 67 ++++++++++++++------- 4 files changed, 134 insertions(+), 24 deletions(-) create mode 100644 ui-test/TestNg.xml create mode 100644 ui-test/browserstack.yml diff --git a/ui-test/TestNg.xml b/ui-test/TestNg.xml new file mode 100644 index 00000000..b2ccb9e3 --- /dev/null +++ b/ui-test/TestNg.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/ui-test/browserstack.yml b/ui-test/browserstack.yml new file mode 100644 index 00000000..a61b7b71 --- /dev/null +++ b/ui-test/browserstack.yml @@ -0,0 +1,72 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: userName +accessKey: accessKey + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Sample +# Set `buildName` as the name of the job / testsuite being run +buildName: browserstack build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} + +# ======================================= +# 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: Windows + osVersion: 11 + browserName: Chrome + browserVersion: latest + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +source: java:intellij:v1.1.4 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: true # (Default false) + +# Options to be passed to BrowserStack local in-case of advanced configurations +# browserStackLocalOptions: + # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. + # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. + # Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) + +# Test Observability is an intelligent test reporting & debugging product. It collects data using the SDK. Read more about what data is collected at https://www.browserstack.com/docs/test-observability/references/terms-and-conditions +# Visit observability.browserstack.com to see your test reports and insights. To disable test observability, specify `testObservability: false` in the key below. +testObservability: true diff --git a/ui-test/pom.xml b/ui-test/pom.xml index 6fd9ccdf..fb75fb5d 100644 --- a/ui-test/pom.xml +++ b/ui-test/pom.xml @@ -1,6 +1,4 @@ - + 4.0.0 io.mosip.uiautomation uitest-injiverify @@ -98,6 +96,12 @@ 7.7.1 + + com.browserstack + browserstack-java-sdk + LATEST + compile + diff --git a/ui-test/src/test/java/utils/BaseTest.java b/ui-test/src/test/java/utils/BaseTest.java index d6b206da..b993fb97 100644 --- a/ui-test/src/test/java/utils/BaseTest.java +++ b/ui-test/src/test/java/utils/BaseTest.java @@ -2,12 +2,21 @@ import io.cucumber.java.After; import io.cucumber.java.Before; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashMap; import java.util.Map; + +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; -import java.time.Duration; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.yaml.snakeyaml.Yaml; public class BaseTest { @@ -17,29 +26,27 @@ public class BaseTest { public void setDriver(WebDriver driver) { this.driver = driver; } - public WebDriver driver; + public JavascriptExecutor jse; + String accessKey = getKeyValueFromYaml("/browserstack.yml","accessKey"); + String userName = getKeyValueFromYaml("/browserstack.yml","userName"); + public final String URL = "https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub"; @Before - public void beforeAll() { - String DriverPath = System.getProperty("user.dir") + "\\src\\test\\resources\\chromeDriver\\chromedriver.exe"; - Map prefs = new HashMap<>(); - Map profile = new HashMap<>(); - Map contentSettings = new HashMap<>(); - contentSettings.put("media_stream", 1); // 1: allow, 2: block - profile.put("managed_default_content_settings", contentSettings); - prefs.put("profile", profile); - System.setProperty("webdriver.chrome.driver", DriverPath); - ChromeOptions options = new ChromeOptions(); - options.addArguments("start-maximized"); - options.addArguments("--disable-infobars"); - options.addArguments("--disable-extensions"); - options.setExperimentalOption("prefs", prefs); - driver = new ChromeDriver(options); - driver.get("https://injiverify.qa-inji.mosip.net/"); - driver.manage().window().maximize(); - driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); + public void beforeAll() throws MalformedURLException { + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability("browserName", "Chrome"); + capabilities.setCapability("browserVersion", "latest"); + HashMap browserstackOptions = new HashMap(); + browserstackOptions.put("os", "Windows"); + browserstackOptions.put("osVersion", "10"); + browserstackOptions.put("projectName", "Bstack-[Java] Sample file download"); + capabilities.setCapability("bstack:options", browserstackOptions); + driver = new RemoteWebDriver(new URL(URL), capabilities); + jse = (JavascriptExecutor) driver; + driver.manage().window().maximize(); + driver.get("https://injiverify.qa-inji.mosip.net/"); } @After @@ -48,8 +55,26 @@ public void afterAll() { driver.quit(); } } - public WebDriver getDriver() { return driver; } + + public static String getKeyValueFromYaml(String filePath, String key) { + FileReader reader = null; + try { + reader = new FileReader(System.getProperty("user.dir")+filePath); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + Yaml yaml = new Yaml(); + Object data = yaml.load(reader); + + if (data instanceof Map) { + @SuppressWarnings("unchecked") + Map map = (Map) data; + return (String) map.get(key); + } else { + throw new RuntimeException("Invalid YAML format, expected a map"); + } + } } \ No newline at end of file