diff --git a/validate_data_with_regex_pattern/pom.xml b/validate_data_with_regex_pattern/pom.xml new file mode 100644 index 00000000..fc2c1240 --- /dev/null +++ b/validate_data_with_regex_pattern/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + com.testsigma.addons + validate_data_with_regex_pattern + 1.0.0 + jar + + + UTF-8 + 11 + 11 + 1.2.5_cloud + 5.8.0-M1 + 1.0.0 + 3.2.1 + 1.18.20 + + + + + + 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 + + + org.apache.commons + commons-lang3 + 3.14.0 + compile + + + + + validate_data_with_regex_pattern + + + 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/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/android/RegExPatternMatch.java b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/android/RegExPatternMatch.java new file mode 100644 index 00000000..b306fcdb --- /dev/null +++ b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/android/RegExPatternMatch.java @@ -0,0 +1,63 @@ +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 lombok.Data; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.openqa.selenium.NoSuchElementException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Data +@Action(actionText = "Verify if the text test-data matches the pattern regex-pattern", + description = "validates options count in a select drop-down", + applicationType = ApplicationType.ANDROID, + useCustomScreenshot = false) +public class RegExPatternMatch extends AndroidAction { + + @TestData(reference = "test-data") + private com.testsigma.sdk.TestData testData; + + @TestData(reference = "regex-pattern") + private com.testsigma.sdk.TestData regExPattern; + + + @Override + public Result execute() throws NoSuchElementException { + //Your Awesome code starts here + logger.info("Initiating execution"); + logger.info("Test Data::"+testData.getValue()); + logger.info("RegEx Pattern::"+regExPattern.getValue()); + + Result result = Result.SUCCESS; + + try { + Pattern pattern = Pattern.compile(regExPattern.getValue().toString()); + Matcher matcher = pattern.matcher(testData.getValue().toString()); + if (matcher.matches()) { + setSuccessMessage("The input string matches the pattern."); + return Result.SUCCESS; + } else { + result = Result.FAILED; + setErrorMessage("The input string does not match the pattern."); + return result; + } + } catch (Exception error) { + result = Result.FAILED; + logger.info(" Exception occurred while executing the action::"+ ExceptionUtils.getStackTrace(error)); + setErrorMessage("Exception occurred while executing the action::"+error.getMessage()); + return result; + } + + } +/* public static void main(String... a){ + MyFirstWebAction myFirstWebAction = new MyFirstWebAction(); + myFirstWebAction.setTestData(new com.testsigma.sdk.TestData("Showing 5 most recent authorizations")); + myFirstWebAction.setRegExPattern(new com.testsigma.sdk.TestData("Showing (\\d{1,2}|100) most recent authorizations")); + myFirstWebAction.execute(); + }*/ +} \ No newline at end of file diff --git a/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/android/StoreMatchingRegexValueInAVariable.java b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/android/StoreMatchingRegexValueInAVariable.java new file mode 100644 index 00000000..25a7921b --- /dev/null +++ b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/android/StoreMatchingRegexValueInAVariable.java @@ -0,0 +1,65 @@ +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.RunTimeData; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Data +@Action(actionText ="Extract data matching regex and store to a variable, Regex: regex-pattern, Input String: Input-Data, Store Variable Variable-Name", + description = "Extracts the regex matching data from given value and stores the first matching data in given variable", + applicationType = ApplicationType.ANDROID) +public class StoreMatchingRegexValueInAVariable extends AndroidAction { + + @TestData(reference = "Input-Data") + private com.testsigma.sdk.TestData testData; + + @TestData(reference = "regex-pattern") + private com.testsigma.sdk.TestData regex; + + @TestData(reference = "Variable-Name",isRuntimeVariable = true) + private com.testsigma.sdk.TestData runTimeVar; + + @RunTimeData + private com.testsigma.sdk.RunTimeData runTimeData; + + @Override + public Result execute() throws NoSuchElementException { + logger.info("Initiating execution"); + String Regex = regex.getValue().toString(); + String data = testData.getValue().toString(); + String varName = runTimeVar.getValue().toString(); + logger.info("Given test data : "+ data); + logger.info("Given regex-value : "+ Regex); + logger.info("Given runtime variable name : "+varName); + Result result = Result.SUCCESS; + try { + Pattern pattern = Pattern.compile(Regex); + Matcher matcher = pattern.matcher(data); + String matchedString; + if (matcher.find()) { + matchedString = matcher.group(); + logger.info("Found the matched data : "+matcher.group()); + } else { + setErrorMessage("Matching data with given regex is not found in given data"); + return Result.FAILED; + } + runTimeData.setKey(varName); + runTimeData.setValue(matchedString); + setSuccessMessage("Successfully stored the value : "+matchedString+", into given variable :"+varName); + } + catch(Exception e) { + logger.debug(e.getMessage()); + setErrorMessage("Failed to perform operation "+e.getMessage()+e.getCause()); + } + + return result; + } +} \ No newline at end of file diff --git a/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/ios/RegExPatternMatch.java b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/ios/RegExPatternMatch.java new file mode 100644 index 00000000..7e3c8471 --- /dev/null +++ b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/ios/RegExPatternMatch.java @@ -0,0 +1,63 @@ +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 lombok.Data; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.openqa.selenium.NoSuchElementException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Data +@Action(actionText = "Verify if the text test-data matches the pattern regex-pattern", + description = "validates options count in a select drop-down", + applicationType = ApplicationType.IOS, + useCustomScreenshot = false) +public class RegExPatternMatch extends IOSAction { + + @TestData(reference = "test-data") + private com.testsigma.sdk.TestData testData; + + @TestData(reference = "regex-pattern") + private com.testsigma.sdk.TestData regExPattern; + + + @Override + public Result execute() throws NoSuchElementException { + //Your Awesome code starts here + logger.info("Initiating execution"); + logger.info("Test Data::"+testData.getValue()); + logger.info("RegEx Pattern::"+regExPattern.getValue()); + + Result result = Result.SUCCESS; + + try { + Pattern pattern = Pattern.compile(regExPattern.getValue().toString()); + Matcher matcher = pattern.matcher(testData.getValue().toString()); + if (matcher.matches()) { + setSuccessMessage("The input string matches the pattern."); + return Result.SUCCESS; + } else { + result = Result.FAILED; + setErrorMessage("The input string does not match the pattern."); + return result; + } + } catch (Exception error) { + result = Result.FAILED; + logger.info(" Exception occurred while executing the action::"+ ExceptionUtils.getStackTrace(error)); + setErrorMessage("Exception occurred while executing the action::"+error.getMessage()); + return result; + } + + } + /* public static void main(String... a){ + RegExPatternMatch myFirstWebAction = new RegExPatternMatch(); + myFirstWebAction.setTestData(new com.testsigma.sdk.TestData("Showing 5 most recent authorizations")); + myFirstWebAction.setRegExPattern(new com.testsigma.sdk.TestData("Showing 5 most recent authorizations")); + myFirstWebAction.execute(); + }*/ +} \ No newline at end of file diff --git a/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/ios/StoreMatchingRegexValueInAVariable.java b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/ios/StoreMatchingRegexValueInAVariable.java new file mode 100644 index 00000000..f4a02093 --- /dev/null +++ b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/ios/StoreMatchingRegexValueInAVariable.java @@ -0,0 +1,65 @@ +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.RunTimeData; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Data +@Action(actionText ="Extract data matching regex and store to a variable, Regex: regex-pattern, Input String: Input-Data, Store Variable Variable-Name", + description = "Extracts the regex matching data from given value and stores the first matching data in given variable", + applicationType = ApplicationType.IOS) +public class StoreMatchingRegexValueInAVariable extends IOSAction { + + @TestData(reference = "Input-Data") + private com.testsigma.sdk.TestData testData; + + @TestData(reference = "regex-pattern") + private com.testsigma.sdk.TestData regex; + + @TestData(reference = "Variable-Name",isRuntimeVariable = true) + private com.testsigma.sdk.TestData runTimeVar; + + @RunTimeData + private com.testsigma.sdk.RunTimeData runTimeData; + + @Override + public Result execute() throws NoSuchElementException { + logger.info("Initiating execution"); + String Regex = regex.getValue().toString(); + String data = testData.getValue().toString(); + String varName = runTimeVar.getValue().toString(); + logger.info("Given test data : "+ data); + logger.info("Given regex-value : "+ Regex); + logger.info("Given runtime variable name : "+varName); + Result result = Result.SUCCESS; + try { + Pattern pattern = Pattern.compile(Regex); + Matcher matcher = pattern.matcher(data); + String matchedString; + if (matcher.find()) { + matchedString = matcher.group(); + logger.info("Found the matched data : "+matcher.group()); + } else { + setErrorMessage("Matching data with given regex is not found in given data"); + return Result.FAILED; + } + runTimeData.setKey(varName); + runTimeData.setValue(matchedString); + setSuccessMessage("Successfully stored the value : "+matchedString+", into given variable :"+varName); + } + catch(Exception e) { + logger.debug(e.getMessage()); + setErrorMessage("Failed to perform operation "+e.getMessage()+e.getCause()); + } + + return result; + } +} \ No newline at end of file diff --git a/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/web/RegExPatternMatch.java b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/web/RegExPatternMatch.java new file mode 100644 index 00000000..2a471056 --- /dev/null +++ b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/web/RegExPatternMatch.java @@ -0,0 +1,63 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.openqa.selenium.NoSuchElementException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Data +@Action(actionText = "Verify if the text test-data matches the pattern regex-pattern", + description = "validates options count in a select drop-down", + applicationType = ApplicationType.WEB, + useCustomScreenshot = false) +public class RegExPatternMatch extends WebAction { + + @TestData(reference = "test-data") + private com.testsigma.sdk.TestData testData; + + @TestData(reference = "regex-pattern") + private com.testsigma.sdk.TestData regExPattern; + + + @Override + public com.testsigma.sdk.Result execute() throws NoSuchElementException { + //Your Awesome code starts here + logger.info("Initiating execution"); + logger.info("Test Data::"+testData.getValue()); + logger.info("RegEx Pattern::"+regExPattern.getValue()); + + com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; + + try { + Pattern pattern = Pattern.compile(regExPattern.getValue().toString()); + Matcher matcher = pattern.matcher(testData.getValue().toString()); + if (matcher.matches()) { + setSuccessMessage("The input string matches the pattern."); + return Result.SUCCESS; + } else { + result = com.testsigma.sdk.Result.FAILED; + setErrorMessage("The input string does not match the pattern."); + return result; + } + } catch (Exception error) { + result = com.testsigma.sdk.Result.FAILED; + logger.info(" Exception occurred while executing the action::"+ ExceptionUtils.getStackTrace(error)); + setErrorMessage("Exception occurred while executing the action::"+error.getMessage()); + return result; + } + + } +/* public static void main(String... a){ + MyFirstWebAction myFirstWebAction = new MyFirstWebAction(); + myFirstWebAction.setTestData(new com.testsigma.sdk.TestData("Showing 5 most recent authorizations")); + myFirstWebAction.setRegExPattern(new com.testsigma.sdk.TestData("Showing (\\d{1,2}|100) most recent authorizations")); + myFirstWebAction.execute(); + }*/ +} \ No newline at end of file diff --git a/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/web/StoreMatchingRegexValueInAVariable.java b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/web/StoreMatchingRegexValueInAVariable.java new file mode 100644 index 00000000..14893e0b --- /dev/null +++ b/validate_data_with_regex_pattern/src/main/java/com/testsigma/addons/web/StoreMatchingRegexValueInAVariable.java @@ -0,0 +1,65 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.RunTimeData; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Data +@Action(actionText ="Extract data matching regex and store to a variable, Regex: regex-pattern, Input String: Input-Data, Store Variable Variable-Name", + description = "Extracts the regex matching data from given value and stores the first matching data in given variable", + applicationType = ApplicationType.WEB) +public class StoreMatchingRegexValueInAVariable extends WebAction { + + @TestData(reference = "Input-Data") + private com.testsigma.sdk.TestData testData; + + @TestData(reference = "regex-pattern") + private com.testsigma.sdk.TestData regex; + + @TestData(reference = "Variable-Name",isRuntimeVariable = true) + private com.testsigma.sdk.TestData runTimeVar; + + @RunTimeData + private com.testsigma.sdk.RunTimeData runTimeData; + + @Override + public Result execute() throws NoSuchElementException { + logger.info("Initiating execution"); + String Regex = regex.getValue().toString(); + String data = testData.getValue().toString(); + String varName = runTimeVar.getValue().toString(); + logger.info("Given test data : "+ data); + logger.info("Given regex-value : "+ Regex); + logger.info("Given runtime variable name : "+varName); + Result result = Result.SUCCESS; + try { + Pattern pattern = Pattern.compile(Regex); + Matcher matcher = pattern.matcher(data); + String matchedString; + if (matcher.find()) { + matchedString = matcher.group(); + logger.info("Found the matched data : "+matcher.group()); + } else { + setErrorMessage("Matching data with given regex is not found in given data"); + return Result.FAILED; + } + runTimeData.setKey(varName); + runTimeData.setValue(matchedString); + setSuccessMessage("Successfully stored the value : "+matchedString+", into given variable :"+varName); + } + catch(Exception e) { + logger.debug(e.getMessage()); + setErrorMessage("Failed to perform operation "+e.getMessage()+e.getCause()); + } + + return result; + } +} \ No newline at end of file