Skip to content

Conversation

@ManojTestsigma
Copy link
Contributor

@ManojTestsigma ManojTestsigma commented Nov 28, 2025

please review this addon and publish as PUBLIC

Addon name : Excel To Json Util
Addon accont: https://jarvis.testsigma.com/ui/tenants/3072/addons
Jira: https://testsigma.atlassian.net/browse/CUS-9364

Summary by CodeRabbit

  • New Features

    • Row-to-JSON conversion added for Web, Android, and iOS actions—supports CSV, XLS, XLSX and remote URLs; outputs as JSON string or JSON file and stores results in runtime variables.
    • Utility added to detect file type, read headers, and convert a specified row to JSON with robust cell handling.
  • Chores

    • Project build/configuration added and source attachments enabled.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Walkthrough

Adds a new Maven module that converts a specific row from CSV/Excel files to JSON, including a core utility for file handling and parsing, platform-specific actions for Web/Android/iOS, and project configuration/resources.

Changes

Cohort / File(s) Summary
Project configuration & properties
excel_to_json_util/pom.xml, excel_to_json_util/src/main/resources/testsigma-sdk.properties
Adds Maven project file with dependencies (TestSigma SDK, Lombok, Selenium, POI, Jackson, commons libs, test frameworks), build plugins (maven-shade, maven-source), and a testsigma-sdk property file containing an API key.
Core conversion utility
excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java
New utility class that detects CSV/Excel, supports local and HTTP(S) sources, reads header row and a target data row, maps headers→values handling STRING/NUMERIC/DATE/BOOLEAN/FORMULA/BLANK, and returns a JSON string; exposes methods for URL-to-file conversion and row-to-JSON conversion.
Platform action classes
excel_to_json_util/src/main/java/com/testsigma/addons/web/ExcelRowToJsonWebAction.java, excel_to_json_util/src/main/java/com/testsigma/addons/android/ExcelRowToJsonAndroidAction.java, excel_to_json_util/src/main/java/com/testsigma/addons/ios/ExcelRowToJsonIOSAction.java
New Web/Android/iOS action classes that accept row-number, file-path, format (JSON string or JSON file), and variable-name; validate inputs, call ExcelFileUtils.convertRowToJson(...), store JSON or file-path into runtime data, and handle NumberFormatException, IOExceptions, and generic exceptions.

Sequence Diagram(s)

sequenceDiagram
    participant Action as Platform Action (Web/Android/iOS)
    participant Utils as ExcelFileUtils
    participant FS as File System / Temp Files
    participant Runtime as RunTimeData

    Action->>Utils: convertRowToJson(filePath, rowNumber)
    alt filePath is HTTP(S)
        Utils->>FS: download remote file to temp
        FS-->>Utils: temp file path
    end
    Utils->>Utils: detect extension (csv/xls/xlsx) and parse
    Utils-->>Action: return JSON string
    alt format == "JSON string"
        Action->>Runtime: put(variableName, jsonString)
        Runtime-->>Action: ack
    else format == "JSON file"
        Action->>FS: write temp JSON file
        FS-->>Action: json file path
        Action->>Runtime: put(variableName, jsonFilePath)
        Runtime-->>Action: ack
    end
    Action-->>Action: set SUCCESS / set FAILED on exceptions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • Review focus:
    • ExcelFileUtils: URL download, temp file lifecycle, CSV vs Excel detection, cell-type handling (dates, formulas), and JSON escaping.
    • Action classes: consistent input validation, error messages, and correct RunTimeData usage.
    • pom.xml: dependency versions and plugin configuration sanity.

Suggested reviewers

  • Ganesh-Testsigma
  • vigneshtestsigma

Poem

🐰 I hopped through rows with eager cheer,
Keys from headers, values clear.
From CSV, XLSX, a JSON tune—
I stash the file or string for you soon. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: converting Excel rows with headers into JSON string/file format.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch CUS-9364

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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: 9

🧹 Nitpick comments (6)
excel_to_json_util/pom.xml (1)

36-46: JUnit milestone version and TestNG scope issue.

  1. JUnit Jupiter 5.8.0-M1 is a pre-release milestone version. Use a stable release (e.g., 5.10.0 or later).
  2. TestNG dependency is missing <scope>test</scope>, causing it to be bundled in the production artifact.
     <dependency>
         <groupId>org.junit.jupiter</groupId>
         <artifactId>junit-jupiter-api</artifactId>
-        <version>${junit.jupiter.version}</version>
+        <version>5.10.0</version>
         <scope>test</scope>
     </dependency>
     <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
-        <version>6.14.3</version>
+        <version>7.8.0</version>
+        <scope>test</scope>
     </dependency>
excel_to_json_util/src/main/java/com/testsigma/addons/ios/ExcelRowToJsonIOSAction.java (1)

12-12: Unused import: NoSuchElementException.

NoSuchElementException is imported and declared in the method signature but never thrown or caught within this action. Consider removing the import and the throws clause.

excel_to_json_util/src/main/java/com/testsigma/addons/android/ExcelRowToJsonAndroidAction.java (1)

39-93: Consider extracting common logic to reduce duplication.

The execute() method is nearly identical across iOS, Android, and Web actions. Consider extracting the core logic to a shared helper method or abstract base class to improve maintainability and reduce the risk of divergent bug fixes.

// Example: Add a static helper in ExcelFileUtils
public static void processAndStoreResult(
    String filePathStr, int rowNum, String varName, String format,
    Consumer<com.testsigma.sdk.RunTimeData> runTimeDataSetter,
    Consumer<String> successMessageSetter, Logger logger) throws IOException {
    // Common logic here
}
excel_to_json_util/src/main/java/com/testsigma/addons/web/ExcelRowToJsonWebAction.java (1)

18-18: Inconsistent actionText wording across platforms.

The Web action uses "...file-path in format into the runtime variable..." while iOS/Android use "...file-path into the format in runtime variable...". Consider aligning the wording for consistency across platforms.

excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java (2)

63-64: Incorrect log level for error scenario.

Error conditions should use logger.error or at minimum logger.warn, not logger.info. This makes it harder to filter and detect issues in logs.

-            logger.info("Error while accessing: " + url);
-            logger.debug(ExceptionUtils.getStackTrace(e));
+            logger.error("Error while accessing: " + url);
+            logger.error(ExceptionUtils.getStackTrace(e));

178-193: Temp files not cleaned up after processing.

The method relies on deleteOnExit() for temp file cleanup, but this only occurs on JVM termination. In long-running processes or high-volume conversions, temp files accumulate on disk. Consider explicit cleanup after processing.

 public String convertRowToJson(String filePath, int rowNumber) throws IOException {
     // Convert URL to file if needed
     File file = urlToFileConverter(filePath);
     String fileName = file.getName().toLowerCase();
+    boolean isTempFile = !filePath.equals(file.getAbsolutePath());

-    // Determine file type and process accordingly
-    if (fileName.endsWith(".csv")) {
-        return convertCsvRowToJson(file.getAbsolutePath(), rowNumber);
-    } else if (fileName.endsWith(".xlsx")) {
-        return convertExcelRowToJson(file.getAbsolutePath(), rowNumber, true);
-    } else if (fileName.endsWith(".xls")) {
-        return convertExcelRowToJson(file.getAbsolutePath(), rowNumber, false);
-    } else {
-        throw new IOException("Unsupported file format. Supported formats: .csv, .xls, .xlsx");
+    try {
+        // Determine file type and process accordingly
+        if (fileName.endsWith(".csv")) {
+            return convertCsvRowToJson(file.getAbsolutePath(), rowNumber);
+        } else if (fileName.endsWith(".xlsx")) {
+            return convertExcelRowToJson(file.getAbsolutePath(), rowNumber, true);
+        } else if (fileName.endsWith(".xls")) {
+            return convertExcelRowToJson(file.getAbsolutePath(), rowNumber, false);
+        } else {
+            throw new IOException("Unsupported file format. Supported formats: .csv, .xls, .xlsx");
+        }
+    } finally {
+        if (isTempFile && file.exists()) {
+            file.delete();
+        }
     }
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d4687d and 77c3f11.

📒 Files selected for processing (6)
  • excel_to_json_util/pom.xml (1 hunks)
  • excel_to_json_util/src/main/java/com/testsigma/addons/android/ExcelRowToJsonAndroidAction.java (1 hunks)
  • excel_to_json_util/src/main/java/com/testsigma/addons/ios/ExcelRowToJsonIOSAction.java (1 hunks)
  • excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java (1 hunks)
  • excel_to_json_util/src/main/java/com/testsigma/addons/web/ExcelRowToJsonWebAction.java (1 hunks)
  • excel_to_json_util/src/main/resources/testsigma-sdk.properties (1 hunks)
🔇 Additional comments (2)
excel_to_json_util/src/main/java/com/testsigma/addons/web/ExcelRowToJsonWebAction.java (1)

33-34: Verify isRuntimeVariable = true annotation.

The variable-name field has isRuntimeVariable = true in the Web action but not in iOS/Android. Ensure this difference is intentional for the SDK behavior on each platform.

excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java (1)

220-221: Formula cells return formula text instead of computed value.

The FORMULA case returns the formula string (e.g., "=SUM(A1:A10)") rather than the evaluated result. Users typically expect the computed value. Consider using FormulaEvaluator to get the actual value.

+    private FormulaEvaluator formulaEvaluator; // Initialize in convertExcelRowToJson
+
     private String getCellValueAsString(Cell cell) {
         // ... existing cases ...
         case FORMULA:
-            return cell.getCellFormula();
+            try {
+                CellValue cellValue = formulaEvaluator.evaluate(cell);
+                switch (cellValue.getCellType()) {
+                    case STRING:
+                        return cellValue.getStringValue();
+                    case NUMERIC:
+                        double numVal = cellValue.getNumberValue();
+                        return numVal == (long) numVal ? String.valueOf((long) numVal) : String.valueOf(numVal);
+                    case BOOLEAN:
+                        return String.valueOf(cellValue.getBooleanValue());
+                    default:
+                        return "";
+                }
+            } catch (Exception e) {
+                return cell.getCellFormula(); // Fallback to formula string
+            }

Please verify if returning the formula text is the intended behavior or if users expect the computed value.

Copy link

@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: 3

♻️ Duplicate comments (3)
excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java (3)

100-104: The missing validation for rowNumber < 1 was flagged in a previous review. Passing rowNumber = 0 or negative values will cause IndexOutOfBoundsException at line 104.


147-151: The missing validation for rowNumber < 1 was flagged in a previous review. Passing rowNumber = 0 would return header row data, inconsistent with documented behavior.


251-260: The missing \b (backspace) and \f (form feed) escaping was flagged in a previous review. Per RFC 8259, these control characters must be escaped in JSON strings.

🧹 Nitpick comments (4)
excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java (4)

21-24: Make the logger field private final.

The logger field is package-private and mutable. It should be private final for proper encapsulation.

-    Logger logger;
+    private final Logger logger;
+
     public ExcelFileUtils(Logger logger) {
         this.logger = logger;
     }

42-42: Misleading log message.

The log says "s3 url" but this branch handles any HTTP/HTTPS URL, not just S3. Consider generalizing to "remote URL" or "HTTP(S) URL".


50-50: Add connection and read timeouts to prevent hanging.

FileUtils.copyURLToFile without timeout parameters can block indefinitely if the server doesn't respond. Use the overload with timeout parameters.

-                FileUtils.copyURLToFile(urlObject, tempFile);
+                int connectionTimeoutMs = 30_000; // 30 seconds
+                int readTimeoutMs = 60_000; // 60 seconds
+                FileUtils.copyURLToFile(urlObject, tempFile, connectionTimeoutMs, readTimeoutMs);

203-226: Consider handling ERROR cell type explicitly.

Cells with errors (e.g., #DIV/0!, #REF!) fall through to the default case and return an empty string silently. Consider returning the error code or logging a warning so users are aware of problematic cells.

+            case ERROR:
+                return FormulaError.forInt(cell.getErrorCellValue()).getString();
             case BLANK:
                 return "";
             default:
                 return "";
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77c3f11 and 51bf50f.

📒 Files selected for processing (1)
  • excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java (1 hunks)
🔇 Additional comments (1)
excel_to_json_util/src/main/java/com/testsigma/addons/util/ExcelFileUtils.java (1)

232-246: LGTM!

The manual JSON construction is straightforward for this simple key-value use case. The escaping is properly delegated to escapeJson.

@ManojTestsigma ManojTestsigma merged commit b7972cb into dev Dec 9, 2025
2 checks passed
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.

3 participants