-
Notifications
You must be signed in to change notification settings - Fork 15
feat/CUS-11086-Added class to clear the input field using backspace #353
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
||
| } 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
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.
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