From 4ff3c86f4f1faf62a14f7a5b6b324ecebd934192 Mon Sep 17 00:00:00 2001 From: Akhil Appini Date: Thu, 5 Mar 2026 15:08:34 +0530 Subject: [PATCH] Added class to clear the input field using backspace --- clear_input_field_using_backspace/pom.xml | 101 ++++++++++++++++++ .../addons/mobileweb/ClearUsingBackspace.java | 61 +++++++++++ .../addons/web/ClearUsingBackspace.java | 61 +++++++++++ .../main/resources/testsigma-sdk.properties | 1 + 4 files changed, 224 insertions(+) create mode 100644 clear_input_field_using_backspace/pom.xml create mode 100644 clear_input_field_using_backspace/src/main/java/com/testsigma/addons/mobileweb/ClearUsingBackspace.java create mode 100644 clear_input_field_using_backspace/src/main/java/com/testsigma/addons/web/ClearUsingBackspace.java create mode 100644 clear_input_field_using_backspace/src/main/resources/testsigma-sdk.properties diff --git a/clear_input_field_using_backspace/pom.xml b/clear_input_field_using_backspace/pom.xml new file mode 100644 index 00000000..ec9bb21d --- /dev/null +++ b/clear_input_field_using_backspace/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + com.testsigma.addons + clear_input_field_using_backspace + 1.0.0 + jar + + + UTF-8 + 11 + 11 + 1.2.24_cloud + 5.8.0-M1 + 1.0.0 + 3.2.1 + 1.18.30 + + + + + + com.testsigma + testsigma-java-sdk + ${testsigma.sdk.version} + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + org.testng + testng + 6.14.3 + + + + org.seleniumhq.selenium + selenium-java + 4.33.0 + + + + io.appium + java-client + 9.4.0 + + + com.fasterxml.jackson.core + jackson-annotations + 2.13.0 + + + org.apache.commons + commons-lang3 + 3.17.0 + + + + clear_input_field_using_backspace + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven.source.plugin.version} + + + attach-sources + + jar + + + + + + + diff --git a/clear_input_field_using_backspace/src/main/java/com/testsigma/addons/mobileweb/ClearUsingBackspace.java b/clear_input_field_using_backspace/src/main/java/com/testsigma/addons/mobileweb/ClearUsingBackspace.java new file mode 100644 index 00000000..8b0f97da --- /dev/null +++ b/clear_input_field_using_backspace/src/main/java/com/testsigma/addons/mobileweb/ClearUsingBackspace.java @@ -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; + } +} \ No newline at end of file diff --git a/clear_input_field_using_backspace/src/main/java/com/testsigma/addons/web/ClearUsingBackspace.java b/clear_input_field_using_backspace/src/main/java/com/testsigma/addons/web/ClearUsingBackspace.java new file mode 100644 index 00000000..f7f0b089 --- /dev/null +++ b/clear_input_field_using_backspace/src/main/java/com/testsigma/addons/web/ClearUsingBackspace.java @@ -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)); + result = com.testsigma.sdk.Result.FAILED; + + } + + return result; + } +} \ No newline at end of file diff --git a/clear_input_field_using_backspace/src/main/resources/testsigma-sdk.properties b/clear_input_field_using_backspace/src/main/resources/testsigma-sdk.properties new file mode 100644 index 00000000..2ec2fe51 --- /dev/null +++ b/clear_input_field_using_backspace/src/main/resources/testsigma-sdk.properties @@ -0,0 +1 @@ +testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjYwMjgiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiNDMifQ.rIHf0f0LSHgKeSgRC-HgRl8tvQHXiBPQbzj1-7XyFb1nvhen_SxrZBwFak4E3Kf1OX4kcavut0mnULWHk-5pBw \ No newline at end of file