Skip to content

Commit 0ee9997

Browse files
[CUS-10915] Verifies if element is clickable in mobile web.
1 parent c7688e5 commit 0ee9997

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.testsigma.addons.mobileweb;
2+
3+
import com.testsigma.sdk.WebAction;
4+
import com.testsigma.sdk.annotation.Action;
5+
import com.testsigma.sdk.annotation.Element;
6+
import com.testsigma.sdk.ApplicationType;
7+
import lombok.Data;
8+
import com.testsigma.sdk.Result;
9+
import org.openqa.selenium.NoSuchElementException;
10+
import org.openqa.selenium.WebElement;
11+
import org.openqa.selenium.support.ui.ExpectedConditions;
12+
import org.openqa.selenium.support.ui.WebDriverWait;
13+
14+
import java.time.Duration;
15+
16+
/**
17+
* Verifies that a UI element is tapable/clickable in the mobile web application.
18+
* Behavior is consistent with web clickable validation: checks visibility, enabled state,
19+
* and that the element is not obscured (via Selenium's elementToBeClickable).
20+
* Works across supported mobile browsers (e.g., Chrome, Safari).
21+
*/
22+
@Data
23+
@lombok.EqualsAndHashCode(callSuper = false)
24+
@Action(actionText = "Verify that the element element-locator is tapable",
25+
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.",
26+
applicationType = ApplicationType.MOBILE_WEB,
27+
useCustomScreenshot = false)
28+
public class VerifyElementIsTapable extends WebAction {
29+
30+
private static final int DEFAULT_WAIT_SECONDS = 30;
31+
32+
@Element(reference = "element-locator")
33+
private com.testsigma.sdk.Element element;
34+
35+
@Override
36+
public Result execute() throws NoSuchElementException {
37+
logger.info("Verifying element is tapable (mobile web)");
38+
logger.debug("Element locator: " + this.element.getValue() + " by: " + this.element.getBy());
39+
40+
try {
41+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(DEFAULT_WAIT_SECONDS));
42+
WebElement webElement = wait.until(ExpectedConditions.elementToBeClickable(element.getBy()));
43+
44+
if (webElement == null) {
45+
setErrorMessage("Element is not tapable: element not found or not interactable within " + DEFAULT_WAIT_SECONDS + " seconds.");
46+
logger.warn(getErrorMessage());
47+
return Result.FAILED;
48+
}
49+
50+
setSuccessMessage("Element is tapable (visible, enabled, and ready for interaction).");
51+
logger.info(getSuccessMessage());
52+
return Result.SUCCESS;
53+
54+
} catch (org.openqa.selenium.TimeoutException e) {
55+
String reason = "Element is not tapable within " + DEFAULT_WAIT_SECONDS + " seconds. It may be hidden, disabled, or covered by another element.";
56+
setErrorMessage(reason + " " + e.getMessage());
57+
logger.warn(reason + " " + e.getMessage());
58+
return Result.FAILED;
59+
} catch (NoSuchElementException e) {
60+
setErrorMessage("Element not found: " + e.getMessage());
61+
logger.warn(getErrorMessage());
62+
return Result.FAILED;
63+
} catch (Exception e) {
64+
setErrorMessage("Element could not be verified as tapable: " + e.getMessage());
65+
logger.warn(getErrorMessage());
66+
return Result.FAILED;
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)