Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.testsigma.addons.mobileweb;

import com.testsigma.sdk.WebAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.Element;
import com.testsigma.sdk.ApplicationType;
import lombok.Data;
import com.testsigma.sdk.Result;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

/**
* Verifies that a UI element is tapable/clickable in the mobile web application.
* Behavior is consistent with web clickable validation: checks visibility, enabled state,
* and that the element is not obscured (via Selenium's elementToBeClickable).
* Works across supported mobile browsers (e.g., Chrome, Safari).
*/
@Data
@lombok.EqualsAndHashCode(callSuper = false)
@Action(actionText = "Verify that the element element-locator is tapable",
description = "Verifies that the element is tapable (visible, enabled, and not blocked by another element) in the mobile web application. Use for consistent validation across mobile browsers.",
applicationType = ApplicationType.MOBILE_WEB,
useCustomScreenshot = false)
public class VerifyElementIsTapable extends WebAction {

private static final int DEFAULT_WAIT_SECONDS = 30;

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

@Override
public Result execute() throws NoSuchElementException {
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 | 🟡 Minor

Misleading throws NoSuchElementException declaration

NoSuchElementException is caught internally on lines 59–62 and never rethrown, so declaring it in the method signature communicates a contract that is never fulfilled. Since NoSuchElementException is also an unchecked exception (extends RuntimeException), the declaration is not compiler-enforced — it is purely misleading documentation noise. Remove it.

🐛 Proposed fix
-    public Result execute() throws NoSuchElementException {
+    public Result execute() {
📝 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
public Result execute() throws NoSuchElementException {
public Result execute() {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@element_validation_actions/src/main/java/com/testsigma/addons/mobileweb/VerifyElementIsTapable.java`
at line 36, The method declaration for VerifyElementIsTapable.execute currently
declares "throws NoSuchElementException" but that exception is caught inside the
method and is unchecked, so remove the redundant throws clause from the
execute() signature in class VerifyElementIsTapable; update the method
declaration "public Result execute()" accordingly and run a quick compile to
ensure no callers rely on the checked-exception contract.

logger.info("Verifying element is tapable (mobile web)");
logger.debug("Element locator: " + this.element.getValue() + " by: " + this.element.getBy());

try {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(DEFAULT_WAIT_SECONDS));
WebElement webElement = wait.until(ExpectedConditions.elementToBeClickable(element.getBy()));

if (webElement == null) {
setErrorMessage("Element is not tapable: element not found or not interactable within " + DEFAULT_WAIT_SECONDS + " seconds.");
logger.warn(getErrorMessage());
return Result.FAILED;
}
Comment on lines +44 to +48
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

Dead code — wait.until() never returns null for ExpectedCondition<WebElement>

until() returns the located element once the condition is met. On failure, a TimeoutException is thrown if no element is found in time. Because wait.until() either returns a non-null WebElement or throws, the webElement == null guard on line 44 can never be true, making lines 44–48 entirely unreachable dead code. The TimeoutException catch block on lines 54–58 already handles the non-clickable scenario.

🐛 Proposed fix — remove the dead null check
         WebElement webElement = wait.until(ExpectedConditions.elementToBeClickable(element.getBy()));

-        if (webElement == null) {
-            setErrorMessage("Element is not tapable: element not found or not interactable within " + DEFAULT_WAIT_SECONDS + " seconds.");
-            logger.warn(getErrorMessage());
-            return Result.FAILED;
-        }
-
         setSuccessMessage("Element is tapable (visible, enabled, and ready for interaction).");
📝 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
if (webElement == null) {
setErrorMessage("Element is not tapable: element not found or not interactable within " + DEFAULT_WAIT_SECONDS + " seconds.");
logger.warn(getErrorMessage());
return Result.FAILED;
}
WebElement webElement = wait.until(ExpectedConditions.elementToBeClickable(element.getBy()));
setSuccessMessage("Element is tapable (visible, enabled, and ready for interaction).");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@element_validation_actions/src/main/java/com/testsigma/addons/mobileweb/VerifyElementIsTapable.java`
around lines 44 - 48, Remove the unreachable null-check block that tests "if
(webElement == null)" after the wait.until(ExpectedCondition<WebElement>) call
in VerifyElementIsTapable; wait.until(...) either returns a non-null WebElement
or throws a TimeoutException, so delete the webElement==null branch (including
setErrorMessage(...), logger.warn(...), and return Result.FAILED) and rely on
the existing TimeoutException catch to handle the not-interactable/not-found
case.


setSuccessMessage("Element is tapable (visible, enabled, and ready for interaction).");
logger.info(getSuccessMessage());
return Result.SUCCESS;

} catch (org.openqa.selenium.TimeoutException e) {
String reason = "Element is not tapable within " + DEFAULT_WAIT_SECONDS + " seconds. It may be hidden, disabled, or covered by another element.";
setErrorMessage(reason + " " + e.getMessage());
logger.warn(reason + " " + e.getMessage());
return Result.FAILED;
} catch (NoSuchElementException e) {
setErrorMessage("Element not found: " + e.getMessage());
logger.warn(getErrorMessage());
return Result.FAILED;
} catch (Exception e) {
setErrorMessage("Element could not be verified as tapable: " + e.getMessage());
logger.warn(getErrorMessage());
return Result.FAILED;
}
}
}