From b0176fa7350f72b08a6868f3b835407229e678d4 Mon Sep 17 00:00:00 2001 From: Sunil Gembali Date: Tue, 5 Mar 2024 16:39:42 +0530 Subject: [PATCH] Feat[TE-17014]: Biometric automation addon --- biometric_automation_addon/pom.xml | 102 ++++++++++++++++ .../addons/android/BiometricAutomator.java | 109 ++++++++++++++++++ .../addons/ios/BiometricAutomator.java | 109 ++++++++++++++++++ 3 files changed, 320 insertions(+) create mode 100644 biometric_automation_addon/pom.xml create mode 100644 biometric_automation_addon/src/main/java/com/testsigma/addons/android/BiometricAutomator.java create mode 100644 biometric_automation_addon/src/main/java/com/testsigma/addons/ios/BiometricAutomator.java diff --git a/biometric_automation_addon/pom.xml b/biometric_automation_addon/pom.xml new file mode 100644 index 0000000..1b48043 --- /dev/null +++ b/biometric_automation_addon/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + com.testsigma.addons + biometric_automation_addon + 1.0.0 + jar + + + UTF-8 + 11 + 11 + 1.2.6_cloud + 5.8.0-M1 + 1.0.0 + 3.2.1 + 1.18.20 + + + + + + org.apache.commons + commons-lang3 + 3.14.0 + + + com.testsigma + testsigma-java-sdk + ${testsigma.sdk.version} + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + org.testng + testng + 6.14.3 + + + + org.seleniumhq.selenium + selenium-java + 4.14.1 + + + + io.appium + java-client + 9.0.0 + + + com.fasterxml.jackson.core + jackson-annotations + 2.13.0 + + + + + biometric_automation_addon + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven.source.plugin.version} + + + attach-sources + + jar + + + + + + + \ No newline at end of file diff --git a/biometric_automation_addon/src/main/java/com/testsigma/addons/android/BiometricAutomator.java b/biometric_automation_addon/src/main/java/com/testsigma/addons/android/BiometricAutomator.java new file mode 100644 index 0000000..ee57d3a --- /dev/null +++ b/biometric_automation_addon/src/main/java/com/testsigma/addons/android/BiometricAutomator.java @@ -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"); + } + } +} \ No newline at end of file diff --git a/biometric_automation_addon/src/main/java/com/testsigma/addons/ios/BiometricAutomator.java b/biometric_automation_addon/src/main/java/com/testsigma/addons/ios/BiometricAutomator.java new file mode 100644 index 0000000..9322894 --- /dev/null +++ b/biometric_automation_addon/src/main/java/com/testsigma/addons/ios/BiometricAutomator.java @@ -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"); + } + } +} \ No newline at end of file