Search in sources :

Example 6 with ElementSearchCriteria

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

the class DriverSessionActionsController method findElements.

@GetMapping(value = "/find_elements")
@ResponseStatus(HttpStatus.OK)
public List<MobileElementDTO> findElements(@PathVariable("session_id") String sessionId, @RequestParam("platform") Platform platform, @RequestParam("locatorType") LocatorType locatorType, @RequestParam("byValue") String byValue) throws MobileAutomationServerCommandExecutionException {
    FindByType findByType = FindByType.getType(locatorType);
    ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(findByType, byValue);
    log.info("Request for searching Elements  in session - " + sessionId);
    List<MobileElement> mobileElements = driverSessionCommand.findElements(sessionId, platform, elementSearchCriteria);
    return mobileElementMapper.map(mobileElements);
}
Also used : MobileElement(com.testsigma.automator.actions.mobile.MobileElement) FindByType(com.testsigma.automator.actions.FindByType) ElementSearchCriteria(com.testsigma.automator.actions.ElementSearchCriteria)

Example 7 with ElementSearchCriteria

use of com.testsigma.automator.actions.ElementSearchCriteria 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

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