-
Notifications
You must be signed in to change notification settings - Fork 15
[CUS-11673] add data generator to get the value from the list string. #369
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
Open
ManojTestsigma
wants to merge
1
commit into
dev
Choose a base branch
from
CUS-11673
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
..._actions/src/main/java/com/testsigma/addons/datagenerator/GetElementCountBySeparator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
| 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; | ||
|
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()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
77 changes: 77 additions & 0 deletions
77
..._actions/src/main/java/com/testsigma/addons/datagenerator/WhileLoopStringBySeparator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
ManojTestsigma marked this conversation as resolved.
|
||
|
|
||
| String indexKey = "WhileLoopStringBySeparator_TSIndex"; | ||
|
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()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
96 changes: 96 additions & 0 deletions
96
...ucture_actions/src/main/java/com/testsigma/addons/restapi/WhileLoopStringBySeparator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
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); | ||
|
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; | ||
| } | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.