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
2 changes: 1 addition & 1 deletion list_data_structure_actions/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>list_data_structure_actions</artifactId>
<version>1.0.0</version>
<version>1.0.2</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.testsigma.addons.datagenerator;

import com.testsigma.sdk.TestData;
import com.testsigma.sdk.annotation.TestDataFunction;
import com.testsigma.sdk.annotation.TestDataFunctionParameter;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;

@Data
@TestDataFunction(displayName = "Get count of elements in separator separated test-data",
description = "Splits the test-data using the given separator and returns the count of elements")
public class GetElementCountBySeparator extends com.testsigma.sdk.TestDataFunction {

@TestDataFunctionParameter(reference = "separator")
private com.testsigma.sdk.TestData separator;

@TestDataFunctionParameter(reference = "test-data")
private com.testsigma.sdk.TestData inputData;

@Override
public TestData generate() throws Exception {
try {
String separatorValue = this.separator.getValue().toString();
String inputValue = this.inputData.getValue().toString();
Comment thread
ManojTestsigma marked this conversation as resolved.

if (inputValue.isEmpty()) {
logger.info("Input data is empty, returning count as 0");
setSuccessMessage("Input data is empty. Element count: <b>0</b>.");
return new TestData("0");
}

String[] elements = inputValue.split(separatorValue, -1);
int count = elements.length;
Comment thread
ManojTestsigma marked this conversation as resolved.

logger.info("Element count: " + count);
setSuccessMessage(String.format("Successfully retrieved element count: <b>%d</b>.", count));
return new TestData(String.valueOf(count));
} catch (Exception e) {
setErrorMessage("Failed to get element count due to " + e.getMessage());
logger.warn("Failed to get element count." + ExceptionUtils.getStackTrace(e));
throw new Exception("Failed to get element count due to " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.testsigma.addons.datagenerator;

import com.testsigma.sdk.TestData;
import com.testsigma.sdk.annotation.RunTimeData;
import com.testsigma.sdk.annotation.RunTimeDataProvider;
import com.testsigma.sdk.annotation.TestDataFunction;
import com.testsigma.sdk.annotation.TestDataFunctionParameter;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;

@Data
@TestDataFunction(displayName = "Store current iteration value using separator separated values",
description = "Iterate separator separated values in test-data and return the current iteration value")
public class WhileLoopStringBySeparator extends com.testsigma.sdk.TestDataFunction {

@TestDataFunctionParameter(reference = "separator")
private com.testsigma.sdk.TestData separator;

@TestDataFunctionParameter(reference = "test-data")
private com.testsigma.sdk.TestData inputData;

@RunTimeData
private com.testsigma.sdk.RunTimeData currentIterationIndex;

@RunTimeDataProvider
private com.testsigma.sdk.RuntimeDataProvider currentIterationIndexProvider;

@Override
public TestData generate() throws Exception {
try {
String separatorValue = this.separator.getValue().toString();
String inputValue = this.inputData.getValue().toString();
String[] inputValues = inputValue.split(separatorValue);
Comment thread
ManojTestsigma marked this conversation as resolved.

String indexKey = "WhileLoopStringBySeparator_TSIndex";
Comment thread
ManojTestsigma marked this conversation as resolved.

Object currentIterationIndexData = null;
try {
currentIterationIndexData = currentIterationIndexProvider.getRuntimeData(indexKey);
} catch (Exception ex) {
logger.info("Failed to get currentIterationIndexData " + ex.getMessage());
}

int currentIterationIndexValue;
if (currentIterationIndexData != null) {
currentIterationIndexValue = Integer.parseInt(currentIterationIndexData.toString());
} else {
logger.info("Current iteration index is null");
currentIterationIndexValue = 0;
}
logger.info("Current iteration index value: " + currentIterationIndexValue);

if (inputValues.length <= currentIterationIndexValue) {
logger.info("No more values to iterate the while loop.");
setErrorMessage("No more values to iterate the while loop.");
throw new Exception("No more values to iterate. All values have been consumed.");
}

String iterationValue = inputValues[currentIterationIndexValue].trim();

currentIterationIndexValue++;
currentIterationIndex = new com.testsigma.sdk.RunTimeData();
currentIterationIndex.setKey(indexKey);
currentIterationIndex.setValue(String.valueOf(currentIterationIndexValue));
logger.info("Stored next index " + indexKey + " = " + currentIterationIndexValue);

setSuccessMessage(String.format("Successfully returned iteration value: <b>%s</b>.", iterationValue));
logger.info("Returning iteration value: " + iterationValue);
return new TestData(iterationValue);
} catch (Exception e) {
setErrorMessage("Failed to iterate the while loop due to " + e.getMessage());
logger.warn("Failed to iterate the while loop." + ExceptionUtils.getStackTrace(e));
throw new Exception("Failed to iterate the while loop due to " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.testsigma.addons.restapi;

import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.RestApiAction;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.StepActionType;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.RunTimeData;
import com.testsigma.sdk.annotation.RunTimeDataProvider;
import com.testsigma.sdk.annotation.TestData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;

@Data
@Action(actionText = "store the current iteration value using SEPARATOR separated values in TEST-DATA " +
"into a runtime variable RUNTIME-VARIABLE",
description = "Iterate SEPARATOR separated values in TEST-DATA and store current iteration value " +
"in RUNTIME-VARIABLE",
applicationType = ApplicationType.REST_API,
actionType = StepActionType.WHILE_LOOP)
public class WhileLoopStringBySeparator extends RestApiAction {

@TestData(reference = "SEPARATOR")
private com.testsigma.sdk.TestData separator;

@TestData(reference = "TEST-DATA")
private com.testsigma.sdk.TestData inputData;

@TestData(reference = "RUNTIME-VARIABLE", isRuntimeVariable = true)
private com.testsigma.sdk.TestData runtimeVariable;

@RunTimeData
private com.testsigma.sdk.RunTimeData currentIteration;

@RunTimeData
private com.testsigma.sdk.RunTimeData currentIterationIndex;

@RunTimeDataProvider
private com.testsigma.sdk.RuntimeDataProvider currentIterationIndexProvider;

@Override
protected Result execute() throws NoSuchElementException {
try {
String runtimeVariableName = runtimeVariable.getValue().toString();
String indexedRuntimeVariableName = runtimeVariableName + "_TSIndex";

String separatorValue = this.separator.getValue().toString();
String inputValue = this.inputData.getValue().toString();
String[] inputValues = inputValue.split(separatorValue);
Comment thread
ManojTestsigma marked this conversation as resolved.

Object currentIterationIndexData = null;
try {
currentIterationIndexData = currentIterationIndexProvider.getRuntimeData(indexedRuntimeVariableName);
} catch (Exception ex) {
logger.info("Failed to get currentIterationIndexData " + ex.getMessage());
}

int currentIterationIndexValue;
if (currentIterationIndexData != null) {
currentIterationIndexValue = Integer.parseInt(currentIterationIndexData.toString());
} else {
logger.info("Current iteration index is null");
currentIterationIndexValue = 0;
}
logger.info("Current iteration index value: " + currentIterationIndexValue);

if (inputValues.length <= currentIterationIndexValue) {
logger.info("No more values to iterate the while loop.");
setErrorMessage("No more values to iterate the while loop.");
return Result.FAILED;
}

String iterationValue = inputValues[currentIterationIndexValue].trim();

currentIteration = new com.testsigma.sdk.RunTimeData();
currentIteration.setKey(runtimeVariableName);
currentIteration.setValue(iterationValue);
logger.info("Stored " + runtimeVariableName + " = " + iterationValue);

currentIterationIndexValue++;
currentIterationIndex = new com.testsigma.sdk.RunTimeData();
currentIterationIndex.setKey(indexedRuntimeVariableName);
currentIterationIndex.setValue(String.valueOf(currentIterationIndexValue));
logger.info("Stored next index" + indexedRuntimeVariableName + " = " + currentIterationIndexValue);
Comment thread
ManojTestsigma marked this conversation as resolved.
setSuccessMessage(String.format("Successfully stored the current iteration value into the " +
"runtime variable <b>%s = %s </b>.", runtimeVariableName, iterationValue));
return Result.SUCCESS;
} catch (Exception e) {
setErrorMessage("Failed to iterate the while loop due to " + e.getMessage());
logger.warn("Failed to iterate the while loop." + ExceptionUtils.getStackTrace(e));
return Result.FAILED;
}
}

}