Repository navigation
feat/CUS-11412-Added class to store environment value in runtime variable - #359
Conversation
📝 WalkthroughWalkthroughAdded a new Maven module Changes
Sequence DiagramsequenceDiagram
actor Action as Platform Action
participant TM as TestMachineResult
participant API as Testsigma API
participant RT as RunTimeData
Action->>TM: Extract testCaseId from<br/>first suite/case result
alt testCaseId Present
Action->>API: GET /api/v1/test_case_results<br/>with testCaseId query & Bearer token
alt HTTP 200 Response
API-->>Action: JSON with test case result
Action->>Action: Parse response &<br/>extract environment.name<br/>from content[0]
alt Environment Name Found
Action->>RT: Set key=variableName<br/>value=envName
Action->>Action: Return SUCCESS
else Name Not Found
Action->>Action: Return FAILED with error
end
else Non-200 Status
Action->>Action: Return FAILED with error
end
else No testCaseId
Action->>Action: Return FAILED with error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 8
♻️ Duplicate comments (4)
store_environment_value/src/main/java/com/testsigma/addons/windows/StoreEnvironmentValue.java (1)
59-67:⚠️ Potential issue | 🟠 MajorHTTP client lacks timeout configuration.
Same issue as other platform implementations - add connection and request timeouts.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/windows/StoreEnvironmentValue.java` around lines 59 - 67, The HttpClient in StoreEnvironmentValue currently has no timeouts; update the HttpClient.newBuilder() call to set a connection timeout (e.g., connectTimeout(Duration.ofSeconds(...))) and set a request timeout on the HttpRequest (HttpRequest.newBuilder().timeout(Duration.ofSeconds(...))) before sending; import java.time.Duration and pick the same timeout values used by other platform implementations to keep behavior consistent, and ensure the variables client and request are created with these timeout configurations prior to client.send(...).store_environment_value/src/main/java/com/testsigma/addons/mobileweb/StoreEnvironmentValue.java (1)
59-67:⚠️ Potential issue | 🟠 MajorHTTP client lacks timeout configuration.
Same issue as other platform implementations - add connection and request timeouts to prevent indefinite hangs.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/mobileweb/StoreEnvironmentValue.java` around lines 59 - 67, The HttpClient in StoreEnvironmentValue (the HttpClient client and HttpRequest request creation) has no timeouts and can hang; update the HttpClient.newBuilder() to set a connect timeout (e.g., via connectTimeout(Duration.ofSeconds(...))) and set a per-request timeout on the HttpRequest.Builder (via timeout(Duration.ofSeconds(...))) so both connection and request timeouts are enforced; add the necessary java.time.Duration import and choose sensible timeout values consistent with other platform implementations.store_environment_value/src/main/java/com/testsigma/addons/android/StoreEnvironmentValue.java (1)
59-67:⚠️ Potential issue | 🟠 MajorHTTP client lacks timeout configuration.
Same issue as other platform implementations.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/android/StoreEnvironmentValue.java` around lines 59 - 67, The HttpClient in StoreEnvironmentValue is created without any timeout, so replace the HttpClient.newBuilder().build() usage to configure timeouts (e.g., set connectTimeout on HttpClient via HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(...)).build()) and also add a request-level timeout on the HttpRequest (use HttpRequest.newBuilder().timeout(Duration.ofSeconds(...)) on the same request being sent) so both connection and overall request timeouts are enforced; update any imports for java.time.Duration and ensure the configured durations are chosen consistently with other platform implementations.store_environment_value/src/main/java/com/testsigma/addons/web/StoreEnvironmentValue.java (1)
59-67:⚠️ Potential issue | 🟠 MajorHTTP client lacks timeout configuration.
Same issue as other platform implementations.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/web/StoreEnvironmentValue.java` around lines 59 - 67, The HTTP client is created without any timeout which can hang requests; update the HttpClient and/or HttpRequest creation to include explicit timeouts by calling HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(...)) and/or HttpRequest.newBuilder().timeout(Duration.ofSeconds(...)) so the call in StoreEnvironmentValue that builds the client (HttpClient client = HttpClient.newBuilder().build()) and the request (HttpRequest.newBuilder()...GET().build()) use a reasonable timeout value to prevent indefinite blocking.
🧹 Nitpick comments (7)
store_environment_value/src/main/java/com/testsigma/addons/ios/StoreEnvironmentValue.java (2)
8-8: Unused import:WebAction.This class extends
IOSAction, notWebAction.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/ios/StoreEnvironmentValue.java` at line 8, The import com.testsigma.sdk.WebAction is unused in the StoreEnvironmentValue class (which extends IOSAction); remove that import statement to clean up unused dependencies and avoid compiler warnings—look for the import line referencing WebAction in StoreEnvironmentValue.java and delete it.
16-16: Unused and suspicious import:org.openqa.selenium.devtools.v135.io.IO.This import is unused and references a specific Chrome DevTools version (v135). This appears to be a copy-paste artifact and should be removed.
Proposed fix
-import org.openqa.selenium.devtools.v135.io.IO;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/ios/StoreEnvironmentValue.java` at line 16, Remove the unused, versioned DevTools import org.openqa.selenium.devtools.v135.io.IO from StoreEnvironmentValue.java; locate the import statement near the top of the StoreEnvironmentValue class and delete it so the file no longer references a hard-coded Chrome DevTools version and to avoid unused-import compilation warnings, then recompile to verify no other references to IO remain.store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java (1)
7-8: Unused import:WebAction.
WebActionis imported but not used; this class extendsSalesforceAction.Proposed fix
import com.testsigma.sdk.SalesforceAction; -import com.testsigma.sdk.WebAction; import com.testsigma.sdk.annotation.Action;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java` around lines 7 - 8, Remove the unused import of WebAction from the StoreEnvironmentValue class: update the import block that currently includes com.testsigma.sdk.WebAction so only com.testsigma.sdk.SalesforceAction remains, ensuring no other references to WebAction exist in methods or fields of StoreEnvironmentValue.store_environment_value/src/main/java/com/testsigma/addons/windows/StoreEnvironmentValue.java (1)
7-8: Unused import:WebAction.This class extends
WindowsAction, notWebAction.Proposed fix
import com.testsigma.sdk.Result; -import com.testsigma.sdk.WebAction; import com.testsigma.sdk.WindowsAction;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/windows/StoreEnvironmentValue.java` around lines 7 - 8, The import com.testsigma.sdk.WebAction is unused in the StoreEnvironmentValue class (which extends WindowsAction); remove that unused import from StoreEnvironmentValue.java so only com.testsigma.sdk.WindowsAction remains, and recompile to ensure no references to WebAction exist in methods of StoreEnvironmentValue.store_environment_value/pom.xml (2)
42-46: Missing test scope for TestNG dependency.TestNG is a testing framework and should be scoped to
testto avoid bundling it into the production shaded JAR.Proposed fix
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.14.3</version> + <scope>test</scope> </dependency>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/pom.xml` around lines 42 - 46, The TestNG dependency (groupId org.testng, artifactId testng, version 6.14.3) is missing a test scope and is being included in the production shaded JAR; update the dependency block to add a <scope>test</scope> element so TestNG is only used for testing and not packaged with the production artifact.
36-41: Consider upgrading from JUnit 5.8.0-M1 milestone release to a stable version.The current version
5.8.0-M1is a pre-release milestone. The latest stable release is6.0.3. Upgrade to a stable version for production code.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/pom.xml` around lines 36 - 41, Update the JUnit dependency from the milestone release to the stable 6.0.3 by changing the junit-jupiter-api version referenced by the ${junit.jupiter.version} property to 6.0.3; also ensure any related JUnit artifacts in the POM (e.g., junit-jupiter-engine, junit-platform-*) use the same stable version and adjust build plugins (Surefire/Failsafe) if needed to remain compatible with JUnit 6.store_environment_value/src/main/java/com/testsigma/addons/restapi/StoreEnvironmentValue.java (1)
29-34: Validate required test data early for clearer failures.
variableNameandbearerTokenare dereferenced later without upfront guards; missing input currently degrades to generic exception flow.Suggested refactor
public Result execute() throws NoSuchElementException { Result result = Result.SUCCESS; logger.info("Initiating execution"); try { + if (variableName == null || variableName.getValue() == null || variableName.getValue().toString().isBlank()) { + setErrorMessage("Runtime variable name is required"); + return Result.FAILED; + } + if (bearerToken == null || bearerToken.getValue() == null || bearerToken.getValue().toString().isBlank()) { + setErrorMessage("Bearer token is required"); + return Result.FAILED; + } + Long testCaseId = null;Also applies to: 63-64, 84-85
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@store_environment_value/src/main/java/com/testsigma/addons/restapi/StoreEnvironmentValue.java` around lines 29 - 34, Add upfront validation for the required TestData fields in StoreEnvironmentValue: check that variableName and bearerToken are not null (and not empty when reading string values) at the start of the action's execution (e.g., in the execute/run method of StoreEnvironmentValue) and fail fast with a clear TestsigmaException or set the action result to failed with a descriptive message (e.g., "missing required test data: variable-name" or "missing required test data: token") before any dereference occurs; update all places using variableName and bearerToken (the spots referenced around lines 63-64 and 84-85) to rely on this early guard so later code can assume non-null values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@store_environment_value/src/main/java/com/testsigma/addons/ios/StoreEnvironmentValue.java`:
- Around line 1-108: The StoreEnvironmentValue class duplicates logic present
across platforms; extract the shared HTTP/JSON/testCaseId parsing logic into a
common helper (e.g., EnvironmentValueExtractor) and make StoreEnvironmentValue a
thin wrapper that calls it from execute(), passing testMachineResult and
bearerToken.getValue(), then only set
runTimeData.setKey(variableName.getValue().toString()) and
runTimeData.setValue(envName) and handle Result and messages there; refactor
references in execute(), and move JSON parsing/HttpClient call/exception
handling into the new utility so other platform classes
(Android/Web/MobileWeb/Windows/Salesforce/REST) can reuse it.
In
`@store_environment_value/src/main/java/com/testsigma/addons/restapi/StoreEnvironmentValue.java`:
- Around line 80-86: The code currently uses envNode.path("name").asText()
without checking if "name" exists, so empty strings get stored and success is
reported; update StoreEnvironmentValue to first verify the presence and
non-empty value of envNode.get("name") (or envNode.has("name") &&
!envNode.path("name").asText().isEmpty()) before setting envName/runTimeData; if
the "name" field is missing or empty, do not call runTimeData.setValue or
setSuccessMessage — instead call setErrorMessage (or the task-failure mechanism
used in this class) with a clear error and return/throw to mark the step failed;
references: envNode, envName, runTimeData, variableName, setSuccessMessage.
- Around line 60-67: The HttpClient and HttpRequest are created without timeouts
which can cause indefinite blocking; update the HttpClient builder used to
create "client" to include a connect timeout (e.g., via
HttpClient.newBuilder().connectTimeout(...)) and set a request-level timeout on
the HttpRequest built into "request" (e.g.,
HttpRequest.newBuilder()....timeout(...)) so that the client.send(...) call will
fail fast on network issues; adjust the timeout durations to sensible values for
your environment and ensure any InterruptedException/IOException handling
remains correct around the send call.
In
`@store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java`:
- Around line 102-104: Fix the typo in the error messages inside
StoreEnvironmentValue where "Error Occured" is used: update the messages passed
to logger.warn(...) and setErrorMessage(...) to read "Error Occurred" (e.g.,
change the string in the logger.warn call that currently concatenates
ExceptionUtils.getStackTrace(e) and the string passed to setErrorMessage that
uses ExceptionUtils.getMessage(e)); ensure both places are updated so the log
and the UI error text are consistent.
- Around line 59-67: The HttpClient in StoreEnvironmentValue is built without
timeouts and can hang; update the HttpClient and HttpRequest creation to include
explicit timeouts (e.g., use
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(30)) and set a
per-request timeout on HttpRequest via .timeout(Duration.ofSeconds(30))) so
requests will fail fast; locate the HttpClient client and HttpRequest request
instantiations in StoreEnvironmentValue and add the Duration-based connect and
request timeouts accordingly.
- Around line 79-85: envName may be empty because JsonNode.path(...).asText()
returns "" when missing; add a guard after extracting envName (the variable
envName from envNode) that checks if envName.trim().isEmpty(), and if so do not
call runTimeData.setValue(...) or setSuccessMessage(...); instead call the
action's error reporting (e.g., setErrorMessage or appropriate failure method)
with a clear message referencing the envNode and variableName.getValue(), and
return/exit the method early; otherwise continue with the existing
runTimeData.setKey(...)/setValue(...) and setSuccessMessage(...) flow.
- Around line 22-33: The actionText uses the placeholder "api-key" but the
bearer token TestData is annotated as reference = "token", causing a UI
mismatch; update the TestData reference for the bearerToken field (in class
StoreEnvironmentValue) to match the actionText placeholder (change reference =
"token" to reference = "api-key") or alternatively update actionText to use
"token"—pick one consistent naming and apply it to the `@TestData` on the
bearerToken field so the UI and code reference the same key.
In `@store_environment_value/src/main/resources/testsigma-sdk.properties`:
- Line 1: The committed testsigma-sdk.properties contains a hardcoded JWT API
key which must be removed: delete this file from the repo, remove it from future
commits (use git rm --cached if already committed) and add its name/pattern to
.gitignore; rotate/revoke the exposed API key immediately outside the codebase;
replace usage of the file in code by reading the credential from a secure source
(e.g., environment variable like TESTSIGMA_API_KEY or a secrets manager)
wherever the testsigma-sdk.api.key value was referenced so functions/classes
that previously relied on testsigma-sdk.properties now read
process/environment-backed configuration.
---
Duplicate comments:
In
`@store_environment_value/src/main/java/com/testsigma/addons/android/StoreEnvironmentValue.java`:
- Around line 59-67: The HttpClient in StoreEnvironmentValue is created without
any timeout, so replace the HttpClient.newBuilder().build() usage to configure
timeouts (e.g., set connectTimeout on HttpClient via
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(...)).build()) and
also add a request-level timeout on the HttpRequest (use
HttpRequest.newBuilder().timeout(Duration.ofSeconds(...)) on the same request
being sent) so both connection and overall request timeouts are enforced; update
any imports for java.time.Duration and ensure the configured durations are
chosen consistently with other platform implementations.
In
`@store_environment_value/src/main/java/com/testsigma/addons/mobileweb/StoreEnvironmentValue.java`:
- Around line 59-67: The HttpClient in StoreEnvironmentValue (the HttpClient
client and HttpRequest request creation) has no timeouts and can hang; update
the HttpClient.newBuilder() to set a connect timeout (e.g., via
connectTimeout(Duration.ofSeconds(...))) and set a per-request timeout on the
HttpRequest.Builder (via timeout(Duration.ofSeconds(...))) so both connection
and request timeouts are enforced; add the necessary java.time.Duration import
and choose sensible timeout values consistent with other platform
implementations.
In
`@store_environment_value/src/main/java/com/testsigma/addons/web/StoreEnvironmentValue.java`:
- Around line 59-67: The HTTP client is created without any timeout which can
hang requests; update the HttpClient and/or HttpRequest creation to include
explicit timeouts by calling
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(...)) and/or
HttpRequest.newBuilder().timeout(Duration.ofSeconds(...)) so the call in
StoreEnvironmentValue that builds the client (HttpClient client =
HttpClient.newBuilder().build()) and the request
(HttpRequest.newBuilder()...GET().build()) use a reasonable timeout value to
prevent indefinite blocking.
In
`@store_environment_value/src/main/java/com/testsigma/addons/windows/StoreEnvironmentValue.java`:
- Around line 59-67: The HttpClient in StoreEnvironmentValue currently has no
timeouts; update the HttpClient.newBuilder() call to set a connection timeout
(e.g., connectTimeout(Duration.ofSeconds(...))) and set a request timeout on the
HttpRequest (HttpRequest.newBuilder().timeout(Duration.ofSeconds(...))) before
sending; import java.time.Duration and pick the same timeout values used by
other platform implementations to keep behavior consistent, and ensure the
variables client and request are created with these timeout configurations prior
to client.send(...).
---
Nitpick comments:
In `@store_environment_value/pom.xml`:
- Around line 42-46: The TestNG dependency (groupId org.testng, artifactId
testng, version 6.14.3) is missing a test scope and is being included in the
production shaded JAR; update the dependency block to add a <scope>test</scope>
element so TestNG is only used for testing and not packaged with the production
artifact.
- Around line 36-41: Update the JUnit dependency from the milestone release to
the stable 6.0.3 by changing the junit-jupiter-api version referenced by the
${junit.jupiter.version} property to 6.0.3; also ensure any related JUnit
artifacts in the POM (e.g., junit-jupiter-engine, junit-platform-*) use the same
stable version and adjust build plugins (Surefire/Failsafe) if needed to remain
compatible with JUnit 6.
In
`@store_environment_value/src/main/java/com/testsigma/addons/ios/StoreEnvironmentValue.java`:
- Line 8: The import com.testsigma.sdk.WebAction is unused in the
StoreEnvironmentValue class (which extends IOSAction); remove that import
statement to clean up unused dependencies and avoid compiler warnings—look for
the import line referencing WebAction in StoreEnvironmentValue.java and delete
it.
- Line 16: Remove the unused, versioned DevTools import
org.openqa.selenium.devtools.v135.io.IO from StoreEnvironmentValue.java; locate
the import statement near the top of the StoreEnvironmentValue class and delete
it so the file no longer references a hard-coded Chrome DevTools version and to
avoid unused-import compilation warnings, then recompile to verify no other
references to IO remain.
In
`@store_environment_value/src/main/java/com/testsigma/addons/restapi/StoreEnvironmentValue.java`:
- Around line 29-34: Add upfront validation for the required TestData fields in
StoreEnvironmentValue: check that variableName and bearerToken are not null (and
not empty when reading string values) at the start of the action's execution
(e.g., in the execute/run method of StoreEnvironmentValue) and fail fast with a
clear TestsigmaException or set the action result to failed with a descriptive
message (e.g., "missing required test data: variable-name" or "missing required
test data: token") before any dereference occurs; update all places using
variableName and bearerToken (the spots referenced around lines 63-64 and 84-85)
to rely on this early guard so later code can assume non-null values.
In
`@store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java`:
- Around line 7-8: Remove the unused import of WebAction from the
StoreEnvironmentValue class: update the import block that currently includes
com.testsigma.sdk.WebAction so only com.testsigma.sdk.SalesforceAction remains,
ensuring no other references to WebAction exist in methods or fields of
StoreEnvironmentValue.
In
`@store_environment_value/src/main/java/com/testsigma/addons/windows/StoreEnvironmentValue.java`:
- Around line 7-8: The import com.testsigma.sdk.WebAction is unused in the
StoreEnvironmentValue class (which extends WindowsAction); remove that unused
import from StoreEnvironmentValue.java so only com.testsigma.sdk.WindowsAction
remains, and recompile to ensure no references to WebAction exist in methods of
StoreEnvironmentValue.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: caf5bcf0-d7e0-4306-8931-85c3ad963a8f
📒 Files selected for processing (9)
store_environment_value/pom.xmlstore_environment_value/src/main/java/com/testsigma/addons/android/StoreEnvironmentValue.javastore_environment_value/src/main/java/com/testsigma/addons/ios/StoreEnvironmentValue.javastore_environment_value/src/main/java/com/testsigma/addons/mobileweb/StoreEnvironmentValue.javastore_environment_value/src/main/java/com/testsigma/addons/restapi/StoreEnvironmentValue.javastore_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.javastore_environment_value/src/main/java/com/testsigma/addons/web/StoreEnvironmentValue.javastore_environment_value/src/main/java/com/testsigma/addons/windows/StoreEnvironmentValue.javastore_environment_value/src/main/resources/testsigma-sdk.properties
| package com.testsigma.addons.ios; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.testsigma.sdk.ApplicationType; | ||
| import com.testsigma.sdk.IOSAction; | ||
| 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 com.testsigma.sdk.annotation.TestMachineResult; | ||
| import lombok.Data; | ||
| import org.apache.commons.lang3.exception.ExceptionUtils; | ||
| import org.openqa.selenium.NoSuchElementException; | ||
| import org.openqa.selenium.devtools.v135.io.IO; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
|
|
||
| @Data | ||
| @Action(actionText = "Store environment value using Testsigma API key api-key in runtime variable variable-name", | ||
| description = "Stores environment value in runtime variable", | ||
| applicationType = ApplicationType.IOS, | ||
| useCustomScreenshot = false) | ||
| public class StoreEnvironmentValue extends IOSAction { | ||
|
|
||
| @TestData(reference = "variable-name", isRuntimeVariable = true) | ||
| private com.testsigma.sdk.TestData variableName; | ||
|
|
||
| @TestData(reference = "token") | ||
| private com.testsigma.sdk.TestData bearerToken; | ||
|
|
||
| @RunTimeData | ||
| private com.testsigma.sdk.RunTimeData runTimeData; | ||
|
|
||
| @TestMachineResult | ||
| private com.testsigma.sdk.TestMachineResult testMachineResult; | ||
|
|
||
| @Override | ||
| public Result execute() throws NoSuchElementException { | ||
| Result result = Result.SUCCESS; | ||
| logger.info("Initiating execution"); | ||
| try { | ||
| Long testCaseId = null; | ||
| if (testMachineResult != null && testMachineResult.getSuiteResults() != null && !testMachineResult.getSuiteResults().isEmpty()) { | ||
| com.testsigma.sdk.SuiteResult suiteResult = testMachineResult.getSuiteResults().get(0); | ||
| if (suiteResult.getCaseResults() != null && !suiteResult.getCaseResults().isEmpty()) { | ||
| com.testsigma.sdk.TestCaseResult caseResult = suiteResult.getCaseResults().get(0); | ||
| testCaseId = caseResult.getTestCaseId(); | ||
| logger.info("Extracted testCaseId: " + testCaseId); | ||
| } | ||
| } | ||
|
|
||
| if (testCaseId != null) { | ||
| String url = "https://app.testsigma.com/api/v1/test_case_results?query=testCaseId%3A" + testCaseId + "&sort=createdDate%2Cdesc&page=0&size=1"; | ||
| logger.info("Calling API: " + url); | ||
|
|
||
| HttpClient client = HttpClient.newBuilder().build(); | ||
| HttpRequest request = HttpRequest.newBuilder() | ||
| .uri(URI.create(url)) | ||
| .header("Authorization", "Bearer " + bearerToken.getValue()) | ||
| .GET() | ||
| .build(); | ||
|
|
||
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
|
|
||
| if (response.statusCode() == 200) { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| JsonNode rootNode = mapper.readTree(response.body()); | ||
| JsonNode contentNode = rootNode.path("content"); | ||
|
|
||
| if (contentNode.isArray() && contentNode.size() > 0) { | ||
| JsonNode envNode = contentNode.get(0) | ||
| .path("environmentResult") | ||
| .path("executionResult") | ||
| .path("environment"); | ||
|
|
||
| String envName = envNode.path("name").asText(); | ||
| logger.info("Extracted environment name: " + envName); | ||
|
|
||
| runTimeData.setValue(envName); | ||
| runTimeData.setKey(variableName.getValue().toString()); | ||
| setSuccessMessage("Successfully stored environment name: '" + envName + "' in runtime variable: " + variableName.getValue()); | ||
| } else { | ||
| logger.warn("No content found in API response"); | ||
| setErrorMessage("No content found in API response"); | ||
| result = Result.FAILED; | ||
| } | ||
| } else { | ||
| logger.warn("API call failed with status code: " + response.statusCode()); | ||
| setErrorMessage("API call failed with status code: " + response.statusCode()); | ||
| result = Result.FAILED; | ||
| } | ||
| } else { | ||
| logger.warn("testCaseId not found"); | ||
| setErrorMessage("testCaseId not found"); | ||
| result = Result.FAILED; | ||
| } | ||
| } catch (Exception e) { | ||
| logger.warn("Error Occurred: " + ExceptionUtils.getStackTrace(e)); | ||
| setErrorMessage("Error Occured: " + ExceptionUtils.getMessage(e)); | ||
| result = Result.FAILED; | ||
| } | ||
| return result; | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
Severe code duplication across all 7 platform implementations.
This file is nearly identical to the Android, Web, MobileWeb, Windows, Salesforce, and REST API implementations. Only the package name, import, ApplicationType, and parent class differ.
Consider extracting the shared logic into a common utility class or abstract base class to improve maintainability. Currently, any bug fix or enhancement needs to be applied to 7 files.
Example approach - extract common logic
// Common utility class
public class EnvironmentValueExtractor {
public static String extractEnvironmentName(
TestMachineResult testMachineResult,
String bearerToken,
Logger logger) throws Exception {
// Shared implementation here
}
}
// Platform-specific class becomes thin wrapper
public class StoreEnvironmentValue extends IOSAction {
`@Override`
public Result execute() {
try {
String envName = EnvironmentValueExtractor.extractEnvironmentName(
testMachineResult, bearerToken.getValue().toString(), logger);
runTimeData.setKey(variableName.getValue().toString());
runTimeData.setValue(envName);
setSuccessMessage("Successfully stored environment name: '" + envName + "'");
return Result.SUCCESS;
} catch (Exception e) {
setErrorMessage(e.getMessage());
return Result.FAILED;
}
}
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@store_environment_value/src/main/java/com/testsigma/addons/ios/StoreEnvironmentValue.java`
around lines 1 - 108, The StoreEnvironmentValue class duplicates logic present
across platforms; extract the shared HTTP/JSON/testCaseId parsing logic into a
common helper (e.g., EnvironmentValueExtractor) and make StoreEnvironmentValue a
thin wrapper that calls it from execute(), passing testMachineResult and
bearerToken.getValue(), then only set
runTimeData.setKey(variableName.getValue().toString()) and
runTimeData.setValue(envName) and handle Result and messages there; refactor
references in execute(), and move JSON parsing/HttpClient call/exception
handling into the new utility so other platform classes
(Android/Web/MobileWeb/Windows/Salesforce/REST) can reuse it.
| HttpClient client = HttpClient.newBuilder().build(); | ||
| HttpRequest request = HttpRequest.newBuilder() | ||
| .uri(URI.create(url)) | ||
| .header("Authorization", "Bearer " + bearerToken.getValue()) | ||
| .GET() | ||
| .build(); | ||
|
|
||
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify timeout usage for outbound Java HTTP calls in this addon module.
rg -nP --type=java 'HttpClient\.newBuilder\(|HttpRequest\.newBuilder\(|connectTimeout\(|\.timeout\(' store_environment_value/src/main/java/com/testsigma/addonsRepository: testsigmahq/testsigma-addons
Length of output: 1795
🌐 Web query:
Java HttpClient HttpRequest timeout configuration best practices
💡 Result:
Java HttpClient (java.net.http.HttpClient since Java 11) supports two main timeout configurations: connect timeout at the client level and overall request timeout at the request level. The connect timeout applies when establishing new connections (reused connections ignore it). The request timeout is the minimum of client connect timeout (if applicable) and request timeout, covering the entire request from send to full response receipt. Best practices: - Set connect timeout on HttpClient: 5-20 seconds typical, e.g., Duration.ofSeconds(10). Use HttpClient.newBuilder.connectTimeout(Duration.ofSeconds(10)).build. - Set request timeout on HttpRequest: 30 seconds to 2 minutes, e.g., Duration.ofSeconds(30). Use HttpRequest.newBuilder.timeout(Duration.ofSeconds(30)).build. This overrides or combines with client timeout. - Handle exceptions: HttpConnectTimeoutException for connect failures, HttpTimeoutException for request timeouts. Use try-catch or CompletableFuture.exceptionally for async. - No separate socket/read timeout; request timeout covers response waiting. - Reuse a single HttpClient instance for efficiency; it's thread-safe. - For production, tune based on service SLAs: shorter for internal APIs (5-10s), longer for external (30-60s). Test with slow networks. - Avoid zero/negative durations; defaults have no timeout (may hang indefinitely). Example: import java.net.http.*; import java.time.Duration; import java.net.URI; HttpClient client = HttpClient.newBuilder .connectTimeout(Duration.ofSeconds(10)) .build; HttpRequest request = HttpRequest.newBuilder .uri(URI.create("https://example.com")) .timeout(Duration.ofSeconds(30)) .GET .build; try { HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString); } catch (HttpConnectTimeoutException e) { // Handle connect timeout } catch (HttpTimeoutException e) { // Handle request timeout } Note: This applies to standard JDK HttpClient, not Apache HttpClient (which has connect/socket/response timeouts via RequestConfig). Confirm usage context if Apache.
Citations:
- 1: https://www.baeldung.com/java-httpclient-timeout
- 2: https://docs.oracle.com/en/java/javase/24/docs/api/java.net.http/java/net/http/HttpClient.html
- 3: https://docs.oracle.com/en/java/javase/21/docs/api/java.net.http/java/net/http/HttpClient.html
- 4: https://docs.oracle.com/en/java/javase/21/docs/api/java.net.http/java/net/http/HttpClient.Builder.html
🏁 Script executed:
#!/bin/bash
# Try to locate and examine the specific file directly from common repository structures
find . -name "StoreEnvironmentValue.java" -type f 2>/dev/null | head -5Repository: testsigmahq/testsigma-addons
Length of output: 1887
Add HTTP timeouts to prevent indefinite hangs on external API calls.
Lines 60–67 perform a blocking external call without any timeout configuration. The HttpClient is built with no connectTimeout(), and the HttpRequest has no timeout() set. According to Java HTTP best practices, both should be specified to prevent the client from hanging indefinitely during network issues.
Suggested fix
+import java.time.Duration;
...
- HttpClient client = HttpClient.newBuilder().build();
+ HttpClient client = HttpClient.newBuilder()
+ .connectTimeout(Duration.ofSeconds(10))
+ .build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + bearerToken.getValue())
+ .timeout(Duration.ofSeconds(20))
.GET()
.build();📝 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.
| HttpClient client = HttpClient.newBuilder().build(); | |
| HttpRequest request = HttpRequest.newBuilder() | |
| .uri(URI.create(url)) | |
| .header("Authorization", "Bearer " + bearerToken.getValue()) | |
| .GET() | |
| .build(); | |
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | |
| HttpClient client = HttpClient.newBuilder() | |
| .connectTimeout(Duration.ofSeconds(10)) | |
| .build(); | |
| HttpRequest request = HttpRequest.newBuilder() | |
| .uri(URI.create(url)) | |
| .header("Authorization", "Bearer " + bearerToken.getValue()) | |
| .timeout(Duration.ofSeconds(20)) | |
| .GET() | |
| .build(); | |
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@store_environment_value/src/main/java/com/testsigma/addons/restapi/StoreEnvironmentValue.java`
around lines 60 - 67, The HttpClient and HttpRequest are created without
timeouts which can cause indefinite blocking; update the HttpClient builder used
to create "client" to include a connect timeout (e.g., via
HttpClient.newBuilder().connectTimeout(...)) and set a request-level timeout on
the HttpRequest built into "request" (e.g.,
HttpRequest.newBuilder()....timeout(...)) so that the client.send(...) call will
fail fast on network issues; adjust the timeout durations to sensible values for
your environment and ensure any InterruptedException/IOException handling
remains correct around the send call.
| String envName = envNode.path("name").asText(); | ||
| logger.info("Extracted environment name: " + envName); | ||
|
|
||
| runTimeData.setValue(envName); | ||
| runTimeData.setKey(variableName.getValue().toString()); | ||
| setSuccessMessage("Successfully stored environment name: '" + envName + "' in runtime variable: " + variableName.getValue()); | ||
| } else { |
There was a problem hiding this comment.
Fail when environment name is missing instead of storing an empty runtime value.
Line 80 uses asText() without validating presence. If the field is absent, this stores an empty string and still reports success.
Suggested fix
- String envName = envNode.path("name").asText();
+ String envName = envNode.path("name").asText(null);
+ if (envName == null || envName.isBlank()) {
+ logger.warn("Environment name missing in API response");
+ setErrorMessage("Environment name missing in API response");
+ return Result.FAILED;
+ }
logger.info("Extracted environment name: " + envName);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@store_environment_value/src/main/java/com/testsigma/addons/restapi/StoreEnvironmentValue.java`
around lines 80 - 86, The code currently uses envNode.path("name").asText()
without checking if "name" exists, so empty strings get stored and success is
reported; update StoreEnvironmentValue to first verify the presence and
non-empty value of envNode.get("name") (or envNode.has("name") &&
!envNode.path("name").asText().isEmpty()) before setting envName/runTimeData; if
the "name" field is missing or empty, do not call runTimeData.setValue or
setSuccessMessage — instead call setErrorMessage (or the task-failure mechanism
used in this class) with a clear error and return/throw to mark the step failed;
references: envNode, envName, runTimeData, variableName, setSuccessMessage.
| @Data | ||
| @Action(actionText = "Store environment value using Testsigma API key api-key in runtime variable variable-name", | ||
| description = "Stores environment value in runtime variable", | ||
| applicationType = ApplicationType.Salesforce, | ||
| useCustomScreenshot = false) | ||
| public class StoreEnvironmentValue extends SalesforceAction { | ||
|
|
||
| @TestData(reference = "variable-name", isRuntimeVariable = true) | ||
| private com.testsigma.sdk.TestData variableName; | ||
|
|
||
| @TestData(reference = "token") | ||
| private com.testsigma.sdk.TestData bearerToken; |
There was a problem hiding this comment.
Mismatch between actionText placeholder and TestData reference.
The actionText references api-key but the @TestData annotation uses reference = "token". Users will see "api-key" in the UI but need to provide a value for "token".
Proposed fix - align references
-@Action(actionText = "Store environment value using Testsigma API key api-key in runtime variable variable-name",
+@Action(actionText = "Store environment value using Testsigma API token in runtime variable variable-name",
description = "Stores environment value in runtime variable",
applicationType = ApplicationType.Salesforce,
useCustomScreenshot = false)
public class StoreEnvironmentValue extends SalesforceAction {
`@TestData`(reference = "variable-name", isRuntimeVariable = true)
private com.testsigma.sdk.TestData variableName;
- `@TestData`(reference = "token")
+ `@TestData`(reference = "api-token")
private com.testsigma.sdk.TestData bearerToken;📝 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.
| @Data | |
| @Action(actionText = "Store environment value using Testsigma API key api-key in runtime variable variable-name", | |
| description = "Stores environment value in runtime variable", | |
| applicationType = ApplicationType.Salesforce, | |
| useCustomScreenshot = false) | |
| public class StoreEnvironmentValue extends SalesforceAction { | |
| @TestData(reference = "variable-name", isRuntimeVariable = true) | |
| private com.testsigma.sdk.TestData variableName; | |
| @TestData(reference = "token") | |
| private com.testsigma.sdk.TestData bearerToken; | |
| `@Data` | |
| `@Action`(actionText = "Store environment value using Testsigma API token in runtime variable variable-name", | |
| description = "Stores environment value in runtime variable", | |
| applicationType = ApplicationType.Salesforce, | |
| useCustomScreenshot = false) | |
| public class StoreEnvironmentValue extends SalesforceAction { | |
| `@TestData`(reference = "variable-name", isRuntimeVariable = true) | |
| private com.testsigma.sdk.TestData variableName; | |
| `@TestData`(reference = "api-token") | |
| private com.testsigma.sdk.TestData bearerToken; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java`
around lines 22 - 33, The actionText uses the placeholder "api-key" but the
bearer token TestData is annotated as reference = "token", causing a UI
mismatch; update the TestData reference for the bearerToken field (in class
StoreEnvironmentValue) to match the actionText placeholder (change reference =
"token" to reference = "api-key") or alternatively update actionText to use
"token"—pick one consistent naming and apply it to the `@TestData` on the
bearerToken field so the UI and code reference the same key.
|
|
||
| HttpClient client = HttpClient.newBuilder().build(); | ||
| HttpRequest request = HttpRequest.newBuilder() | ||
| .uri(URI.create(url)) | ||
| .header("Authorization", "Bearer " + bearerToken.getValue()) | ||
| .GET() | ||
| .build(); | ||
|
|
||
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
There was a problem hiding this comment.
HTTP client lacks timeout configuration.
The HttpClient is created without connection or request timeouts. If the API is unresponsive, the action will hang indefinitely, potentially blocking test execution.
Proposed fix - add timeout
- HttpClient client = HttpClient.newBuilder().build();
+ HttpClient client = HttpClient.newBuilder()
+ .connectTimeout(java.time.Duration.ofSeconds(30))
+ .build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + bearerToken.getValue())
+ .timeout(java.time.Duration.ofSeconds(30))
.GET()
.build();📝 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.
| HttpClient client = HttpClient.newBuilder().build(); | |
| HttpRequest request = HttpRequest.newBuilder() | |
| .uri(URI.create(url)) | |
| .header("Authorization", "Bearer " + bearerToken.getValue()) | |
| .GET() | |
| .build(); | |
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | |
| HttpClient client = HttpClient.newBuilder() | |
| .connectTimeout(java.time.Duration.ofSeconds(30)) | |
| .build(); | |
| HttpRequest request = HttpRequest.newBuilder() | |
| .uri(URI.create(url)) | |
| .header("Authorization", "Bearer " + bearerToken.getValue()) | |
| .timeout(java.time.Duration.ofSeconds(30)) | |
| .GET() | |
| .build(); | |
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java`
around lines 59 - 67, The HttpClient in StoreEnvironmentValue is built without
timeouts and can hang; update the HttpClient and HttpRequest creation to include
explicit timeouts (e.g., use
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(30)) and set a
per-request timeout on HttpRequest via .timeout(Duration.ofSeconds(30))) so
requests will fail fast; locate the HttpClient client and HttpRequest request
instantiations in StoreEnvironmentValue and add the Duration-based connect and
request timeouts accordingly.
|
|
||
| String envName = envNode.path("name").asText(); | ||
| logger.info("Extracted environment name: " + envName); | ||
|
|
||
| runTimeData.setValue(envName); | ||
| runTimeData.setKey(variableName.getValue().toString()); | ||
| setSuccessMessage("Successfully stored environment name: '" + envName + "' in runtime variable: " + variableName.getValue()); |
There was a problem hiding this comment.
Empty environment name not validated before reporting success.
JsonNode.path().asText() returns an empty string if the path doesn't exist. The action will store an empty string and report success, which may silently cause downstream failures.
Proposed fix - validate envName
String envName = envNode.path("name").asText();
+ if (envName == null || envName.isEmpty()) {
+ logger.warn("Environment name is empty or missing");
+ setErrorMessage("Environment name is empty or missing in API response");
+ return Result.FAILED;
+ }
logger.info("Extracted environment name: " + envName);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java`
around lines 79 - 85, envName may be empty because JsonNode.path(...).asText()
returns "" when missing; add a guard after extracting envName (the variable
envName from envNode) that checks if envName.trim().isEmpty(), and if so do not
call runTimeData.setValue(...) or setSuccessMessage(...); instead call the
action's error reporting (e.g., setErrorMessage or appropriate failure method)
with a clear message referencing the envNode and variableName.getValue(), and
return/exit the method early; otherwise continue with the existing
runTimeData.setKey(...)/setValue(...) and setSuccessMessage(...) flow.
| logger.warn("Error Occurred: " + ExceptionUtils.getStackTrace(e)); | ||
| setErrorMessage("Error Occured: " + ExceptionUtils.getMessage(e)); | ||
| result = Result.FAILED; |
There was a problem hiding this comment.
Typo: "Error Occured" should be "Error Occurred".
Proposed fix
- setErrorMessage("Error Occured: " + ExceptionUtils.getMessage(e));
+ setErrorMessage("Error Occurred: " + ExceptionUtils.getMessage(e));📝 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.
| logger.warn("Error Occurred: " + ExceptionUtils.getStackTrace(e)); | |
| setErrorMessage("Error Occured: " + ExceptionUtils.getMessage(e)); | |
| result = Result.FAILED; | |
| logger.warn("Error Occurred: " + ExceptionUtils.getStackTrace(e)); | |
| setErrorMessage("Error Occurred: " + ExceptionUtils.getMessage(e)); | |
| result = Result.FAILED; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@store_environment_value/src/main/java/com/testsigma/addons/salesforce/StoreEnvironmentValue.java`
around lines 102 - 104, Fix the typo in the error messages inside
StoreEnvironmentValue where "Error Occured" is used: update the messages passed
to logger.warn(...) and setErrorMessage(...) to read "Error Occurred" (e.g.,
change the string in the logger.warn call that currently concatenates
ExceptionUtils.getStackTrace(e) and the string passed to setErrorMessage that
uses ExceptionUtils.getMessage(e)); ensure both places are updated so the log
and the UI error text are consistent.
| @@ -0,0 +1 @@ | |||
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjYwOTAiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.J7zfur9Wk9NKUzQYtCd8dyjk7_OPBOXFVL33fara9n58ZsjsJhn7VozVi2yRkIQiJTDArqEY07Q_r1ibWj5ljQ No newline at end of file | |||
There was a problem hiding this comment.
Critical: Hardcoded API key committed to repository.
This JWT token is a secret credential that should never be committed to source control. This addon is being published as PUBLIC per the PR description, which will expose this key to anyone.
Immediate actions required:
- Remove this file from the repository
- Rotate/revoke this API key immediately as it may already be compromised in git history
- Use environment variables or a secure secrets manager to provide the key at runtime
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@store_environment_value/src/main/resources/testsigma-sdk.properties` at line
1, The committed testsigma-sdk.properties contains a hardcoded JWT API key which
must be removed: delete this file from the repo, remove it from future commits
(use git rm --cached if already committed) and add its name/pattern to
.gitignore; rotate/revoke the exposed API key immediately outside the codebase;
replace usage of the file in code by reading the credential from a secure source
(e.g., environment variable like TESTSIGMA_API_KEY or a secrets manager)
wherever the testsigma-sdk.api.key value was referenced so functions/classes
that previously relied on testsigma-sdk.properties now read
process/environment-backed configuration.
Publish this addon as PUBLIC
Addon Name: Store Environment Value
Jarvis Link: https://jarvis.testsigma.com/ui/tenants/2817/addons
Jira : https://testsigma.atlassian.net/browse/CUS-11412
Added class to store environment value in runtime variable
Summary by CodeRabbit