Search in sources :

Example 1 with ElementPropertiesEntity

use of com.testsigma.automator.entity.ElementPropertiesEntity in project testsigma by testsigmahq.

the class DragAndDropAction method getElement.

private WebElement getElement(String elementActionVarName, LocatorType locatorType, String locatorValue) throws Exception {
    FindByType findByType = FindByType.getType(locatorType);
    ElementPropertiesEntity elementPropertiesEntity = new ElementPropertiesEntity();
    elementPropertiesEntity.setFindByType(findByType);
    elementPropertiesEntity.setLocatorValue(locatorValue);
    elementPropertiesEntity.setElementName("ui-iden");
    elementPropertiesEntity.setDynamicLocator(true);
    Map<String, ElementPropertiesEntity> elementPropertiesMap = getElementPropertiesEntityMap();
    if (elementPropertiesMap == null) {
        elementPropertiesMap = new HashMap<>();
        setElementPropertiesEntityMap(elementPropertiesMap);
    }
    getElementPropertiesEntityMap().put(elementActionVarName, elementPropertiesEntity);
    findElement(elementActionVarName);
    return getElement();
}
Also used : FindByType(com.testsigma.automator.actions.FindByType) ElementPropertiesEntity(com.testsigma.automator.entity.ElementPropertiesEntity)

Example 2 with ElementPropertiesEntity

use of com.testsigma.automator.entity.ElementPropertiesEntity in project testsigma by testsigmahq.

the class ElementAction method setElementSearchCriteria.

protected void setElementSearchCriteria(String elementActionVariableName) throws AutomatorException {
    log.debug("Setting element search criteria");
    ElementPropertiesEntity elementPropertiesEntity = getElementPropertiesEntity(elementActionVariableName);
    if (StringUtils.isBlank(elementPropertiesEntity.getLocatorValue())) {
        throw new AutomatorException(String.format(LOCATOR_VALUE_MISSING_ERROR_MSG, elementPropertiesEntity.getFindByType()));
    }
    elementSearchCriteria = new ElementSearchCriteria(elementPropertiesEntity.getFindByType(), elementPropertiesEntity.getLocatorValue());
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) ElementPropertiesEntity(com.testsigma.automator.entity.ElementPropertiesEntity)

Example 3 with ElementPropertiesEntity

use of com.testsigma.automator.entity.ElementPropertiesEntity in project testsigma by testsigmahq.

the class ListFrameAction method getElements.

private List<WebElement> getElements(String elementActionVarName, LocatorType locatorType, String locatorValue) throws Exception {
    FindByType findByType = FindByType.getType(locatorType);
    ElementPropertiesEntity elementPropertiesEntity = new ElementPropertiesEntity();
    elementPropertiesEntity.setFindByType(findByType);
    elementPropertiesEntity.setLocatorValue(locatorValue);
    elementPropertiesEntity.setElementName("ui-iden");
    elementPropertiesEntity.setDynamicLocator(true);
    Map<String, ElementPropertiesEntity> elementPropertiesMap = getElementPropertiesEntityMap();
    if (elementPropertiesMap == null) {
        elementPropertiesMap = new HashMap<>();
        setElementPropertiesEntityMap(elementPropertiesMap);
    }
    getElementPropertiesEntityMap().put(elementActionVarName, elementPropertiesEntity);
    findElement(elementActionVarName);
    return getElements();
}
Also used : FindByType(com.testsigma.automator.actions.FindByType) ElementPropertiesEntity(com.testsigma.automator.entity.ElementPropertiesEntity)

Example 4 with ElementPropertiesEntity

use of com.testsigma.automator.entity.ElementPropertiesEntity 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 ElementPropertiesEntity

use of com.testsigma.automator.entity.ElementPropertiesEntity in project testsigma by testsigmahq.

the class DriverSessionCommand method createElementPropertiesMap.

private Map<String, ElementPropertiesEntity> createElementPropertiesMap(FindByType findByType, String locatorValue) {
    ElementPropertiesEntity elementPropertiesEntity = new ElementPropertiesEntity();
    Map<String, ElementPropertiesEntity> elementPropertiesEntityMap = new HashMap<>();
    elementPropertiesEntity.setFindByType(findByType);
    elementPropertiesEntity.setLocatorValue(locatorValue);
    elementPropertiesEntityMap.put(NaturalTextActionConstants.TESTS_TEP_DATA_MAP_KEY_ELEMENT, elementPropertiesEntity);
    return elementPropertiesEntityMap;
}
Also used : HashMap(java.util.HashMap) ElementPropertiesEntity(com.testsigma.automator.entity.ElementPropertiesEntity)

Aggregations

ElementPropertiesEntity (com.testsigma.automator.entity.ElementPropertiesEntity)8 FindByType (com.testsigma.automator.actions.FindByType)3 ElementSearchCriteria (com.testsigma.automator.actions.ElementSearchCriteria)2 HashMap (java.util.HashMap)2 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)2 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)1 JSONObject (org.json.JSONObject)1 NoAlertPresentException (org.openqa.selenium.NoAlertPresentException)1 WebElement (org.openqa.selenium.WebElement)1