Skip to content

Commit

Permalink
MOSIP-34140 inji-verify browser stack integration (#117)
Browse files Browse the repository at this point in the history
* MOSIP-34140

Signed-off-by: Anup Nehe <[email protected]>

* MOSIP-34140

Signed-off-by: Anup Nehe <[email protected]>

* resolve conflicts

Signed-off-by: Anup Nehe <[email protected]>

---------

Signed-off-by: Anup Nehe <[email protected]>
  • Loading branch information
anup-nehe authored Jul 15, 2024
1 parent f0a9ce1 commit 3fc63f9
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 24 deletions.
9 changes: 9 additions & 0 deletions ui-test/TestNg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Cucumber Test Suite">
<test name="Cucumber Tests">
<classes>

<class name="runnerfiles.Runner"/>
</classes>
</test>
</suite>
72 changes: 72 additions & 0 deletions ui-test/browserstack.yml
Original file line number Diff line number Diff line change
@@ -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 # <boolean> (Default false)

# Options to be passed to BrowserStack local in-case of advanced configurations
# browserStackLocalOptions:
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
# forceLocal: true # <boolean> (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 # <boolean> # Set to true if you need screenshots for every selenium command ran
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
consoleLogs: errors # <string> 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
10 changes: 7 additions & 3 deletions ui-test/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.mosip.uiautomation</groupId>
<artifactId>uitest-injiverify</artifactId>
Expand Down Expand Up @@ -98,6 +96,12 @@
<version>7.7.1</version>
</dependency>

<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-java-sdk</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
67 changes: 46 additions & 21 deletions ui-test/src/test/java/utils/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<String, Object> prefs = new HashMap<>();
Map<String, Object> profile = new HashMap<>();
Map<String, Object> 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<String, Object> browserstackOptions = new HashMap<String, Object>();
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
Expand All @@ -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<String, String> map = (Map<String, String>) data;
return (String) map.get(key);
} else {
throw new RuntimeException("Invalid YAML format, expected a map");
}
}
}

0 comments on commit 3fc63f9

Please sign in to comment.