Search in sources :

Example 1 with ElementSearchCriteria

use of com.testsigma.automator.actions.ElementSearchCriteria in project testsigma by testsigmahq.

the class DriverSessionActionsController method searchByIndexAndSendKeys.

@PostMapping(value = "/search_and_send_keys")
@ResponseStatus(HttpStatus.ACCEPTED)
public void searchByIndexAndSendKeys(@PathVariable("session_id") String sessionId, @RequestParam("platform") Platform platform, @RequestParam("locatorType") LocatorType locatorType, @RequestParam("byValue") String byValue, @RequestParam("index") Integer index, @RequestParam("keys") String keys, @Nullable @RequestParam(value = "webViewName", required = false) String webViewName) throws Exception {
    FindByType findByType = FindByType.getType(locatorType);
    ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(findByType, byValue);
    log.info("Request for searching the Element By Index and Tapping on it, in session - " + sessionId + ",for locatorType - " + locatorType + ", byValue - " + byValue + ", index - " + index + ", keys -" + keys);
    driverSessionCommand.findElementByIndexAndSendKey(sessionId, platform, elementSearchCriteria, index, keys, webViewName);
}
Also used : FindByType(com.testsigma.automator.actions.FindByType) ElementSearchCriteria(com.testsigma.automator.actions.ElementSearchCriteria)

Example 2 with ElementSearchCriteria

use of com.testsigma.automator.actions.ElementSearchCriteria in project testsigma by testsigmahq.

the class DriverSessionActionsController method searchByIndexAndTapElement.

@PostMapping(value = "/search_and_tap")
@ResponseStatus(HttpStatus.ACCEPTED)
public void searchByIndexAndTapElement(@PathVariable("session_id") String sessionId, @RequestParam("platform") Platform platform, @RequestParam("locatorType") LocatorType locatorType, @RequestParam("byValue") String byValue, @RequestParam("index") Integer index, @Nullable @RequestParam(value = "webViewName", required = false) String webViewName) throws Exception {
    FindByType findByType = FindByType.getType(locatorType);
    ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(findByType, byValue);
    log.info("Request for searching the Element By Index and Tapping on it, in session - " + sessionId + ",for locatorType - " + locatorType + ", byValue - " + byValue + ", index - " + index);
    driverSessionCommand.findElementByIndexAndTap(sessionId, platform, elementSearchCriteria, index, webViewName);
}
Also used : FindByType(com.testsigma.automator.actions.FindByType) ElementSearchCriteria(com.testsigma.automator.actions.ElementSearchCriteria)

Example 3 with ElementSearchCriteria

use of com.testsigma.automator.actions.ElementSearchCriteria in project testsigma by testsigmahq.

the class GetUniqueXpathAction method execute.

@Override
protected void execute() throws Exception {
    AppiumDriver driver = getDriver();
    List<RemoteWebElement> webElements = new ArrayList<>();
    ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(FindByType.XPATH, webElement.getXpath());
    if (webElement.getWebViewName() != null) {
        driver.context(webElement.getWebViewName());
        webElements = driver.findElements(elementSearchCriteria.getBy());
        driver.context("NATIVE_APP");
    } else {
        webElements = driver.findElements(elementSearchCriteria.getBy());
    }
    if (webElements.size() > 1) {
        String absoluteXpath = this.optimizeXpathUsingAttributes(webElement);
        elementSearchCriteria.setByValue(absoluteXpath);
        if (driver.findElements(elementSearchCriteria.getBy()).size() != 1) {
            String relativeXpath = this.optimizeXpathRelatively(webElement);
            elementSearchCriteria.setByValue(relativeXpath);
            if (driver.findElements(elementSearchCriteria.getBy()).size() != 1) {
                setActualValue(null);
            } else
                setActualValue(relativeXpath);
        } else {
            setActualValue(absoluteXpath);
        }
    } else {
        setActualValue(null);
    }
}
Also used : AppiumDriver(io.appium.java_client.AppiumDriver) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) ArrayList(java.util.ArrayList) ElementSearchCriteria(com.testsigma.automator.actions.ElementSearchCriteria)

Example 4 with ElementSearchCriteria

use of com.testsigma.automator.actions.ElementSearchCriteria in project testsigma by testsigmahq.

the class CheckElementIsInDifferentFrame method execute.

@Override
protected void execute() throws Exception {
    ElementPropertiesEntity elementPropertiesEntity = getElementPropertiesEntity(NaturalTextActionConstants.TESTS_TEP_DATA_MAP_KEY_ELEMENT);
    if (StringUtils.isBlank(elementPropertiesEntity.getLocatorValue())) {
        throw new Exception();
    }
    ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(elementPropertiesEntity.getFindByType(), elementPropertiesEntity.getLocatorValue());
    WebElement elementInIframe = null;
    JavascriptExecutor jsExecutor = driver;
    String defaultPathName = (String) jsExecutor.executeScript("return window.location.pathname");
    List<WebElement> iframes = getDriver().findElements(By.xpath("//iframe|//frame"));
    Integer i = 1;
    for (WebElement iframe : iframes) {
        try {
            getDriver().switchTo().defaultContent();
            getDriver().switchTo().frame(iframe);
            elementInIframe = getDriver().findElement(elementSearchCriteria.getBy());
            Map<String, String> suggestions = new HashMap<String, String>();
            // iframe.getAttribute("name")
            suggestions.put("Frame Name", "");
            suggestions.put("Frame Index", new Integer(i).toString());
            engineResult.getMetaData().setSuggestions(new JSONObject().put("list", suggestions));
            this.suggestionActionResult = SuggestionActionResult.Success;
            break;
        } catch (Exception e) {
            continue;
        }
    }
    if (defaultPathName != jsExecutor.executeScript("return window.location.pathname")) {
        getDriver().switchTo().defaultContent();
        List<WebElement> elements = getDriver().findElementsByXPath("//iframe[@src=\"" + defaultPathName + "\"]");
        if (elements.size() > 0) {
            getDriver().switchTo().frame(elements.get(0));
        }
    }
    if (elementInIframe == null)
        throw exception;
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) WebElement(org.openqa.selenium.WebElement) ElementPropertiesEntity(com.testsigma.automator.entity.ElementPropertiesEntity) ElementSearchCriteria(com.testsigma.automator.actions.ElementSearchCriteria)

Example 5 with ElementSearchCriteria

use of com.testsigma.automator.actions.ElementSearchCriteria in project testsigma by testsigmahq.

the class DriverSessionActionsController method searchByIndexAndClearElement.

@PostMapping(value = "/search_and_clear")
@ResponseStatus(HttpStatus.ACCEPTED)
public void searchByIndexAndClearElement(@PathVariable("session_id") String sessionId, @RequestParam("platform") Platform platform, @RequestParam("locatorType") LocatorType locatorType, @RequestParam("byValue") String byValue, @RequestParam("index") Integer index, @Nullable @RequestParam(value = "webViewName", required = false) String webViewName) throws Exception {
    FindByType findByType = FindByType.getType(locatorType);
    ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(findByType, byValue);
    log.info("Request for searching the Element By Index and Clearing it, in session - " + sessionId + ",for locatorType - " + locatorType + ", byValue - " + byValue + ", index - " + index);
    driverSessionCommand.findElementByIndexAndClear(sessionId, platform, elementSearchCriteria, index, webViewName);
}
Also used : FindByType(com.testsigma.automator.actions.FindByType) ElementSearchCriteria(com.testsigma.automator.actions.ElementSearchCriteria)

Aggregations

ElementSearchCriteria (com.testsigma.automator.actions.ElementSearchCriteria)7 FindByType (com.testsigma.automator.actions.FindByType)4 ElementPropertiesEntity (com.testsigma.automator.entity.ElementPropertiesEntity)2 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)2 MobileElement (com.testsigma.automator.actions.mobile.MobileElement)1 AppiumDriver (io.appium.java_client.AppiumDriver)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1 NoAlertPresentException (org.openqa.selenium.NoAlertPresentException)1 WebElement (org.openqa.selenium.WebElement)1 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)1