Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions clear_input_field_using_backspace/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testsigma.addons</groupId>
<artifactId>clear_input_field_using_backspace</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<testsigma.sdk.version>1.2.24_cloud</testsigma.sdk.version>
<junit.jupiter.version>5.8.0-M1</junit.jupiter.version>
<testsigma.addon.maven.plugin>1.0.0</testsigma.addon.maven.plugin>
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
<lombok.version>1.18.30</lombok.version>

</properties>

<dependencies>
<dependency>
<groupId>com.testsigma</groupId>
<artifactId>testsigma-java-sdk</artifactId>
<version>${testsigma.sdk.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<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>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.33.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>
</dependencies>
<build>
<finalName>clear_input_field_using_backspace</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.testsigma.addons.mobileweb;

import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.WebAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.Element;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;

@Data
@Action(actionText = "Clear the text from element-locator using backspace",
description = "Clears the text from an input field using backspaces",
applicationType = ApplicationType.MOBILE_WEB,
useCustomScreenshot = false)
public class ClearUsingBackspace extends WebAction {

@Element(reference = "element-locator")
private com.testsigma.sdk.Element element;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {

com.testsigma.sdk.Result result;

try {

logger.info("Initiating execution");
logger.info("element locator with : " + this.element.getValue() + " by:" + this.element.getBy());

WebElement webElement = element.getElement();

webElement.click();
webElement.sendKeys(Keys.END);

String text = webElement.getAttribute("value");

logger.info("text : " + text);

if (text != null) {
for (int i = 0; i < text.length(); i++) {
webElement.sendKeys(Keys.BACK_SPACE);
}
}

logger.info("Successfully cleared the input field using backspace");
setSuccessMessage("Successfully cleared the input field using backspace");
result = com.testsigma.sdk.Result.SUCCESS;

} catch (Exception e) {
logger.warn("Failed to clear the input field: " + ExceptionUtils.getStackTrace(e));
setErrorMessage("Failed to clear the input field due to: " + ExceptionUtils.getMessage(e));
result = com.testsigma.sdk.Result.FAILED;

}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.testsigma.addons.web;

import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.WebAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.Element;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;

@Data
@Action(actionText = "Clear the text from element-locator using backspace",
description = "Clears the text from an input field using backspaces",
applicationType = ApplicationType.WEB,
useCustomScreenshot = false)
public class ClearUsingBackspace extends WebAction {

@Element(reference = "element-locator")
private com.testsigma.sdk.Element element;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {

com.testsigma.sdk.Result result;

try {

logger.info("Initiating execution");
logger.info("element locator with : " + this.element.getValue() + " by:" + this.element.getBy());

WebElement webElement = element.getElement();

webElement.click();
webElement.sendKeys(Keys.END);

String text = webElement.getAttribute("value");

logger.info("text : " + text);

if (text != null) {
for (int i = 0; i < text.length(); i++) {
webElement.sendKeys(Keys.BACK_SPACE);
}
}

logger.info("Successfully cleared the input field using backspace");
setSuccessMessage("Successfully cleared the input field using backspace");
result = com.testsigma.sdk.Result.SUCCESS;
Comment on lines +48 to +50
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 | 🟠 Major

Verify the field is actually empty before returning SUCCESS.

Line 48-Line 50 marks success without validating the clear operation outcome. If key events are ignored/intercepted, this can return a false positive.

✅ Proposed post-condition check
       if (text != null) {
         for (int i = 0; i < text.length(); i++) {
           webElement.sendKeys(Keys.BACK_SPACE);
         }
       }
+
+      String remaining = webElement.getAttribute("value");
+      if (remaining != null && !remaining.isEmpty()) {
+        setErrorMessage("Unable to clear the input field completely.");
+        return com.testsigma.sdk.Result.FAILED;
+      }
 
       logger.info("Successfully cleared the input field using backspace");
       setSuccessMessage("Successfully cleared the input field using backspace");
       result = com.testsigma.sdk.Result.SUCCESS;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@clear_input_field_using_backspace/src/main/java/com/testsigma/addons/web/ClearUsingBackspace.java`
around lines 48 - 50, The code in ClearUsingBackspace sets result to SUCCESS
(using logger, setSuccessMessage, and result) without verifying the field was
actually cleared; modify the clear routine in the ClearUsingBackspace class to
read the field value after sending backspaces (e.g., via
element.getAttribute("value") or element.getText()), perform a short retry loop
with a few small waits to allow JS to update, and only set result =
com.testsigma.sdk.Result.SUCCESS and call setSuccessMessage(...) if the
post-condition shows an empty value; otherwise set an appropriate failure
result/message.


} catch (Exception e) {
logger.warn("Failed to clear the input field: " + ExceptionUtils.getStackTrace(e));
setErrorMessage("Failed to clear the input field due to: " + ExceptionUtils.getMessage(e));
Comment on lines +53 to +54
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 | 🟠 Major

Avoid exposing internal exception details in logs/error messages.

Line 53-Line 54 logs full stack trace text and propagates raw exception details to user-visible error messaging.

🛡️ Proposed safer error handling
-      logger.warn("Failed to clear the input field: " + ExceptionUtils.getStackTrace(e));
-      setErrorMessage("Failed to clear the input field due to: " + ExceptionUtils.getMessage(e));
+      logger.warn("Failed to clear the input field", e);
+      setErrorMessage("Failed to clear the input field.");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@clear_input_field_using_backspace/src/main/java/com/testsigma/addons/web/ClearUsingBackspace.java`
around lines 53 - 54, The code in ClearUsingBackspace currently prints the full
stack trace and raw exception message; replace those with non-sensitive,
user-friendly messages: change logger.warn("Failed to clear the input field: " +
ExceptionUtils.getStackTrace(e)) to a generic warn like logger.warn("Failed to
clear the input field") and, if you need the exception for debugging, log the
stacktrace at debug level (e.g., logger.debug("clear failure", e)). Replace
setErrorMessage("Failed to clear the input field due to: " +
ExceptionUtils.getMessage(e)) with a generic user-facing message such as
setErrorMessage("Failed to clear the input field.") and optionally include a
short, non-sensitive error code or e.getClass().getSimpleName() if you need
minimal diagnostic info.

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

}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjYwMjgiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiNDMifQ.rIHf0f0LSHgKeSgRC-HgRl8tvQHXiBPQbzj1-7XyFb1nvhen_SxrZBwFak4E3Kf1OX4kcavut0mnULWHk-5pBw
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 | 🔴 Critical

Remove committed SDK API key from source control immediately.

Line 1 contains a real credential in plaintext. This is a direct secret exposure risk and should be treated as a blocker: rotate the key, remove it from git history, and load it from a secure runtime secret source.

🔐 Proposed safe replacement
-testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjYwMjgiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiNDMifQ.rIHf0f0LSHgKeSgRC-HgRl8tvQHXiBPQbzj1-7XyFb1nvhen_SxrZBwFak4E3Kf1OX4kcavut0mnULWHk-5pBw
+testsigma-sdk.api.key=${TESTSIGMA_SDK_API_KEY}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@clear_input_field_using_backspace/src/main/resources/testsigma-sdk.properties`
at line 1, The committed file contains a plaintext SDK API key under the
property testsigma-sdk.api.key; remove this secret from the repository
immediately, rotate the exposed key in the provider, purge it from git history
(e.g., git filter-repo or BFG), and replace the hardcoded entry with a secure
runtime lookup (e.g., read testsigma API key from an environment variable or
injected secret manager value and reference that variable name where
testsigma-sdk.api.key was used). Ensure any code that referenced
testsigma-sdk.api.key is updated to read from the new secure source and add the
property name (or env var) to the project's .gitignore and secrets documentation
so future commits do not reintroduce secrets.

Loading