Skip to content

Conversation

@akhil-testsigma
Copy link
Contributor

@akhil-testsigma akhil-testsigma commented Sep 3, 2025

Addon Name: Copy clipboard data
Jarvis Link: https://jarvis-in.testsigma.com/ui/tenants/3/users
Jira : https://testsigma.atlassian.net/browse/TE-29457
Added try-catch blocks and integrated addon to handle in-region

Summary by CodeRabbit

  • New Features

    • Introduced a “Copy clipboard data” action across Android, iOS, Web, and Mobile Web.
    • Reads the device/system clipboard and saves the content into a runtime variable you specify.
    • Provides clear success/error messaging during execution.
  • Chores

    • Added a new module with build settings to produce a self-contained distributable and attached sources for easier integration.

@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

Adds a new Maven module copy_clipboard_data with four platform-specific Copyclipboard actions (Android, iOS, Web, Mobile Web) that read clipboard text and store it into a runtime variable. Includes helper methods to access clipboard data and a properties file with a testsigma-sdk.api.key.

Changes

Cohort / File(s) Summary of changes
Maven module setup
copy_clipboard_data/pom.xml
New module POM targeting Java 11; adds dependencies (Testsigma SDK, Selenium, TestNG/JUnit, Jackson, etc.); configures maven-shade-plugin for uber-jar; attaches sources; sets finalName.
Android clipboard action
copy_clipboard_data/src/main/java/com/testsigma/addons/android/Copyclipboard.java
New AndroidAction that fetches clipboard via AndroidDriver.getClipboardText(), saves to RunTimeData using key from TestData, returns SUCCESS/FAILED with log messaging.
iOS clipboard action
copy_clipboard_data/src/main/java/com/testsigma/addons/ios/Copyclipboard.java
New IOSAction that fetches clipboard via IOSDriver.getClipboardText(), saves to RunTimeData using key from TestData, returns SUCCESS/FAILED with log messaging.
Web + Mobile Web clipboard actions
copy_clipboard_data/src/main/java/com/testsigma/addons/web/Copyclipboard.java, copy_clipboard_data/src/main/java/com/testsigma/addons/mobileweb/Copyclipboard.java
New WebAction implementations that read system clipboard via AWT Toolkit, save to RunTimeData using key from TestData, return SUCCESS/FAILED with log messaging.
SDK configuration
copy_clipboard_data/src/main/resources/testsigma-sdk.properties
Adds testsigma-sdk.api.key property.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Runner as Test Execution
  participant Action as Copyclipboard Action
  participant Driver as Platform Driver / System Clipboard
  participant RTD as RunTimeData

  Runner->>Action: execute()
  alt Android / iOS
    Action->>Driver: getClipboardText()
    Driver-->>Action: clipboard string
  else Web / Mobile Web
    Action->>Driver: AWT Toolkit.getSystemClipboard().getData()
    Driver-->>Action: clipboard string or null
  end
  Action->>RTD: set(key from TestData, value=clipboard)
  Action-->>Runner: Result (SUCCESS or FAILED) + message
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • vigneshtestsigma
  • Ganesh-Testsigma

Poem

A nibble of text from the air I see,
Snipped from the clip to set it free.
Droid, iOS, web alike,
Hop-hopping keys on every strike.
Into runtime burrows it’ll stay—
Clipboard crumbs guide my way.
(_/) ✨ Clipboard to cache, hooray!

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/TE-29457-Added-try-catch-blocks-and-integrated-addon-to-handle-in-region

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

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

🧹 Nitpick comments (10)
copy_clipboard_data/pom.xml (2)

59-63: Avoid pinning old jackson-annotations; remove or align via a BOM.

Selenium/Appium already pull compatible Jackson versions. Keeping 2.13.0 risks dependency convergence and CVE backports.

-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-annotations</artifactId>
-            <version>2.13.0</version>
-        </dependency>

If you must pin, consider a current 2.17.x/2.18.x and import jackson-bom.


72-101: Enforce Java 11 with compiler plugin and keep it out of shaded output.

Explicitly configure maven-compiler-plugin; current properties alone rely on defaults.

         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.11.0</version>
+                <configuration>
+                    <release>11</release>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>

Optional: add shade minimization/exclusions so test deps never sneak in.

copy_clipboard_data/src/main/java/com/testsigma/addons/web/Copyclipboard.java (2)

17-21: Tighten action text for clarity.

-@Action(actionText = "Copy data from the clipboard and store into a runtime variable testdata",
-        description = "Copying the data from the clipboard and store into a runtime variable",
+@Action(actionText = "Copy clipboard text into runtime variable testdata",
+        description = "Reads system clipboard text and stores it into the provided runtime variable",
         applicationType = ApplicationType.WEB)

21-21: Class naming style.

Consider renaming to CopyClipboard for standard Java PascalCase.

copy_clipboard_data/src/main/java/com/testsigma/addons/ios/Copyclipboard.java (1)

19-20: Consistent field naming.

Rename testData1 -> testdata for parity with other platforms.

copy_clipboard_data/src/main/java/com/testsigma/addons/mobileweb/Copyclipboard.java (1)

21-62: Deduplicate clipboard utility across Web and MobileWeb.

Both classes implement identical AWT clipboard helpers. Extract to a small internal util (e.g., com.testsigma.addons.util.ClipboardUtils) to reduce divergence.

copy_clipboard_data/src/main/java/com/testsigma/addons/android/Copyclipboard.java (4)

25-25: Align throws with catch-all or remove it for clarity.

The method catches all Exceptions, so declaring throws NoSuchElementException is misleading. If the base AndroidAction#execute allows, drop the throws clause.

-  public com.testsigma.sdk.Result execute() throws NoSuchElementException {
+  public com.testsigma.sdk.Result execute() {

If you remove it, also remove the unused NoSuchElementException import (Line 11).


41-44: Log failures at error level and attach the exception object.

This is an action failure; prefer error level and structured logging with the throwable.

-            logger.warn("Exception while executing action" + ExceptionUtils.getStackTrace(e));
+            logger.error("Exception while executing action", e);

Confirm the logger supports the (String, Throwable) signature; otherwise keep WARN with stack trace.


14-16: Polish action text (grammar, clarity).

Minor copyedits; confirm these strings don’t feed any parser logic.

-@Action(actionText = "Copy data from the clipboard and store into a runtime variable testdata",
-        description = "Copying the data from the clipboard and store into a runtime variable",
+@Action(actionText = "Copy clipboard text into runtime variable testdata",
+        description = "Copies clipboard text into a runtime variable",
         applicationType = ApplicationType.ANDROID)

17-17: Class naming: use CamelCase (CopyClipboard).

For Java conventions and easier cross-platform parity, consider CopyClipboard. Rename file/class consistently if you adopt this.

-public class Copyclipboard extends AndroidAction {
+public class CopyClipboard extends AndroidAction {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 99e1de1 and 77e7ba3.

📒 Files selected for processing (6)
  • copy_clipboard_data/pom.xml (1 hunks)
  • copy_clipboard_data/src/main/java/com/testsigma/addons/android/Copyclipboard.java (1 hunks)
  • copy_clipboard_data/src/main/java/com/testsigma/addons/ios/Copyclipboard.java (1 hunks)
  • copy_clipboard_data/src/main/java/com/testsigma/addons/mobileweb/Copyclipboard.java (1 hunks)
  • copy_clipboard_data/src/main/java/com/testsigma/addons/web/Copyclipboard.java (1 hunks)
  • copy_clipboard_data/src/main/resources/testsigma-sdk.properties (1 hunks)

Comment on lines +42 to +46
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Scope TestNG as test-only to avoid shading it into the runtime jar.

         <dependency>
             <groupId>org.testng</groupId>
             <artifactId>testng</artifactId>
             <version>6.14.3</version>
+            <scope>test</scope>
         </dependency>
🤖 Prompt for AI Agents
In copy_clipboard_data/pom.xml around lines 42 to 46, the TestNG dependency is
currently declared without scope which can cause it to be included in the
runtime/shaded jar; change the dependency block to add a test scope by adding a
<scope>test</scope> element so TestNG is only used for tests and not bundled
into the runtime artifact.

Comment on lines +30 to +40
try {
AndroidDriver androidDriver = (AndroidDriver)this.driver;

String clipboarddata = androidDriver.getClipboardText();
logger.info("clipboardData: " + clipboarddata);

runTimeData = new com.testsigma.sdk.RunTimeData();
runTimeData.setValue(clipboarddata);
runTimeData.setKey(testData1.getValue().toString());
setSuccessMessage("Successfully stored "+clipboarddata+" into ::"+testData1.getValue().toString());
} catch (Exception e) {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Do not log clipboard contents; add null/empty checks to avoid NPEs; keep runtime data safe.

Logging raw clipboard text (Line 34) and echoing it in the success message (Line 39) can leak sensitive data. Also, testData1.getValue() may be null, leading to an NPE (Line 38). Tighten validation, avoid logging PII, and make the driver cast generic-safe.

Apply:

-        try {
-            AndroidDriver androidDriver = (AndroidDriver)this.driver;
-
-            String clipboarddata = androidDriver.getClipboardText();
-            logger.info("clipboardData: " + clipboarddata);
-
-            runTimeData = new com.testsigma.sdk.RunTimeData();
-            runTimeData.setValue(clipboarddata);
-            runTimeData.setKey(testData1.getValue().toString());
-            setSuccessMessage("Successfully stored "+clipboarddata+" into ::"+testData1.getValue().toString());
+        try {
+            AndroidDriver<?> androidDriver = (AndroidDriver<?>) this.driver;
+            // Validate runtime variable key to avoid NPEs
+            String key = (testData1 != null && testData1.getValue() != null)
+                    ? testData1.getValue().toString().trim()
+                    : null;
+            if (key == null || key.isEmpty()) {
+                setErrorMessage("Missing/empty runtime variable name in 'testdata'.");
+                return com.testsigma.sdk.Result.FAILED;
+            }
+            // Read clipboard safely and avoid logging sensitive content
+            String clipboarddata = androidDriver.getClipboardText();
+            if (clipboarddata == null) clipboarddata = "";
+            logger.info("Clipboard text length: " + clipboarddata.length());
+
+            if (runTimeData == null) {
+                runTimeData = new com.testsigma.sdk.RunTimeData();
+            }
+            runTimeData.setKey(key);
+            runTimeData.setValue(clipboarddata);
+            setSuccessMessage("Successfully stored clipboard text into ::" + key
+                    + " (length: " + clipboarddata.length() + ")");
🤖 Prompt for AI Agents
In
copy_clipboard_data/src/main/java/com/testsigma/addons/android/Copyclipboard.java
around lines 30 to 40, remove the direct logging and echoing of clipboard text
and make the driver cast safe; check for null/empty values before using them and
avoid including raw clipboard contents in messages or logs. Concretely: verify
driver is an AndroidDriver with an instanceof check before casting, call
getClipboardText() and null-check/trim the result (treat null as empty or fail
gracefully), ensure testData1 and testData1.getValue() are non-null before using
them as the runtime key (use a safe default or throw a clear error), set
runTimeData value only after validation, and change success/failure messages to
not contain the clipboard contents (use a generic message referencing the key
only).

Comment on lines +33 to +41
String clipboarddata = iosDriver.getClipboardText();
logger.info("clipboardData: " + clipboarddata);

runTimeData = new com.testsigma.sdk.RunTimeData();
runTimeData.setValue(clipboarddata);
runTimeData.setKey(testData1.getValue().toString());
setSuccessMessage("Successfully stored "+clipboarddata+" into ::"+testData1.getValue().toString());
} catch (Exception e) {
logger.warn("Exception while executing action" + ExceptionUtils.getStackTrace(e));
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid logging clipboard contents; add null/empty guards and avoid leaking in messages.

-            String clipboarddata = iosDriver.getClipboardText();
-            logger.info("clipboardData: " + clipboarddata);
-
-            runTimeData = new com.testsigma.sdk.RunTimeData();
-            runTimeData.setValue(clipboarddata);
-            runTimeData.setKey(testData1.getValue().toString());
-            setSuccessMessage("Successfully stored "+clipboarddata+" into ::"+testData1.getValue().toString());
+            String clipboardData = iosDriver.getClipboardText();
+            if (clipboardData == null || clipboardData.isEmpty()) {
+              setErrorMessage("Clipboard on iOS device is empty/unavailable.");
+              return com.testsigma.sdk.Result.FAILED;
+            }
+            if (testData1 == null || testData1.getValue() == null) {
+              setErrorMessage("Runtime variable name (testdata) is required.");
+              return com.testsigma.sdk.Result.FAILED;
+            }
+            if (runTimeData == null) {
+              runTimeData = new com.testsigma.sdk.RunTimeData();
+            }
+            runTimeData.setKey(testData1.getValue().toString());
+            runTimeData.setValue(clipboardData);
+            setSuccessMessage("Successfully stored clipboard text into ::"+testData1.getValue().toString());
📝 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
String clipboarddata = iosDriver.getClipboardText();
logger.info("clipboardData: " + clipboarddata);
runTimeData = new com.testsigma.sdk.RunTimeData();
runTimeData.setValue(clipboarddata);
runTimeData.setKey(testData1.getValue().toString());
setSuccessMessage("Successfully stored "+clipboarddata+" into ::"+testData1.getValue().toString());
} catch (Exception e) {
logger.warn("Exception while executing action" + ExceptionUtils.getStackTrace(e));
String clipboardData = iosDriver.getClipboardText();
if (clipboardData == null || clipboardData.isEmpty()) {
setErrorMessage("Clipboard on iOS device is empty/unavailable.");
return com.testsigma.sdk.Result.FAILED;
}
if (testData1 == null || testData1.getValue() == null) {
setErrorMessage("Runtime variable name (testdata) is required.");
return com.testsigma.sdk.Result.FAILED;
}
if (runTimeData == null) {
runTimeData = new com.testsigma.sdk.RunTimeData();
}
runTimeData.setKey(testData1.getValue().toString());
runTimeData.setValue(clipboardData);
setSuccessMessage("Successfully stored clipboard text into ::" + testData1.getValue().toString());
🤖 Prompt for AI Agents
In copy_clipboard_data/src/main/java/com/testsigma/addons/ios/Copyclipboard.java
around lines 33 to 41, remove the logger.info that prints the raw clipboard
contents, add a null/empty check before using clipboarddata (if null or empty,
set a failure or no-op with an appropriate message and do not call setValue),
and update the success message to avoid including the clipboard contents (e.g.,
reference the target key only). Ensure you still set the runTimeData key and
only set runTimeData.value when clipboarddata is non-empty; do not log or
include clipboarddata in any logs or messages.

Comment on lines +34 to +41
try {
String clipboardData = getClipboardData();
logger.info("clipboardData: " + clipboardData);

runTimeData = new com.testsigma.sdk.RunTimeData();
runTimeData.setValue(clipboardData);
runTimeData.setKey(testdata.getValue().toString());
setSuccessMessage("Successfully stored "+clipboardData+" into ::"+testdata.getValue().toString());
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Do not log clipboard contents; validate inputs; avoid leaking in messages.

-          String clipboardData = getClipboardData();
-          logger.info("clipboardData: " + clipboardData);
-
-          runTimeData = new com.testsigma.sdk.RunTimeData();
-          runTimeData.setValue(clipboardData);
-          runTimeData.setKey(testdata.getValue().toString());
-          setSuccessMessage("Successfully stored "+clipboardData+" into ::"+testdata.getValue().toString());
+          String clipboardData = getClipboardData();
+          if (clipboardData == null || clipboardData.isEmpty()) {
+            setErrorMessage("Clipboard is empty or unavailable (possibly headless environment).");
+            return com.testsigma.sdk.Result.FAILED;
+          }
+          if (testdata == null || testdata.getValue() == null) {
+            setErrorMessage("Runtime variable name (testdata) is required.");
+            return com.testsigma.sdk.Result.FAILED;
+          }
+          if (runTimeData == null) {
+            runTimeData = new com.testsigma.sdk.RunTimeData();
+          }
+          runTimeData.setKey(testdata.getValue().toString());
+          runTimeData.setValue(clipboardData);
+          setSuccessMessage("Successfully stored clipboard text into ::"+testdata.getValue().toString());
📝 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
try {
String clipboardData = getClipboardData();
logger.info("clipboardData: " + clipboardData);
runTimeData = new com.testsigma.sdk.RunTimeData();
runTimeData.setValue(clipboardData);
runTimeData.setKey(testdata.getValue().toString());
setSuccessMessage("Successfully stored "+clipboardData+" into ::"+testdata.getValue().toString());
try {
String clipboardData = getClipboardData();
if (clipboardData == null || clipboardData.isEmpty()) {
setErrorMessage("Clipboard is empty or unavailable (possibly headless environment).");
return com.testsigma.sdk.Result.FAILED;
}
if (testdata == null || testdata.getValue() == null) {
setErrorMessage("Runtime variable name (testdata) is required.");
return com.testsigma.sdk.Result.FAILED;
}
if (runTimeData == null) {
runTimeData = new com.testsigma.sdk.RunTimeData();
}
runTimeData.setKey(testdata.getValue().toString());
runTimeData.setValue(clipboardData);
setSuccessMessage("Successfully stored clipboard text into ::"+testdata.getValue().toString());
🤖 Prompt for AI Agents
In
copy_clipboard_data/src/main/java/com/testsigma/addons/mobileweb/Copyclipboard.java
around lines 34 to 41, the code currently logs the raw clipboard content and
embeds it in the success message which leaks sensitive data; remove
logger.info("clipboardData: " + clipboardData) and stop concatenating the
clipboard value into user-facing or log messages; instead validate inputs before
use (ensure clipboardData and testdata.getValue() are non-null and non-empty,
trim values, and throw or set failure when invalid), store the clipboard value
in runTimeData as before but keep any messages generic (e.g., "Successfully
stored clipboard data into ::<key>" without the actual clipboard content) and
ensure no other debug or error logs print the clipboard contents.

Comment on lines +50 to +60
private static String getClipboardData() {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Headless-safe clipboard access and structured logging.

-  private static String getClipboardData() {
+  private String getClipboardData() {
       try {
           Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
           Transferable contents = clipboard.getContents(null);
           if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
               return (String) contents.getTransferData(DataFlavor.stringFlavor);
           }
-      } catch (Exception ex) {
-          ex.printStackTrace();
+      } catch (java.awt.HeadlessException ex) {
+          logger.warn("Clipboard access is not available in headless environments.");
+      } catch (Exception ex) {
+          logger.warn("Failed to access clipboard: " + ExceptionUtils.getMessage(ex));
       }
       return null;
   }
📝 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
private static String getClipboardData() {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
private String getClipboardData() {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
}
} catch (java.awt.HeadlessException ex) {
logger.warn("Clipboard access is not available in headless environments.");
} catch (Exception ex) {
logger.warn("Failed to access clipboard: " + ExceptionUtils.getMessage(ex));
}
return null;
}
🤖 Prompt for AI Agents
In
copy_clipboard_data/src/main/java/com/testsigma/addons/mobileweb/Copyclipboard.java
around lines 50 to 60, make clipboard access headless-safe and replace
ex.printStackTrace() with structured logging: first guard with
GraphicsEnvironment.isHeadless() and return null immediately if headless; then
obtain the system clipboard inside the try, and on any exception log a
structured error (e.g., LOGGER.error("Failed to read system clipboard", ex))
using the class logger instead of printing the stack trace; ensure the method
still returns null on failure and add/ reuse a private static logger field if
one does not exist.

Comment on lines +34 to +41
try {
String clipboardData = getClipboardData();
logger.info("clipboardData: " + clipboardData);

runTimeData = new com.testsigma.sdk.RunTimeData();
runTimeData.setValue(clipboardData);
runTimeData.setKey(testdata.getValue().toString());
setSuccessMessage("Successfully stored "+clipboardData+" into ::"+testdata.getValue().toString());
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Do not log clipboard contents or echo them in success messages. This leaks sensitive data.

Redact value from logs/messages and fail fast on null/empty.

-          String clipboardData = getClipboardData();
-          logger.info("clipboardData: " + clipboardData);
-
-          runTimeData = new com.testsigma.sdk.RunTimeData();
-          runTimeData.setValue(clipboardData);
-          runTimeData.setKey(testdata.getValue().toString());
-          setSuccessMessage("Successfully stored "+clipboardData+" into ::"+testdata.getValue().toString());
+          String clipboardData = getClipboardData();
+          if (clipboardData == null || clipboardData.isEmpty()) {
+            setErrorMessage("Clipboard is empty or unavailable (possibly headless environment).");
+            return com.testsigma.sdk.Result.FAILED;
+          }
+          if (testdata == null || testdata.getValue() == null) {
+            setErrorMessage("Runtime variable name (testdata) is required.");
+            return com.testsigma.sdk.Result.FAILED;
+          }
+          if (runTimeData == null) {
+            runTimeData = new com.testsigma.sdk.RunTimeData();
+          }
+          runTimeData.setKey(testdata.getValue().toString());
+          runTimeData.setValue(clipboardData);
+          setSuccessMessage("Successfully stored clipboard text into ::"+testdata.getValue().toString());
📝 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
try {
String clipboardData = getClipboardData();
logger.info("clipboardData: " + clipboardData);
runTimeData = new com.testsigma.sdk.RunTimeData();
runTimeData.setValue(clipboardData);
runTimeData.setKey(testdata.getValue().toString());
setSuccessMessage("Successfully stored "+clipboardData+" into ::"+testdata.getValue().toString());
try {
String clipboardData = getClipboardData();
if (clipboardData == null || clipboardData.isEmpty()) {
setErrorMessage("Clipboard is empty or unavailable (possibly headless environment).");
return com.testsigma.sdk.Result.FAILED;
}
if (testdata == null || testdata.getValue() == null) {
setErrorMessage("Runtime variable name (testdata) is required.");
return com.testsigma.sdk.Result.FAILED;
}
if (runTimeData == null) {
runTimeData = new com.testsigma.sdk.RunTimeData();
}
runTimeData.setKey(testdata.getValue().toString());
runTimeData.setValue(clipboardData);
setSuccessMessage("Successfully stored clipboard text into ::"+testdata.getValue().toString());
🤖 Prompt for AI Agents
In copy_clipboard_data/src/main/java/com/testsigma/addons/web/Copyclipboard.java
around lines 34 to 41, do not log or include the raw clipboard value in logs or
success messages and fail fast if the clipboard value is null/empty: remove or
replace logger.info("clipboardData: ...") with a non-sensitive message (e.g.,
"clipboardData retrieved" or include a redacted placeholder like "<REDACTED>"),
check if clipboardData is null or empty and immediately set failure (or throw)
with a generic message if so, and update the success message to avoid echoing
the clipboard contents (e.g., "Successfully stored clipboard data into
::<key>"). Ensure runTimeData still stores the actual value internally but never
expose it in logs or user-facing messages.

Comment on lines +50 to +60
private static String getClipboardData() {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle headless environments and stop using printStackTrace.

Toolkit clipboard often fails on CI servers without a display; log cleanly instead.

-  private static String getClipboardData() {
+  private String getClipboardData() {
       try {
           Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
           Transferable contents = clipboard.getContents(null);
           if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
               return (String) contents.getTransferData(DataFlavor.stringFlavor);
           }
-      } catch (Exception ex) {
-          ex.printStackTrace();
+      } catch (java.awt.HeadlessException ex) {
+          logger.warn("Clipboard access is not available in headless environments.");
+      } catch (Exception ex) {
+          logger.warn("Failed to access clipboard: " + ExceptionUtils.getMessage(ex));
       }
       return null;
   }
📝 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
private static String getClipboardData() {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
private String getClipboardData() {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
}
} catch (java.awt.HeadlessException ex) {
logger.warn("Clipboard access is not available in headless environments.");
} catch (Exception ex) {
logger.warn("Failed to access clipboard: " + ExceptionUtils.getMessage(ex));
}
return null;
}
🤖 Prompt for AI Agents
In copy_clipboard_data/src/main/java/com/testsigma/addons/web/Copyclipboard.java
around lines 50 to 60, the current getClipboardData() calls
Toolkit.getDefaultToolkit() and uses ex.printStackTrace(), which fails on
headless CI machines and produces noisy output; modify the method to first check
GraphicsEnvironment.isHeadless() and immediately return null (or an empty
string) when headless, avoid calling Toolkit in that case, replace
printStackTrace() with a proper logger call (or System.err.println with a clear
message) and catch HeadlessException and general Exception separately so you log
a helpful message and return null without throwing; ensure no toolkit operations
run when headless.

@@ -0,0 +1 @@
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzMmYwYTg1MC02NjMyLWIyN2ItOTBhYS1jZDkwMDcwNzRlMWUiLCJ1bmlxdWVJZCI6IjMwIiwiaWRlbnRpdHlBY2NvdW50VVVJZCI6ImZlMmEzOGNiLThiODktNzdhNC04OTRiLTgwZjNiOWEzNzEzZSJ9.HMwJ4RklWBmwJzCXamXduAjXDjAMDd4uK3QN_zpWdkqmBuQfTuHhFTAQX0gvor2zYKdvfxjkkOy96rWWgcTYNA No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Hardcoded API key checked into VCS — rotate immediately and remove from repo.

This is a live-looking JWT-like secret committed to the repo and will also be embedded in the shaded jar. Immediate rotation and history purge are required. Replace with env/CI-injected config and commit only a template.

Apply this diff to stop committing secrets and switch to env-based config:

-testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzMmYwYTg1MC02NjMyLWIyN2ItOTBhYS1jZDkwMDcwNzRlMWUiLCJ1bmlxdWVJZCI6IjMwIiwiaWRlbnRpdHlBY2NvdW50VVVJZCI6ImZlMmEzOGNiLThiODktNzdhNC04OTRiLTgwZjNiOWEzNzEzZSJ9.HMwJ4RklWBmwJzCXamXduAjXDjAMDd4uK3QN_zpWdkqmBuQfTuHhFTAQX0gvor2zYKdvfxjkkOy96rWWgcTYNA
+# DO NOT COMMIT REAL KEYS. Inject via env/CI secrets.
+testsigma-sdk.api.key=${env.TESTSIGMA_SDK_API_KEY}

Additionally add to .gitignore (outside this diff):

copy_clipboard_data/src/main/resources/testsigma-sdk.properties

Verification (scan for other occurrences):

#!/bin/bash
rg -n --hidden -S "testsigma-sdk.api.key|eyJhbGciOiJIUzUxMiJ9" -C2
🤖 Prompt for AI Agents
In copy_clipboard_data/src/main/resources/testsigma-sdk.properties around lines
1 to 1, a live API key/JWT is hardcoded and checked into VCS; remove the secret,
replace the file content with a non-sensitive template (e.g. a placeholder key
or commented example), and update the code to read the real key from an
environment variable or CI secret (e.g. TESTSIGMA_API_KEY) instead of this file.
Rotate the compromised key immediately and purge or rewrite git history to
remove the secret from past commits; add
copy_clipboard_data/src/main/resources/testsigma-sdk.properties to .gitignore so
the file cannot be committed again; finally run the provided ripgrep scan to
verify no other occurrences remain.

@akhil-testsigma akhil-testsigma merged commit b4f9322 into dev Sep 4, 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