Skip to content

feat/CR-2026-CSV File is taken from upload section,updates it and store the tmp path in runtime variable#126

Merged
akhil-testsigma merged 1 commit intodevfrom
feat/CR-2026-CSV-File-is-taken-from-upload-section,updates-it-and-store-the-tmp-path-in-runtime-variable
Mar 13, 2025
Merged

feat/CR-2026-CSV File is taken from upload section,updates it and store the tmp path in runtime variable#126
akhil-testsigma merged 1 commit intodevfrom
feat/CR-2026-CSV-File-is-taken-from-upload-section,updates-it-and-store-the-tmp-path-in-runtime-variable

Conversation

@akhil-testsigma
Copy link
Copy Markdown
Contributor

@akhil-testsigma akhil-testsigma commented Mar 13, 2025

JIRA

https://testsigma.atlassian.net/browse/CR-2026

Fix

CSV File is taken from upload section, updates it and store the tmp path in runtime variable.

Summary by CodeRabbit

  • New Features

    • Introduced a functionality that allows users to update CSV file content with provided test data, automatically generating a new file reference for subsequent use.
  • Chores

    • Enhanced project configuration and dependency management, including new secure integration settings for API authentication.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 13, 2025

Walkthrough

This pull request introduces a new Maven project configuration for csv_file_update_from_upload_section by adding a Maven POM file with detailed project metadata, dependencies, and build plugins. Additionally, it adds a new Java class, WriteCsvFileandStorePath, in the Testsigma framework to handle CSV file updates, and a properties file containing an API key. The changes establish file manipulation and runtime storage functionalities for CSV file data updates.

Changes

File(s) Summary
csv_file_update_from_upload_section/pom.xml New POM file defining project metadata, dependencies (Testsigma SDK, Lombok, JUnit, TestNG, Selenium, etc.), and build plugins (Shade & Source) configurations.
csv_file_update_from_upload_section/src/main/java/.../WriteCsvFileandStorePath.java New Java class added to perform CSV updates: reads a CSV file, updates a specific cell, writes to a temporary file, and stores the updated file path.
csv_file_update_from_upload_section/src/main/resources/testsigma-sdk.properties New properties file added with a single API key (testsigma-sdk.api.key) configuration for Testsigma SDK.

Sequence Diagram(s)

sequenceDiagram
    actor Tester as Test Runner
    participant Action as WriteCsvFileandStorePath
    participant FS as File System
    participant CSV as CSVReader/CSVWriter
    participant Runtime as Runtime Variable Store

    Tester->>Action: execute(test data)
    Action->>FS: convertToFile(path or URL)
    FS-->>Action: Return file reference
    Action->>CSV: Read CSV data
    CSV-->>Action: Return CSV content
    Action->>CSV: Update cell & write to temporary file
    CSV-->>Action: Confirm write success
    Action->>Runtime: Store updated file path
    Action->>Tester: Return success result
Loading

Possibly related PRs

Suggested reviewers

  • vigneshtestsigma

Poem

Hop, hop, hop, I’m a coding bunny,
Crafting changes that make work less runny.
CSV rows dance with a leap and a twirl,
As the API key gives a magical whirl.
With lines of code and a joyful cheer,
I celebrate the updates, oh so dear!
🐰💻✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
csv_file_update_from_upload_section/pom.xml (2)

12-15: Consider reviewing the compiler source/target versions if a newer Java version is desired.

You're currently using Java 11. This is perfectly acceptable, but if you plan to migrate in the near future, you can adjust <maven.compiler.source> and <maven.compiler.target> accordingly.


24-47: Unify or clarify usage of JUnit and TestNG test frameworks.

Your POM includes both JUnit 5 (Milestone release 5.8.0-M1) and TestNG (6.14.3). Mixing two testing frameworks can cause confusion and extra overhead. Consider choosing one framework and upgrading to its stable, more modern version to simplify maintenance.

-        <dependency>
-            <groupId>org.junit.jupiter</groupId>
-            <artifactId>junit-jupiter-api</artifactId>
-            <version>${junit.jupiter.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.testng</groupId>
-            <artifactId>testng</artifactId>
-            <version>6.14.3</version>
-        </dependency>
+        <!-- Choose either JUnit 5 or TestNG and remove the other to avoid confusion -->
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1)

132-153: Optional file type validation and adjustable timeouts.

  1. File extension checks: You may want to verify the file extension if you want to strictly handle CSV only, especially for remote downloads.
  2. Timeout settings: The 10s read/connect timeouts could be too short or too generous depending on network conditions. Consider externalizing them as config so they are easier to modify.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 141d762 and 9a619f9.

📒 Files selected for processing (3)
  • csv_file_update_from_upload_section/pom.xml (1 hunks)
  • csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1 hunks)
  • csv_file_update_from_upload_section/src/main/resources/testsigma-sdk.properties (1 hunks)
🧰 Additional context used
🪛 Gitleaks (8.21.2)
csv_file_update_from_upload_section/src/main/resources/testsigma-sdk.properties

1-1: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.

(jwt)

🔇 Additional comments (3)
csv_file_update_from_upload_section/pom.xml (2)

2-9: Good project metadata definition.

Your groupId, artifactId, and version are clearly defined. The initial setup appears standard and well-structured.


88-119: Build plugin configurations look correct.

The Maven Shade Plugin and Source Plugin sections are properly set up to shade dependencies and attach sources. This should meet the packaging requirements for your new module.

csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1)

30-44: Clear parameter definitions.

The @TestData fields are well-labeled, indicating row, column, file path, data to write, and runtime variable name. This helps maintain clarity in your test setup.

@@ -0,0 +1 @@
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjQ0NTgiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.atlDcaLnjdkUwsm9carKsEeRawxn9fNzRaxcn_5itgen2xFPovxDR7QlyzG_HmdlRmxHp8vmjEXH2Y-6A1xszQ No newline at end of file
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

Remove or mask the JWT from the public code to avoid critical security leaks.

Embedding JWTs in source code can lead to unauthorized access. Instead, store this secret in an environment variable or a secure secrets manager.

Below is a possible diff that demonstrates how to replace the inline token with an environment-based property (adjust the key name as needed):

- testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9...
+ testsigma-sdk.api.key=${TESTSIGMA_SDK_API_KEY}
📝 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
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjQ0NTgiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.atlDcaLnjdkUwsm9carKsEeRawxn9fNzRaxcn_5itgen2xFPovxDR7QlyzG_HmdlRmxHp8vmjEXH2Y-6A1xszQ
testsigma-sdk.api.key=${TESTSIGMA_SDK_API_KEY}
🧰 Tools
🪛 Gitleaks (8.21.2)

1-1: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.

(jwt)

Comment on lines +49 to +129
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating execution");

com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;

String filePathString = filePath.getValue().toString();
String replace = testData.getValue().toString();
int targetRow = Integer.parseInt(row.getValue().toString());
int targetColumn = Integer.parseInt(column.getValue().toString());

File csvFile = null;
File tempCsvFile = null;

try {
csvFile = convertToFile(filePathString);
logger.info("CSV file path: " + csvFile.getAbsolutePath());

if (csvFile == null || !csvFile.exists()) {
setErrorMessage("CSV File not found or could not be downloaded: " + filePathString);
return com.testsigma.sdk.Result.FAILED;
}

// Create a unique temp file each time
String uniqueFileName = "updated_" + System.currentTimeMillis() + ".csv";
tempCsvFile = new File(csvFile.getParentFile(), uniqueFileName);
logger.info("Temp file path: " + tempCsvFile.getAbsolutePath());
Files.copy(csvFile.toPath(), tempCsvFile.toPath(), StandardCopyOption.REPLACE_EXISTING);

CSVReader csvReader = null;
CSVWriter writer = null;
try {
csvReader = new CSVReader(new FileReader(tempCsvFile));
List<String[]> data = csvReader.readAll();

int rowIndex = targetRow - 1;
int columnIndex = targetColumn - 1;

while (data.size() <= rowIndex) {
data.add(new String[Math.max(columnIndex + 1, 0)]);
}
String[] targetRowData = data.get(rowIndex);
if (targetRowData.length <= columnIndex) {
String[] newRow = new String[columnIndex + 1];
System.arraycopy(targetRowData, 0, newRow, 0, targetRowData.length);
data.set(rowIndex, newRow);
targetRowData = newRow;
}
targetRowData[columnIndex] = replace;

writer = new CSVWriter(new FileWriter(tempCsvFile));
writer.writeAll(data);
writer.flush();
} finally {
if (csvReader != null) {
try {
csvReader.close();
} catch (IOException e) {
logger.warn("Error closing CSVReader: " + e.getMessage() + e);
}
}
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
logger.warn("Error closing CSVWriter: " + e.getMessage() + e);
}
}
}

// Store the path of the new updated file
runTimeData.setKey(variableName.getValue().toString());
runTimeData.setValue(tempCsvFile.getAbsolutePath()); // Store absolute path of the new file

setSuccessMessage("Data is updated successfully in the CSV file. Updated data is " + replace + ". File path stored in runtime variable: " + variableName.getValue().toString() + " = " + tempCsvFile.getAbsolutePath());
} catch (Exception e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Operation Failed: " + e.getMessage());
logger.warn("Error during CSV processing: " + e.getMessage() + e);
}

return result;
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

Validate row/column inputs and consider large CSV read performance.

  1. Boundary checks: Ensure row and column are positive, or handle negative or zero values with clear error messages.
  2. Memory usage: csvReader.readAll() loads the entire CSV into memory, which can be problematic for large files. Consider streaming or incremental reading if large files are common.
  3. Resource handling: Switching to try-with-resources for CSVReader and CSVWriter can simplify cleanup and reduce error-prone boilerplate.
try (CSVReader csvReader = new CSVReader(new FileReader(tempCsvFile));
     CSVWriter writer = new CSVWriter(new FileWriter(tempCsvFile))) {
-    List<String[]> data = csvReader.readAll();
+    // Example boundary checks
+    if (targetRow <= 0 || targetColumn <= 0) {
+        setErrorMessage("Row and Column must be positive integers.");
+        return com.testsigma.sdk.Result.FAILED;
+    }
    
    List<String[]> data = csvReader.readAll();
    // ... proceed with updates
}
📝 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
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating execution");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
String filePathString = filePath.getValue().toString();
String replace = testData.getValue().toString();
int targetRow = Integer.parseInt(row.getValue().toString());
int targetColumn = Integer.parseInt(column.getValue().toString());
File csvFile = null;
File tempCsvFile = null;
try {
csvFile = convertToFile(filePathString);
logger.info("CSV file path: " + csvFile.getAbsolutePath());
if (csvFile == null || !csvFile.exists()) {
setErrorMessage("CSV File not found or could not be downloaded: " + filePathString);
return com.testsigma.sdk.Result.FAILED;
}
// Create a unique temp file each time
String uniqueFileName = "updated_" + System.currentTimeMillis() + ".csv";
tempCsvFile = new File(csvFile.getParentFile(), uniqueFileName);
logger.info("Temp file path: " + tempCsvFile.getAbsolutePath());
Files.copy(csvFile.toPath(), tempCsvFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
CSVReader csvReader = null;
CSVWriter writer = null;
try {
csvReader = new CSVReader(new FileReader(tempCsvFile));
List<String[]> data = csvReader.readAll();
int rowIndex = targetRow - 1;
int columnIndex = targetColumn - 1;
while (data.size() <= rowIndex) {
data.add(new String[Math.max(columnIndex + 1, 0)]);
}
String[] targetRowData = data.get(rowIndex);
if (targetRowData.length <= columnIndex) {
String[] newRow = new String[columnIndex + 1];
System.arraycopy(targetRowData, 0, newRow, 0, targetRowData.length);
data.set(rowIndex, newRow);
targetRowData = newRow;
}
targetRowData[columnIndex] = replace;
writer = new CSVWriter(new FileWriter(tempCsvFile));
writer.writeAll(data);
writer.flush();
} finally {
if (csvReader != null) {
try {
csvReader.close();
} catch (IOException e) {
logger.warn("Error closing CSVReader: " + e.getMessage() + e);
}
}
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
logger.warn("Error closing CSVWriter: " + e.getMessage() + e);
}
}
}
// Store the path of the new updated file
runTimeData.setKey(variableName.getValue().toString());
runTimeData.setValue(tempCsvFile.getAbsolutePath()); // Store absolute path of the new file
setSuccessMessage("Data is updated successfully in the CSV file. Updated data is " + replace + ". File path stored in runtime variable: " + variableName.getValue().toString() + " = " + tempCsvFile.getAbsolutePath());
} catch (Exception e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Operation Failed: " + e.getMessage());
logger.warn("Error during CSV processing: " + e.getMessage() + e);
}
return result;
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating execution");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
String filePathString = filePath.getValue().toString();
String replace = testData.getValue().toString();
int targetRow = Integer.parseInt(row.getValue().toString());
int targetColumn = Integer.parseInt(column.getValue().toString());
File csvFile = null;
File tempCsvFile = null;
try {
csvFile = convertToFile(filePathString);
logger.info("CSV file path: " + csvFile.getAbsolutePath());
if (csvFile == null || !csvFile.exists()) {
setErrorMessage("CSV File not found or could not be downloaded: " + filePathString);
return com.testsigma.sdk.Result.FAILED;
}
// Create a unique temp file each time
String uniqueFileName = "updated_" + System.currentTimeMillis() + ".csv";
tempCsvFile = new File(csvFile.getParentFile(), uniqueFileName);
logger.info("Temp file path: " + tempCsvFile.getAbsolutePath());
Files.copy(csvFile.toPath(), tempCsvFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
try (CSVReader csvReader = new CSVReader(new FileReader(tempCsvFile));
CSVWriter writer = new CSVWriter(new FileWriter(tempCsvFile))) {
// Example boundary checks
if (targetRow <= 0 || targetColumn <= 0) {
setErrorMessage("Row and Column must be positive integers.");
return com.testsigma.sdk.Result.FAILED;
}
List<String[]> data = csvReader.readAll();
int rowIndex = targetRow - 1;
int columnIndex = targetColumn - 1;
while (data.size() <= rowIndex) {
data.add(new String[Math.max(columnIndex + 1, 0)]);
}
String[] targetRowData = data.get(rowIndex);
if (targetRowData.length <= columnIndex) {
String[] newRow = new String[columnIndex + 1];
System.arraycopy(targetRowData, 0, newRow, 0, targetRowData.length);
data.set(rowIndex, newRow);
targetRowData = newRow;
}
targetRowData[columnIndex] = replace;
writer.writeAll(data);
writer.flush();
}
// Store the path of the new updated file
runTimeData.setKey(variableName.getValue().toString());
runTimeData.setValue(tempCsvFile.getAbsolutePath()); // Store absolute path of the new file
setSuccessMessage("Data is updated successfully in the CSV file. Updated data is " + replace + ". File path stored in runtime variable: " + variableName.getValue().toString() + " = " + tempCsvFile.getAbsolutePath());
} catch (Exception e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Operation Failed: " + e.getMessage());
logger.warn("Error during CSV processing: " + e.getMessage() + e);
}
return result;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants