Skip to content
Open
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
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;

}
Comment on lines +34 to +41
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Execution continues after validation failure — no early return.

When any input is empty, result is set to FAILED but execution proceeds to Double.parseDouble on lines 43-44, which will throw NumberFormatException on empty strings. Add return result; after setting FAILED.

🐛 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
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 34 - 41, In execute(), after the empty-input validation that sets
result = Result.FAILED and calls setErrorMessage/logger, add an immediate return
of that result to prevent further execution; specifically update the execute()
method (where testData1, testData2, testData4 are checked) to return result
right after setting FAILED so the subsequent Double.parseDouble(...) calls
cannot run on empty strings.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Multiple parsing issues: no exception handling, incorrect regex, and NPE risk.

  1. No try-catch around Double.parseDouble/Integer.parseInt: Non-numeric input will throw an unhandled NumberFormatException, crashing the action instead of returning a user-friendly failure.
  2. Regex [$,@,%,#]: The commas inside the character class are matched literally. If the intent is to strip $, @, %, # only, use [$@%#]. If commas should also be stripped, use [$@%#,].
  3. Line 45: String.valueOf(testData4.getValue().toString()) is redundant — .toString() already returns a String.
  4. NPE risk: getValue() may return null; calling .toString() on it will throw NPE. Consider null-checks or Objects.toString().
🐛 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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());
try {
String operatorString = operator.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;
}
🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 42 - 45, The parsing code for operatorString and numeric inputs
(operatorString, Double.parseDouble calls for testData1 and testData2, and the
testData4 handling) is unsafe: calling getValue().toString() can NPE, the regex
"[$,@,%,#]" incorrectly includes commas, and there is no NumberFormatException
handling. Fix by null-checking getValue() (or use Objects.toString(value, "") )
before toString(), replace the regex with a correct character class like
"[$@%#]" (or include comma if desired), and wrap parsing (Double.parseDouble /
Integer.parseInt) in try-catch to handle NumberFormatException and return a
controlled failure result; also simplify testData4 by removing redundant
String.valueOf(...) and using the null-safe string.




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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Division by zero is not handled.

When b is 0, a / b produces Infinity or NaN (IEEE 754 doubles). This will be stored as the runtime variable value and reported as a "successful" division, which is incorrect. Check for b == 0 and return a meaningful error.

🐛 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
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 77 - 78, In the "division" case inside
MathematicalOperationsRestApi (the switch handling a and b), add a guard that
checks if b == 0 before computing double division = a / b; and handle it by
returning or throwing a meaningful error (e.g., HTTP 400 /
IllegalArgumentException or setting the runtime variable to an error state)
instead of storing Infinity/NaN; ensure the error message references the
division-by-zero condition and avoid performing the division when b is zero so
the operation is reported as failed rather than successful.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

No default case in switch; silent success on invalid operator.

If operatorString doesn't match any case (e.g., due to extra whitespace or capitalization), the method returns SUCCESS without performing any operation or setting a runtime value. Add a default case that fails with a descriptive message. Also consider normalizing input with .trim().toLowerCase().

🐛 Proposed fix
+          default:
+              setErrorMessage("Unsupported operation: " + operatorString);
+              return Result.FAILED;
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
}
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;
default:
setErrorMessage("Unsupported operation: " + operatorString);
return Result.FAILED;
}
🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsRestApi.java`
around lines 49 - 87, Normalize operatorString before the switch (e.g.,
operatorString = operatorString.trim().toLowerCase()) to handle
whitespace/capitalization, and add a default case to the switch that logs the
unsupported operator (using logger.error("Unsupported operator:
"+operatorString)), clears or does not set runTimeData, and prevents silent
success by throwing an IllegalArgumentException with a descriptive message (so
the method does not fall through returning success); update any callers if they
rely on exceptions for failure handling instead of setSuccessMessage.


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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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 -100

Repository: testsigmahq/testsigma-addons

Length of output: 5865


🏁 Script executed:

# Search for ApplicationType.Salesforce specifically
rg "ApplicationType\.Salesforce" --type=java

Repository: testsigmahq/testsigma-addons

Length of output: 5865


🌐 Web query:

Testsigma ApplicationType enum Salesforce constant

💡 Result:

In Testsigma, Salesforce is treated as an application type, so the ApplicationType enum’s Salesforce value is SALESFORCE (i.e., the “Salesforce” application type). [1]

Source: Testsigma docs list supported application types including Salesforce. [1]

References
[1] Testsigma guide: “Application Types Supported: Salesforce, SAP, Web, Mobile, Desktop, Mobile Web, and API apps” https://testsigma.com/guides/salesforce-testing/


🌐 Web query:

Testsigma SDK ApplicationType supported values documentation

💡 Result:

In the Testsigma Java SDK, com.testsigma.sdk.ApplicationType is an enum with these supported values:

  • WEB
  • MOBILE_WEB
  • IOS
  • ANDROID
  • WINDOWS
  • MAC [1]

You typically use it in add-ons via the @Action(..., applicationType = ApplicationType.<VALUE>) annotation (example shown with ApplicationType.WEB). [2]

Sources: [1], [2]


ApplicationType.Salesforce is not a valid enum constant.

The Testsigma Java SDK's ApplicationType enum only supports: WEB, MOBILE_WEB, IOS, ANDROID, WINDOWS, and MAC. Replace ApplicationType.Salesforce with an appropriate constant from this list.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsSalesforce.java`
at line 14, The code sets applicationType = ApplicationType.Salesforce, but
ApplicationType.Salesforce is not a valid enum member; change that assignment in
MathematicalOperationsSalesforce (the applicationType field/initializer) to one
of the supported enum constants (e.g., ApplicationType.WEB or
ApplicationType.MOBILE_WEB) that best matches the addon’s target environment,
ensuring you update any related metadata or comments to reflect the chosen
ApplicationType.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

This execute() method is a verbatim copy of MathematicalOperationsRestApi.execute().

All issues raised in the RestApi review (no early return after validation, unhandled NumberFormatException, division by zero, missing default case, incorrect regex, System.out.println) apply identically here. Since both classes extend MathematicalOperationsWeb, the shared execute() logic and field declarations should be pulled up into the base class. The subclasses would then only differ by their @Action annotation.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/MathematicalOperationsSalesforce.java`
around lines 32 - 89, The execute() implementation in
MathematicalOperationsSalesforce is a duplicate of MathematicalOperationsRestApi
and must be consolidated into the base class (MathematicalOperationsWeb): move
the execute() method into MathematicalOperationsWeb and have subclasses only
keep their `@Action` annotations; while doing so fix the logic in execute():
validate empty inputs and return immediately on failure (use setErrorMessage and
return Result.FAILED), wrap parsing of testData1/testData2/testData4 in a
try/catch for NumberFormatException and set an error on catch, guard division by
zero before computing division, add a default case in the operator switch to set
failure if operator is unknown, replace the incorrect regex
replaceAll("[$,@,%,#]","") with a correct character-class like
replaceAll("[\\\\$@%#]", "") and remove System.out.println calls (use logger).
Ensure you reference and use the existing fields/methods (execute(),
testData1/testData2/testData4, operator, runTimeData, setErrorMessage,
setSuccessMessage, logger) so subclasses inherit the fixed behavior.

}
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Same regex issue: commas are matched literally in character class.

"[$,@,%,#]" matches literal commas in addition to $, @, %, #. Use "[$@%#]" if commas should not be stripped, or "[$@%#,]" if they should.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java`
around lines 24 - 25, The regex in RandomNumberGenerator that strips symbols
before parsing (used when computing minVal and maxVal) incorrectly includes
commas in the character class ("[$,@,%,#]") so commas are removed; update the
replaceAll pattern to the intended character set (e.g., "[$@%#]" to not strip
commas or "[$@%#,]" to strip commas) in both places where min.getValue() and
max.getValue() are parsed (variables minVal and maxVal) so parsing behaves
correctly.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Truncation instead of rounding, and no min ≤ max validation.

  1. (int) number truncates toward zero (e.g., 4.99 → 4). Use Math.round(number) for correct rounding to nearest integer.
  2. If minVal > maxVal, Math.random() * (maxVal - minVal) produces a negative offset, resulting in values outside the intended range. Validate or swap the values.
🐛 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
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java`
around lines 30 - 31, The RandomNumberGenerator computes a double "number" and
then truncates to int with (int) number and doesn't validate minVal/maxVal;
change the logic in the generator (e.g., where "number", "minVal", "maxVal", and
"decimals" are used) to first ensure minVal <= maxVal (either validate and throw
IllegalArgumentException or swap them), compute number as minVal + Math.random()
* (maxVal - minVal), then when decimals == 0 use Math.round(number) to correctly
round to the nearest integer instead of truncating, and for decimals > 0 keep
the formatted String.format approach using decimals.

TestData testData = new TestData(formatted);
logger.info("Generated random number: " + formatted);
return testData;
}
Comment on lines +21 to +35
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

No error handling for invalid inputs.

Double.parseDouble and Integer.parseInt can throw NumberFormatException if the input strings are non-numeric after stripping. Wrapping in a try-catch with a meaningful error message would improve robustness.

🤖 Prompt for AI Agents
In
`@mathematical_operations/src/main/java/com/testsigma/addons/web/generators/RandomNumberGenerator.java`
around lines 21 - 35, The generate() method in RandomNumberGenerator lacks
handling for NumberFormatException from Double.parseDouble and Integer.parseInt;
wrap the parsing and number-generation logic in a try-catch that catches
NumberFormatException (and optionally other Exceptions), validate that min, max,
and decimalPlaces values are non-null and numeric before parsing, and when a
parse fails throw or rethrow an Exception with a clear message identifying which
field (min, max, or decimalPlaces) was invalid and include the offending input
value; ensure the logger (logger.info / logger.error) records the error message
before propagating the exception so callers can diagnose bad inputs.

}