Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat[TE-17014]: Biometric automation addon #50

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions biometric_automation_addon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testsigma.addons</groupId>
<artifactId>biometric_automation_addon</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<testsigma.sdk.version>1.2.6_cloud</testsigma.sdk.version>
<junit.jupiter.version>5.8.0-M1</junit.jupiter.version>
<testsigma.addon.maven.plugin>1.0.0</testsigma.addon.maven.plugin>
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
<lombok.version>1.18.20</lombok.version>

</properties>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>com.testsigma</groupId>
<artifactId>testsigma-java-sdk</artifactId>
<version>${testsigma.sdk.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.14.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.0.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>

</dependencies>
<build>
<finalName>biometric_automation_addon</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.testsigma.addons.android;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriverException;

@Action(actionText = "Mark the biometric authentication as test-data",
description = "We can mark the biometric authentication as pass or fail",
applicationType = ApplicationType.ANDROID)
public class BiometricAutomator extends AndroidAction {

@TestData(reference = "test-data",allowedValues = {"PASS","FAIL"})
private com.testsigma.sdk.TestData testData;

private boolean isLambdaTest = false;

@Override
protected com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating biometric automation...");
Result result = Result.SUCCESS;
AppiumDriver appiumDriver = (AppiumDriver) driver;
String host = appiumDriver.getRemoteAddress().getHost();
logger.info("Host url: " + host);
try {
if (host.contains("lambdatest")) {
this.isLambdaTest = true;
processBiometric("lambda-biometric-injection=pass", "lambda-biometric-injection=fail");
} else if (host.contains("browserstack")) {
processBiometric( "browserstack_executor: {\"action\":\"biometric\", \"arguments\": {\"biometricMatch\" : \"pass\"}}", "browserstack_executor: {\"action\":\"biometric\", \"arguments\": {\"biometricMatch\" : \"fail\"}}");
} else if (host.contains("saucelabs")) {
processBiometric( "sauce:biometrics-authenticate=true", "sauce:biometrics-authenticate=false");
} else {
setErrorMessage("Unsupported lab. Biometric authentication supports in Browserstack, lambda-test and sauce-labs only");
result = Result.FAILED;
}
} catch (WebDriverException e) {
logger.info("Exception occurred biometric popup missing: " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Biometric authentication popup not shown, unable to perform biometric authentication");
} catch (Exception e) {
logger.info("Exception occurred : " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Unable to perform the biometric authentication");
}
return result;
}

private boolean failScriptRunner(String failScript) throws Exception {
AndroidDriver androidDriver = (AndroidDriver) driver;
try {
Object result = androidDriver.executeScript(failScript);
if (result != null) {
logger.info("Script execution result: " + result);
}
return true;
} catch (WebDriverException e) {
logger.info("Webdriver exception occurred and handled it");
return false;
} catch (Exception e) {
logger.info("Unknown exception in the occurred failScriptRunner: " + e.getMessage());
throw new Exception(e.getMessage());
}
}

private void processBiometric(String passScript, String failScript) throws Exception {
AndroidDriver androidDriver = (AndroidDriver) driver;
if (testData.getValue().toString().equals("PASS")) {
logger.info("Making the biometric to pass..");
Object result = androidDriver.executeScript(passScript);
if (result != null) {
logger.info("Script execution result: " + result.toString());
if (result.toString().contains("BROWSERSTACK_COMMAND_EXECUTION_FAILED")) {
throw new WebDriverException("Popup not shown");
}

}
logger.info("Biometric passed successfully");
setSuccessMessage("Successfully marked the biometric to PASS");
} else {
logger.info("Making the biometric to fail");
if (isLambdaTest) {
boolean firstTry = failScriptRunner(failScript);
if (!firstTry) {
throw new WebDriverException("Popup not shown");
} else {
failScriptRunner(failScript);
}
} else {
Object result = androidDriver.executeScript(failScript);
if(result != null) {
logger.info("Script execution result: " + result);
if (result.toString().contains("BROWSERSTACK_COMMAND_EXECUTION_FAILED")) {
throw new WebDriverException("Popup not shown");
}
}

}
logger.info("Biometric failed successfully");
setSuccessMessage("Successfully marked the biometric to FAIL");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.testsigma.addons.ios;

import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.IOSAction;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriverException;

@Action(actionText = "Mark the biometric authentication as test-data",
description = "We can mark the biometric authentication as pass or fail",
applicationType = ApplicationType.IOS)
public class BiometricAutomator extends IOSAction {

@TestData(reference = "test-data",allowedValues = {"PASS","FAIL"})
private com.testsigma.sdk.TestData testData;

private boolean isLambdaTest = false;

@Override
protected Result execute() throws NoSuchElementException {
logger.info("Initiating biometric automation...");
Result result = Result.SUCCESS;
AppiumDriver appiumDriver = (AppiumDriver) driver;
String host = appiumDriver.getRemoteAddress().getHost();
logger.info("Host url: " + host);
try {
if (host.contains("lambdatest")) {
this.isLambdaTest = true;
processBiometric("lambda-biometric-injection=pass", "lambda-biometric-injection=fail");
} else if (host.contains("browserstack")) {
processBiometric( "browserstack_executor: {\"action\":\"biometric\", \"arguments\": {\"biometricMatch\" : \"pass\"}}", "browserstack_executor: {\"action\":\"biometric\", \"arguments\": {\"biometricMatch\" : \"fail\"}}");
} else if (host.contains("saucelabs")) {
processBiometric( "sauce:biometrics-authenticate=true", "sauce:biometrics-authenticate=false");
} else {
setErrorMessage("Unsupported lab. Biometric authentication supports in Browserstack, lambda-test and sauce-labs only");
result = Result.FAILED;
}
} catch (WebDriverException e) {
logger.info("Exception occurred biometric authentication not initiated: " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Biometric authentication not initiated");
} catch (Exception e) {
logger.info("Exception occurred : " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Unable to perform the biometric authentication");
}
return result;
}

private boolean failScriptRunner(String failScript) throws Exception {
AndroidDriver androidDriver = (AndroidDriver) driver;
try {
Object result = androidDriver.executeScript(failScript);
if (result != null) {
logger.info("Script execution result: " + result);
}
return true;
} catch (WebDriverException e) {
logger.info("Webdriver exception occurred and handled it");
return false;
} catch (Exception e) {
logger.info("Unknown exception in the occurred failScriptRunner: " + e.getMessage());
throw new Exception(e.getMessage());
}
}

private void processBiometric(String passScript, String failScript) throws Exception {
AndroidDriver androidDriver = (AndroidDriver) driver;
if (testData.getValue().toString().equals("PASS")) {
logger.info("Making the biometric to pass..");
Object result = androidDriver.executeScript(passScript);
if (result != null) {
logger.info("Script execution result: " + result.toString());
if (result.toString().contains("BROWSERSTACK_COMMAND_EXECUTION_FAILED")) {
throw new WebDriverException("Biometric auth not initiated");
}

}
logger.info("Biometric passed successfully");
setSuccessMessage("Successfully marked the biometric to PASS");
} else {
logger.info("Making the biometric to fail");
if (isLambdaTest) {
boolean firstTry = failScriptRunner(failScript);
if (!firstTry) {
throw new WebDriverException("Popup not shown");
} else {
failScriptRunner(failScript);
}
} else {
Object result = androidDriver.executeScript(failScript);
if(result != null) {
logger.info("Script execution result: " + result);
if (result.toString().contains("BROWSERSTACK_COMMAND_EXECUTION_FAILED")) {
throw new WebDriverException("Biometric auth not initiated");
}
}

}
logger.info("Biometric failed successfully");
setSuccessMessage("Successfully marked the biometric to FAIL");
}
}
}