Search in sources :

Example 6 with ElementPropertiesEntity

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

the class ElementAction method constructElementWithDynamicXpath.

protected void constructElementWithDynamicXpath(String parameterizedXpath, String elementActionVarName, String testDataActionVarName, String attributeActionVariableName, boolean isAttributeToBeReplacedWith) throws AutomatorException {
    ElementPropertiesEntity elementPropertiesEntity = new ElementPropertiesEntity();
    String xpath = parameterizedXpath;
    if (isAttributeToBeReplacedWith && attributeActionVariableName != null) {
        log.info("Constructing XPATH with Pre-defined syntax: " + parameterizedXpath + " and attribute:" + getAttribute(attributeActionVariableName));
        xpath = parameterizedXpath.replace(PARAMETERIZED_XPATH_PLACE_HOLDER, getAttribute(attributeActionVariableName));
    } else if (testDataActionVarName != null) {
        log.info("Constructing XPATH with Pre-defined syntax: " + parameterizedXpath + " and testdata:" + getTestData(testDataActionVarName));
        xpath = parameterizedXpath.replace(PARAMETERIZED_XPATH_PLACE_HOLDER, getTestData(testDataActionVarName));
    }
    log.info("Constructed XPATH:" + xpath);
    elementPropertiesEntity.setFindByType(FindByType.XPATH);
    elementPropertiesEntity.setLocatorValue(xpath);
    elementPropertiesEntity.setElementName("Dynamic element");
    elementPropertiesEntity.setDynamicLocator(true);
    Map<String, ElementPropertiesEntity> elementPropertiesMap = getElementPropertiesEntityMap();
    if (elementPropertiesMap == null) {
        elementPropertiesMap = new HashMap<>();
        setElementPropertiesEntityMap(elementPropertiesMap);
    }
    getElementPropertiesEntityMap().put(elementActionVarName, elementPropertiesEntity);
}
Also used : ElementPropertiesEntity(com.testsigma.automator.entity.ElementPropertiesEntity)

Example 7 with ElementPropertiesEntity

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

the class GetAllCheckboxesAction 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 8 with ElementPropertiesEntity

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

the class CheckInvalidSelectorAction method execute.

@Override
protected void execute() throws Exception {
    try {
        getDriver().switchTo().alert();
        this.suggestionActionResult = SuggestionActionResult.Failure;
        throw new Exception();
    } catch (NoAlertPresentException exception) {
    }
    JavascriptExecutor jsExecutor = driver;
    Object frameSrc = jsExecutor.executeScript("return window.location.pathname");
    getDriver().switchTo().parentFrame();
    int size = getDriver().findElements(By.xpath("//iframe")).size();
    if (!frameSrc.toString().equals("/") || size > 0) {
        this.suggestionActionResult = SuggestionActionResult.Failure;
        if (!frameSrc.toString().equals("/")) {
            getDriver().switchTo().frame(getDriver().findElement(By.xpath("//iframe[@src='" + frameSrc + "']")));
        }
        throw new Exception();
    }
    ElementPropertiesEntity elementPropertiesEntity = getElementPropertiesEntity(NaturalTextActionConstants.TESTS_TEP_DATA_MAP_KEY_ELEMENT);
    if (StringUtils.isBlank(elementPropertiesEntity.getLocatorValue())) {
        this.suggestionActionResult = SuggestionActionResult.Success;
        throw new Exception();
    }
    ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(elementPropertiesEntity.getFindByType(), elementPropertiesEntity.getLocatorValue());
    boolean isInvalid = false;
    try {
        getDriver().findElement(elementSearchCriteria.getBy());
        this.suggestionActionResult = SuggestionActionResult.Failure;
        isInvalid = true;
    } catch (Exception e) {
        this.suggestionActionResult = SuggestionActionResult.Success;
    }
    if (isInvalid) {
        throw new Exception();
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) ElementPropertiesEntity(com.testsigma.automator.entity.ElementPropertiesEntity) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) ElementSearchCriteria(com.testsigma.automator.actions.ElementSearchCriteria)

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