Skip to content
Merged
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
13 changes: 11 additions & 2 deletions iterating_through_columns_in_tdps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.testsigma.addons</groupId>
<artifactId>iterating_through_columns_in_tdps</artifactId>
<version>1.0.0</version>
<version>1.0.6</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -71,7 +71,16 @@
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>5.0.0-alpha.12</version>
</dependency>
</dependencies>
<build>
<finalName>iterating_through_columns_in_tdps</finalName>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.testsigma.addons.android;

import com.testsigma.addons.util.TDPApiUtil;
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 org.openqa.selenium.NoSuchElementException;

@Action(actionText = "add new column column-name with default value default-value to TDP tdp-id" +
" using the apikey api-key",
description = "Adds a new parameter/column to an existing TDP with the specified default value for all rows.",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class AddColumnToTDP extends AndroidAction {

@TestData(reference = "tdp-id")
private com.testsigma.sdk.TestData tdpId;
@TestData(reference = "column-name")
private com.testsigma.sdk.TestData columnName;
@TestData(reference = "default-value")
private com.testsigma.sdk.TestData defaultValue;
@TestData(reference = "api-key")
private com.testsigma.sdk.TestData apiKey;

@Override
public Result execute() throws NoSuchElementException {
logger.info("Initiating AddColumnToTDP execution");
String tdpIdStr = tdpId.getValue().toString().trim();
String colName = columnName.getValue().toString().trim();
String defValue = defaultValue.getValue().toString().trim();
String apiKeyStr = apiKey.getValue().toString().trim();
logger.info("TDP ID: " + tdpIdStr + ", Column: " + colName + ", Default Value: " + defValue);
if (colName.isEmpty()) {
setErrorMessage("Column name cannot be empty");
return Result.FAILED;
}
try {
TDPApiUtil.addTDPColumn(tdpIdStr, colName, defValue, apiKeyStr, logger);
logger.info("New column added to TDP successfully");
setSuccessMessage("Successfully added new column <b>" + colName + "</b> with default value <b>" + defValue + "</b> to all rows in TDP");
return Result.SUCCESS;
} catch (Exception e) {
logger.info("Error occurred while adding column to TDP: " + e.getMessage());
setErrorMessage("Failed to add column to TDP: " + e.getMessage());
return Result.FAILED;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.testsigma.addons.android;

import com.testsigma.addons.util.TDPApiUtil;
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 org.openqa.selenium.NoSuchElementException;

@Action(actionText = "add new row row-name to TDP tdp-id using the apikey api-key",
description = "Adds a new row/set to an existing TDP with empty values for all existing parameters.",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class AddNewRowToTDP extends AndroidAction {

@TestData(reference = "tdp-id")
private com.testsigma.sdk.TestData tdpId;
@TestData(reference = "row-name")
private com.testsigma.sdk.TestData rowName;
@TestData(reference = "api-key")
private com.testsigma.sdk.TestData apiKey;

@Override
public Result execute() throws NoSuchElementException {
logger.info("Initiating AddNewRowToTDP execution");
String tdpIdStr = tdpId.getValue().toString().trim();
String rowNameStr = rowName.getValue().toString().trim();
String apiKeyStr = apiKey.getValue().toString().trim();
try {
TDPApiUtil.addTDPRowWithEmptyData(tdpIdStr, rowNameStr, apiKeyStr, logger);
setSuccessMessage("Successfully added new row <b>" + rowNameStr + "</b> to TDP with empty parameter values");
return Result.SUCCESS;
} catch (Exception e) {
setErrorMessage("Failed to add new row to TDP: " + e.getMessage());
return Result.FAILED;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.testsigma.addons.android;

import com.testsigma.addons.util.TDPApiUtil;
import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import com.testsigma.sdk.annotation.RunTimeData;
import org.openqa.selenium.NoSuchElementException;

import java.util.Map;

@Action(actionText = "get entire row from TDP tdp-id for the set name set-name using the apikey api-key and" +
" store data in the run time variable runtime-variable",
description = "Get entire row from TDP",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class GetEntireRowFromTDP extends AndroidAction {

@TestData(reference = "tdp-id")
private com.testsigma.sdk.TestData testData1;
@TestData(reference = "set-name")
private com.testsigma.sdk.TestData testData2;
@TestData(reference = "api-key")
private com.testsigma.sdk.TestData testData3;
@TestData(reference = "runtime-variable", isRuntimeVariable = true)
private com.testsigma.sdk.TestData testData4;
@RunTimeData
private com.testsigma.sdk.RunTimeData runTimeData;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating execution");
try {
String tdpId = testData1.getValue().toString();
String setName = testData2.getValue().toString();
String apiKey = testData3.getValue().toString();
Map<String, String> parameterValues = TDPApiUtil.getTDPIterationData(tdpId, setName, apiKey, logger);
String resultVariable = "";
for (Map.Entry<String, String> entry : parameterValues.entrySet()) {
String key = entry.getKey();
if (key.equals("S.No.") || key.equals("ETF") || key.equals("Set Name")) continue;
resultVariable += entry.getValue() + ", ";
}
resultVariable = resultVariable.substring(0, resultVariable.length() - 2);
runTimeData.setValue(resultVariable);
Comment on lines +39 to +46
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

substring can crash when no eligible columns are present.

If all keys are filtered out, resultVariable is empty and substring(0, -2) throws at runtime.

Suggested fix
+import java.util.StringJoiner;
...
-            String resultVariable = "";
+            StringJoiner resultJoiner = new StringJoiner(", ");
             for (Map.Entry<String, String> entry : parameterValues.entrySet()) {
                 String key = entry.getKey();
                 if (key.equals("S.No.") || key.equals("ETF") || key.equals("Set Name")) continue;
-                resultVariable += entry.getValue() + ", ";
+                resultJoiner.add(String.valueOf(entry.getValue()));
             }
-            resultVariable = resultVariable.substring(0, resultVariable.length() - 2);
-            runTimeData.setValue(resultVariable);
+            runTimeData.setValue(resultJoiner.toString());
             runTimeData.setKey(testData4.getValue().toString());
📝 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 resultVariable = "";
for (Map.Entry<String, String> entry : parameterValues.entrySet()) {
String key = entry.getKey();
if (key.equals("S.No.") || key.equals("ETF") || key.equals("Set Name")) continue;
resultVariable += entry.getValue() + ", ";
}
resultVariable = resultVariable.substring(0, resultVariable.length() - 2);
runTimeData.setValue(resultVariable);
StringJoiner resultJoiner = new StringJoiner(", ");
for (Map.Entry<String, String> entry : parameterValues.entrySet()) {
String key = entry.getKey();
if (key.equals("S.No.") || key.equals("ETF") || key.equals("Set Name")) continue;
resultJoiner.add(String.valueOf(entry.getValue()));
}
runTimeData.setValue(resultJoiner.toString());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@iterating_through_columns_in_tdps/src/main/java/com/testsigma/addons/android/GetEntireRowFromTDP.java`
around lines 39 - 46, The current loop in GetEntireRowFromTDP builds
resultVariable by appending values then unconditionally calling substring to
strip the trailing ", ", which will throw if no eligible keys in parameterValues
exist; change the logic to avoid substring on an empty string—e.g., use a
StringBuilder or check resultVariable.length() >= 2 before calling substring,
and only call runTimeData.setValue(...) with the trimmed string (or an empty
string) when appropriate; update references around resultVariable,
parameterValues iteration, and runTimeData.setValue to implement this safe
trimming.

runTimeData.setKey(testData4.getValue().toString());
logger.info("Successfully retrieved and stored data for iteration: " + setName);
return com.testsigma.sdk.Result.SUCCESS;
} catch (Exception e) {
logger.warn("Error occurred while processing TDP data: " + e.getMessage());
setErrorMessage("Error occurred while processing TDP data: " + e.getMessage());
return com.testsigma.sdk.Result.FAILED;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.testsigma.addons.android;

import com.testsigma.addons.util.TDPApiUtil;
import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import com.testsigma.sdk.annotation.RunTimeData;

import java.util.Map;

@Action(actionText = "store total column count of TDP tdp-id for the set name set-name using the apikey" +
" api-key into variable column-count-variable",
description = "Get total column count of TDP",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class GetTDPColumncount extends AndroidAction {

@TestData(reference = "tdp-id")
private com.testsigma.sdk.TestData testData1;
@TestData(reference = "set-name")
private com.testsigma.sdk.TestData testData2;
@TestData(reference = "api-key")
private com.testsigma.sdk.TestData testData3;
@TestData(reference = "column-count-variable", isRuntimeVariable = true)
private com.testsigma.sdk.TestData testData4;
@RunTimeData
private com.testsigma.sdk.RunTimeData runTimeData;

@Override
public com.testsigma.sdk.Result execute() {
logger.info("Initiating execution");
try {
String tdpId = testData1.getValue().toString();
String setName = testData2.getValue().toString();
String apiKey = testData3.getValue().toString();
Map<String, String> parameterValues = TDPApiUtil.getTDPIterationData(tdpId, setName, apiKey, logger);
int totalColumnCount = parameterValues.size();
runTimeData.setKey(testData4.getValue().toString());
runTimeData.setValue(String.valueOf(totalColumnCount));
logger.info("Total column count: " + totalColumnCount);
return com.testsigma.sdk.Result.SUCCESS;
} catch (Exception e) {
logger.info("Error occurred while getting total column count of TDP: " + e.getMessage());
setErrorMessage("Error occurred while getting total column count: " + e.getMessage());
return com.testsigma.sdk.Result.FAILED;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.testsigma.addons.android;

import com.testsigma.addons.util.TDPApiUtil;
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 org.openqa.selenium.NoSuchElementException;

import java.util.Map;

@Action(actionText = "get TDP tdp-id value for set name set-name and parameter parameter-name" +
" using the apikey api-key and store in variable runtime-variable",
description = "Gets the value of a specific parameter/column for a given set name in the TDP" +
" and stores it in a runtime variable.",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class GetTDPValue extends AndroidAction {

@TestData(reference = "tdp-id")
private com.testsigma.sdk.TestData tdpId;
@TestData(reference = "set-name")
private com.testsigma.sdk.TestData setName;
@TestData(reference = "parameter-name")
private com.testsigma.sdk.TestData parameterName;
@TestData(reference = "api-key")
private com.testsigma.sdk.TestData apiKey;
@TestData(reference = "runtime-variable", isRuntimeVariable = true)
private com.testsigma.sdk.TestData runtimeVariable;
@RunTimeData
private com.testsigma.sdk.RunTimeData runTimeData;

@Override
public Result execute() throws NoSuchElementException {
logger.info("Initiating GetTDPValue execution");
String tdpIdStr = tdpId.getValue().toString().trim();
String setNameStr = setName.getValue().toString().trim();
String paramName = parameterName.getValue().toString().trim();
String apiKeyStr = apiKey.getValue().toString().trim();
try {
Map<String, String> parameterValues = TDPApiUtil.getTDPIterationData(tdpIdStr, setNameStr, apiKeyStr, logger);
if (!parameterValues.containsKey(paramName)) {
setErrorMessage("Parameter <b>" + paramName + "</b> not found in set <b>" + setNameStr + "</b>. Available parameters: " + parameterValues.keySet());
return Result.FAILED;
}
String value = parameterValues.get(paramName);
runTimeData.setKey(runtimeVariable.getValue().toString());
runTimeData.setValue(value);
setSuccessMessage("Successfully retrieved parameter <b>" + paramName + "</b> = <b>" + value + "</b> from set <b>" + setNameStr + "</b>");
return Result.SUCCESS;
} catch (Exception e) {
setErrorMessage("Failed to get TDP value: " + e.getMessage());
return Result.FAILED;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.testsigma.addons.android;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import com.testsigma.sdk.annotation.RunTimeData;

import java.util.Objects;

@Action(actionText = "set TDP iterator TDP_ITERATOR_KEY_NAME value to 0",
description = "Set TDP iterator TDP_ITERATOR_KEY_NAME to 0",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class SetTDpIteratorToZero extends AndroidAction {

@TestData(reference = "TDP_ITERATOR_KEY_NAME", isRuntimeVariable = true)
private com.testsigma.sdk.TestData testData1;
@RunTimeData
private com.testsigma.sdk.RunTimeData runTimeData;

@Override
public com.testsigma.sdk.Result execute() {
logger.info("Initiating execution");
if (!Objects.equals(testData1.getValue().toString(), "TDP_ITERATOR_KEY_NAME")) {
setErrorMessage("Don't change the TDP_ITERATOR_KEY_NAME variable name");
return com.testsigma.sdk.Result.FAILED;
}
try {
runTimeData.setValue("0");
runTimeData.setKey("TDP_ITERATOR_KEY_NAME");
setSuccessMessage("Set TDP iterator TDP_ITERATOR_KEY_NAME to 0");
return com.testsigma.sdk.Result.SUCCESS;
} catch (Exception e) {
setErrorMessage("Error occurred while setting runtime variable to 0: " + e.getMessage());
return com.testsigma.sdk.Result.FAILED;
}
}
}
Loading
Loading