Search in sources :

Example 96 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project cerberus-source by cerberustesting.

the class WebDriverService method doSeleniumActionType.

@Override
public MessageEvent doSeleniumActionType(Session session, Identifier identifier, String valueToType, String propertyName, boolean waitForVisibility, boolean waitForClickability) {
    MessageEvent message;
    try {
        AnswerItem answer = this.getSeleniumElement(session, identifier, waitForVisibility, waitForClickability);
        if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
            WebElement webElement = (WebElement) answer.getItem();
            if (webElement != null) {
                webElement.clear();
                if (!StringUtil.isNull(valueToType)) {
                    webElement.sendKeys(valueToType);
                }
                message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE);
                message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
                if (!StringUtil.isNull(valueToType)) {
                    message.setDescription(message.getDescription().replace("%DATA%", ParameterParserUtil.securePassword(valueToType, propertyName)));
                } else {
                    message.setDescription(message.getDescription().replace("%DATA%", "No property"));
                }
                return message;
            }
        }
        return answer.getResultMessage();
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE_NO_SUCH_ELEMENT);
        message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
        LOG.debug(exception.toString());
        return message;
    } catch (TimeoutException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);
        message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));
        LOG.warn(exception.toString());
        return message;
    } catch (WebDriverException exception) {
        LOG.warn(exception.toString());
        return parseWebDriverException(exception);
    }
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) WebElement(org.openqa.selenium.WebElement) AnswerItem(org.cerberus.util.answer.AnswerItem) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 97 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project cerberus-source by cerberustesting.

the class ControlService method verifyElementInElement.

private MessageEvent verifyElementInElement(TestCaseExecution tCExecution, String element, String childElement) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Control : verifyElementInElement on : '" + element + "' is child of '" + childElement + "'");
    }
    MessageEvent mes;
    if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {
        if (!StringUtil.isNull(element) && !StringUtil.isNull(childElement)) {
            try {
                Identifier identifier = identifierService.convertStringToIdentifier(element);
                Identifier childIdentifier = identifierService.convertStringToIdentifier(childElement);
                if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {
                    if (this.webdriverService.isElementInElement(tCExecution.getSession(), identifier, childIdentifier)) {
                        mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTINELEMENT);
                        mes.resolveDescription("STRING2", element);
                        mes.resolveDescription("STRING1", childElement);
                        return mes;
                    } else {
                        mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);
                        mes.resolveDescription("STRING2", element);
                        mes.resolveDescription("STRING1", childElement);
                        return mes;
                    }
                } else {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NO_SUCH_ELEMENT);
                    mes.resolveDescription("SELEX", new NoSuchElementException("").toString());
                    mes.resolveDescription("ELEMENT", element);
                    return mes;
                }
            } catch (WebDriverException exception) {
                return parseWebDriverException(exception);
            }
        } else {
            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);
            mes.resolveDescription("STRING2", element);
            mes.resolveDescription("STRING1", childElement);
            return mes;
        }
    } else {
        mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        mes.resolveDescription("CONTROL", "verifyElementInElement");
        mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());
        return mes;
    }
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 98 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project cerberus-source by cerberustesting.

the class AppiumService method clearField.

@Override
public MessageEvent clearField(final Session session, final Identifier identifier) {
    try {
        final TouchAction action = new TouchAction(session.getAppiumDriver());
        if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {
            final Coordinates coordinates = getCoordinates(identifier);
            click(session, identifier);
        } else {
            click(session, identifier);
            // action.press(ElementOption.element(getElement(session, identifier, false, false))).waitAction(WaitOptions.waitOptions(Duration.ofMillis(8000))).release().perform();
            // MobileElement element = (MobileElement) session.getAppiumDriver().findElementByAccessibilityId("SomeAccessibilityID");
            // element.clear();
            // WebElement elmt = this.getElement(session, identifier, false, false);
            this.getElement(session, identifier, false, false).clear();
        }
        return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLEAR).resolveDescription("ELEMENT", identifier.toString());
    } catch (NoSuchElementException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getMessage());
        }
        return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLEAR_NO_SUCH_ELEMENT).resolveDescription("ELEMENT", identifier.toString());
    } catch (WebDriverException e) {
        LOG.warn(e.getMessage());
        return parseWebDriverException(e);
    }
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TouchAction(io.appium.java_client.TouchAction)

Example 99 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project cerberus-source by cerberustesting.

the class AppiumService method click.

@Override
public MessageEvent click(final Session session, final Identifier identifier) {
    try {
        final TouchAction action = new TouchAction(session.getAppiumDriver());
        if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {
            final Coordinates coordinates = getCoordinates(identifier);
            action.tap(PointOption.point(coordinates.getX(), coordinates.getY())).perform();
        } else {
            action.tap(ElementOption.element(getElement(session, identifier, false, false))).perform();
        }
        return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICK).resolveDescription("ELEMENT", identifier.toString());
    } catch (NoSuchElementException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getMessage());
        }
        return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT).resolveDescription("ELEMENT", identifier.toString());
    } catch (WebDriverException e) {
        LOG.warn(e.getMessage());
        return parseWebDriverException(e);
    }
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TouchAction(io.appium.java_client.TouchAction)

Example 100 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project cerberus-source by cerberustesting.

the class AppiumService method wait.

@Override
public MessageEvent wait(Session session, Identifier identifier) {
    MessageEvent message;
    try {
        WebElement elmt = this.getElement(session, identifier, false, false);
        message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT);
        message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
        return message;
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT);
        message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
        LOG.debug(exception.toString());
        return message;
    } catch (WebDriverException exception) {
        LOG.error("Exception during Appium Wait Operation.", exception);
        return parseWebDriverException(exception);
    }
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Aggregations

NoSuchElementException (org.openqa.selenium.NoSuchElementException)275 WebElement (org.openqa.selenium.WebElement)158 TimeoutException (org.openqa.selenium.TimeoutException)48 Test (org.junit.Test)41 WebDriverException (org.openqa.selenium.WebDriverException)35 MessageEvent (org.cerberus.engine.entity.MessageEvent)34 Test (org.testng.annotations.Test)34 MockitoTest (com.seleniumtests.MockitoTest)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 WebDriver (org.openqa.selenium.WebDriver)22 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)22 Select (org.openqa.selenium.support.ui.Select)19 AnswerItem (org.cerberus.util.answer.AnswerItem)18 By (org.openqa.selenium.By)18 CerberusEventException (org.cerberus.exception.CerberusEventException)11 StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)11 AndroidElement (io.appium.java_client.android.AndroidElement)10 Actions (org.openqa.selenium.interactions.Actions)10 BFElementNotFoundException (com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException)9 BFElementNotFoundException (com.capgemini.ntc.selenium.core.exceptions.BFElementNotFoundException)9