-
Notifications
You must be signed in to change notification settings - Fork 15
[CUS-10690] added eisting addon to restapi and salesforce with data generator #335
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Action(actionText = "Perform mathematical_operations on testdata1 and testdata2 and store the result inside a runtimevariable considering number decimal places", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description = "Perform math operations and shows the result based on number of decimal places as per users requirement", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| applicationType = ApplicationType.REST_API) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class MathematicalOperationsRestApi extends MathematicalOperationsWeb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @TestData(reference = "testdata1") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private com.testsigma.sdk.TestData testData1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @TestData(reference = "mathematical_operations", allowedValues = {"addition", "subtraction", "multiplication", "division"}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private com.testsigma.sdk.TestData operator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @TestData(reference = "testdata2") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private com.testsigma.sdk.TestData testData2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @TestData(reference = "runtimevariable", isRuntimeVariable = true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private com.testsigma.sdk.TestData testData3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @TestData(reference = "number") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private com.testsigma.sdk.TestData testData4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @RunTimeData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private com.testsigma.sdk.RunTimeData runTimeData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public Result execute() throws NoSuchElementException { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(testData1.getValue().toString().isEmpty()|| testData2.getValue().toString().isEmpty()||testData4.getValue().toString().isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Some data is empty check the source for details"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setErrorMessage("Operation failed. Please check if some datas are empty"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = Result.FAILED; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String operatorString = operator.getValue().toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$,@,%,#]","")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$,@,%,#]","")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String num=String.valueOf(testData4.getValue().toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple parsing issues: no exception handling, incorrect regex, and NPE risk.
🐛 Proposed fix (parsing with error handling)+ try {
String operatorString = operator.getValue().toString();
- double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$,@,%,#]",""));
- double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$,@,%,#]",""));
- String num=String.valueOf(testData4.getValue().toString());
+ double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$@%#,]","").trim());
+ double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$@%#,]","").trim());
+ String num = testData4.getValue().toString().trim();
// ... switch block ...
+ } catch (NumberFormatException e) {
+ logger.warn("Failed to parse numeric input: " + e.getMessage());
+ setErrorMessage("Invalid numeric input provided. Please check testdata1, testdata2, and decimal places.");
+ return Result.FAILED;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (operatorString) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "addition": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double sum=a+b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String formattedvaluesum=String.format("%."+num+"f", sum); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setValue(String.valueOf(formattedvaluesum)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setKey(testData3.getValue().toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("sum is "+formattedvaluesum); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println(runTimeData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSuccessMessage("Successfully Performed addition. The sum is "+formattedvaluesum+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "subtraction": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double difference=a-b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String formattedvaluediff=String.format("%."+num+"f", difference); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setValue(String.valueOf(formattedvaluediff)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setKey(testData3.getValue().toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("difference is "+formattedvaluediff); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println(runTimeData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSuccessMessage("Successfully Performed Subtraction. The output is "+formattedvaluediff+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "multiplication": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double multiplication=a*b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String formattedvaluemulti=String.format("%."+num+"f",multiplication); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("multiplication is "+ formattedvaluemulti); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setValue(String.valueOf(formattedvaluemulti)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setKey(testData3.getValue().toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println(runTimeData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSuccessMessage("Successfully Performed Multiplication. The output is "+ formattedvaluemulti+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "division": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double division=a/b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Division by zero is not handled. When 🐛 Proposed fix case "division":
+ if (b == 0) {
+ setErrorMessage("Division by zero is not allowed.");
+ return Result.FAILED;
+ }
double division=a/b;🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String formattedvaluediv=String.format("%."+num+"f",division); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("division is "+ formattedvaluediv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setValue(String.valueOf( formattedvaluediv)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTimeData.setKey(testData3.getValue().toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println(runTimeData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSuccessMessage("Successfully Performed division. The output is "+ formattedvaluediv+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+49
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No default case in switch; silent success on invalid operator. If 🐛 Proposed fix+ default:
+ setErrorMessage("Unsupported operation: " + operatorString);
+ return Result.FAILED;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package com.testsigma.addons.web; | ||
|
|
||
| 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; | ||
|
|
||
| @Data | ||
| @Action(actionText = "Perform mathematical_operations on testdata1 and testdata2 and store the result inside a runtimevariable considering number decimal places", | ||
| description = "Perform math operations and shows the result based on number of decimal places as per users requirement", | ||
| applicationType = ApplicationType.Salesforce) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find the ApplicationType enum definition
find . -type f -name "*.java" | xargs grep -l "enum ApplicationType"Repository: testsigmahq/testsigma-addons Length of output: 5865 🏁 Script executed: # Also search for where ApplicationType is imported/used
rg "ApplicationType" --type=java -B2 -A2 | head -100Repository: testsigmahq/testsigma-addons Length of output: 5865 🏁 Script executed: # Search for ApplicationType.Salesforce specifically
rg "ApplicationType\.Salesforce" --type=javaRepository: testsigmahq/testsigma-addons Length of output: 5865 🌐 Web query:
💡 Result: In Testsigma, Salesforce is treated as an application type, so the Source: Testsigma docs list supported application types including Salesforce. [1] References 🌐 Web query:
💡 Result: In the Testsigma Java SDK,
You typically use it in add-ons via the Sources: [1], [2]
The Testsigma Java SDK's 🤖 Prompt for AI Agents |
||
| public class MathematicalOperationsSalesforce extends MathematicalOperationsWeb { | ||
|
|
||
|
|
||
| @TestData(reference = "testdata1") | ||
| private com.testsigma.sdk.TestData testData1; | ||
| @TestData(reference = "mathematical_operations", allowedValues = {"addition", "subtraction", "multiplication", "division"}) | ||
| private com.testsigma.sdk.TestData operator; | ||
| @TestData(reference = "testdata2") | ||
| private com.testsigma.sdk.TestData testData2; | ||
| @TestData(reference = "runtimevariable", isRuntimeVariable = true) | ||
| private com.testsigma.sdk.TestData testData3; | ||
| @TestData(reference = "number") | ||
| private com.testsigma.sdk.TestData testData4; | ||
| @RunTimeData | ||
| private com.testsigma.sdk.RunTimeData runTimeData; | ||
|
|
||
|
|
||
| @Override | ||
| public Result execute() throws NoSuchElementException { | ||
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | ||
| if(testData1.getValue().toString().isEmpty()|| testData2.getValue().toString().isEmpty()||testData4.getValue().toString().isEmpty()) { | ||
| logger.info("Some data is empty check the source for details"); | ||
| setErrorMessage("Operation failed. Please check if some datas are empty"); | ||
| result = Result.FAILED; | ||
|
|
||
| } | ||
| String operatorString = operator.getValue().toString(); | ||
| double a = Double.parseDouble(testData1.getValue().toString().replaceAll("[$,@,%,#]","")); | ||
| double b = Double.parseDouble(testData2.getValue().toString().replaceAll("[$,@,%,#]","")); | ||
| String num=String.valueOf(testData4.getValue().toString()); | ||
|
|
||
|
|
||
|
|
||
| switch (operatorString) { | ||
| case "addition": | ||
| double sum=a+b; | ||
| String formattedvaluesum=String.format("%."+num+"f", sum); | ||
| runTimeData.setValue(String.valueOf(formattedvaluesum)); | ||
| runTimeData.setKey(testData3.getValue().toString()); | ||
| logger.info("sum is "+formattedvaluesum); | ||
| System.out.println(runTimeData); | ||
| setSuccessMessage("Successfully Performed addition. The sum is "+formattedvaluesum+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||
| break; | ||
| case "subtraction": | ||
| double difference=a-b; | ||
| String formattedvaluediff=String.format("%."+num+"f", difference); | ||
| runTimeData.setValue(String.valueOf(formattedvaluediff)); | ||
| runTimeData.setKey(testData3.getValue().toString()); | ||
| logger.info("difference is "+formattedvaluediff); | ||
| System.out.println(runTimeData); | ||
| setSuccessMessage("Successfully Performed Subtraction. The output is "+formattedvaluediff+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||
| break; | ||
| case "multiplication": | ||
| double multiplication=a*b; | ||
| String formattedvaluemulti=String.format("%."+num+"f",multiplication); | ||
| logger.info("multiplication is "+ formattedvaluemulti); | ||
| runTimeData.setValue(String.valueOf(formattedvaluemulti)); | ||
| runTimeData.setKey(testData3.getValue().toString()); | ||
| System.out.println(runTimeData); | ||
| setSuccessMessage("Successfully Performed Multiplication. The output is "+ formattedvaluemulti+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||
| break; | ||
| case "division": | ||
| double division=a/b; | ||
| String formattedvaluediv=String.format("%."+num+"f",division); | ||
| logger.info("division is "+ formattedvaluediv); | ||
| runTimeData.setValue(String.valueOf( formattedvaluediv)); | ||
| runTimeData.setKey(testData3.getValue().toString()); | ||
| System.out.println(runTimeData); | ||
| setSuccessMessage("Successfully Performed division. The output is "+ formattedvaluediv+" .:: and has been stored into a runtime variable "+runTimeData.getKey()); | ||
| break; | ||
|
|
||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
Comment on lines
+32
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major This All issues raised in the RestApi review (no early return after validation, unhandled 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.testsigma.addons.web.generators; | ||
|
|
||
| import com.testsigma.sdk.TestData; | ||
| import com.testsigma.sdk.TestDataFunction; | ||
| import com.testsigma.sdk.annotation.TestDataFunctionParameter; | ||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| @com.testsigma.sdk.annotation.TestDataFunction( | ||
| displayName = "Generate random number within range min and max with decimal_places", | ||
| description = "Generates a random number within the given range, optionally with decimal places. Use this with mathematical operations addon.") | ||
| public class RandomNumberGenerator extends TestDataFunction { | ||
|
|
||
| @TestDataFunctionParameter(reference = "min") | ||
| private com.testsigma.sdk.TestDataParameter min; | ||
| @TestDataFunctionParameter(reference = "max") | ||
| private com.testsigma.sdk.TestDataParameter max; | ||
| @TestDataFunctionParameter(reference = "decimal_places") | ||
| private com.testsigma.sdk.TestDataParameter decimalPlaces; | ||
|
|
||
| @Override | ||
| public TestData generate() throws Exception { | ||
| logger.info("Initiating random number generation"); | ||
| double minVal = Double.parseDouble(min.getValue().toString().replaceAll("[$,@,%,#]", "").trim()); | ||
| double maxVal = Double.parseDouble(max.getValue().toString().replaceAll("[$,@,%,#]", "").trim()); | ||
|
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same regex issue: commas are matched literally in character class.
🤖 Prompt for AI Agents |
||
| int decimals = 0; | ||
| if (decimalPlaces != null && decimalPlaces.getValue() != null && !decimalPlaces.getValue().toString().trim().isEmpty()) { | ||
| decimals = Integer.parseInt(decimalPlaces.getValue().toString().trim()); | ||
| } | ||
| double number = minVal + (Math.random() * (maxVal - minVal)); | ||
| String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf((int) number); | ||
|
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Truncation instead of rounding, and no min ≤ max validation.
🐛 Proposed fix+ if (minVal > maxVal) {
+ double temp = minVal;
+ minVal = maxVal;
+ maxVal = temp;
+ }
double number = minVal + (Math.random() * (maxVal - minVal));
- String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf((int) number);
+ String formatted = decimals > 0 ? String.format("%." + decimals + "f", number) : String.valueOf(Math.round(number));🤖 Prompt for AI Agents |
||
| TestData testData = new TestData(formatted); | ||
| logger.info("Generated random number: " + formatted); | ||
| return testData; | ||
| } | ||
|
Comment on lines
+21
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No error handling for invalid inputs.
🤖 Prompt for AI Agents |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Execution continues after validation failure — no early return.
When any input is empty,
resultis set toFAILEDbut execution proceeds toDouble.parseDoubleon lines 43-44, which will throwNumberFormatExceptionon empty strings. Addreturn result;after settingFAILED.🐛 Proposed fix
if(testData1.getValue().toString().isEmpty()|| testData2.getValue().toString().isEmpty()||testData4.getValue().toString().isEmpty()) { logger.info("Some data is empty check the source for details"); setErrorMessage("Operation failed. Please check if some datas are empty"); result = Result.FAILED; - + return result; }🤖 Prompt for AI Agents