-
Notifications
You must be signed in to change notification settings - Fork 16
feat/TE-29457-Added try-catch blocks and integrated addon to handle in-region #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/TE-29457-Added try-catch blocks and integrated addon to handle in-region #217
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 NoSuchElementExceptionis misleading. If the baseAndroidAction#executeallows, 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
NoSuchElementExceptionimport (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.
📒 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)
| <dependency> | ||
| <groupId>org.testng</groupId> | ||
| <artifactId>testng</artifactId> | ||
| <version>6.14.3</version> | ||
| </dependency> |
There was a problem hiding this comment.
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.
| 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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).
| 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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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.
| 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.
| 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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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.
| 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.
| 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; |
There was a problem hiding this comment.
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.
| 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.
| 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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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.
| 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.
| 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; |
There was a problem hiding this comment.
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.
| 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 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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
Chores