Search in sources :

Example 76 with TimeoutException

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

the class ControlService method verifyUrl.

private MessageEvent verifyUrl(TestCaseExecution tCExecution, String value1) throws CerberusEventException {
    LOG.debug("Control: verifyUrl on: {}", value1);
    MessageEvent mes;
    if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {
        String url;
        // Control is made forcing the / at the beginning of URL. getCurrentUrl from Selenium
        // already have that control but value1 is specified by user and could miss it.
        final String controlUrl = StringUtil.addPrefixIfNotAlready(value1, "/");
        try {
            LOG.debug("Before wait: {}", System.currentTimeMillis());
            WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(), TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));
            // Wait until the url is the expected one
            wait.until(new Function<WebDriver, Boolean>() {

                final String expectedValue = controlUrl;

                @Override
                public Boolean apply(WebDriver driver) {
                    String value = "";
                    try {
                        value = webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());
                        LOG.debug("Get new url: {} >> Expected url: {}", value, expectedValue);
                    } catch (CerberusEventException ex) {
                        LOG.warn(ex.getMessageError().getDescription());
                    }
                    return value.equalsIgnoreCase(expectedValue);
                }
            });
            LOG.debug("After wait: {}", System.currentTimeMillis());
            url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());
            mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_URL);
            mes.resolveDescription("STRING1", url);
        } catch (TimeoutException exception) {
            url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());
            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_URL);
            mes.resolveDescription("STRING1", url);
        } catch (WebDriverException exception) {
            return parseWebDriverException(exception);
        }
        mes.resolveDescription("STRING2", controlUrl);
    } else {
        mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYURL);
        mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());
    }
    return mes;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) CerberusEventException(org.cerberus.exception.CerberusEventException) MessageEvent(org.cerberus.engine.entity.MessageEvent) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 77 with TimeoutException

use of org.openqa.selenium.TimeoutException 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 78 with TimeoutException

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

the class WebDriverService method doSeleniumActionMouseDown.

@Override
public MessageEvent doSeleniumActionMouseDown(Session session, Identifier identifier, 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) {
                Actions actions = new Actions(session.getDriver());
                actions.clickAndHold(webElement);
                actions.build().perform();
                message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEDOWN);
                message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
                return message;
            }
        }
        return answer.getResultMessage();
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEDOWN_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 : Actions(org.openqa.selenium.interactions.Actions) 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 79 with TimeoutException

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

the class WebDriverService method doSeleniumActionDragAndDrop.

// we need to implement the right selenium dragAndDrop method when it works
@Override
public MessageEvent doSeleniumActionDragAndDrop(Session session, Identifier drag, Identifier drop, boolean waitForVisibility, boolean waitForClickability) throws IOException {
    MessageEvent message;
    try {
        AnswerItem answerDrag = this.getSeleniumElement(session, drag, waitForVisibility, waitForClickability);
        AnswerItem answerDrop = this.getSeleniumElement(session, drop, waitForVisibility, waitForClickability);
        if (answerDrag.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode()) && answerDrop.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
            WebElement source = (WebElement) answerDrag.getItem();
            WebElement target = (WebElement) answerDrop.getItem();
            if (source != null && target != null) {
                ((JavascriptExecutor) session.getDriver()).executeScript("function createEvent(typeOfEvent) {\n" + "var event =document.createEvent(\"CustomEvent\");\n" + "event.initCustomEvent(typeOfEvent,true, true, null);\n" + "event.dataTransfer = {\n" + "data: {},\n" + "setData: function (key, value) {\n" + "this.data[key] = value;\n" + "},\n" + "getData: function (key) {\n" + "return this.data[key];\n" + "}\n" + "};\n" + "return event;\n" + "}\n" + "\n" + "function dispatchEvent(element, event,transferData) {\n" + "if (transferData !== undefined) {\n" + "event.dataTransfer = transferData;\n" + "}\n" + "if (element.dispatchEvent) {\n" + "element.dispatchEvent(event);\n" + "} else if (element.fireEvent) {\n" + "element.fireEvent(\"on\" + event.type, event);\n" + "}\n" + "}\n" + "\n" + "function simulateHTML5DragAndDrop(element, destination) {\n" + "var dragStartEvent =createEvent('dragstart');\n" + "dispatchEvent(element, dragStartEvent);\n" + "var dropEvent = createEvent('drop');\n" + "dispatchEvent(destination, dropEvent,dragStartEvent.dataTransfer);\n" + "var dragEndEvent = createEvent('dragend');\n" + "dispatchEvent(element, dragEndEvent,dropEvent.dataTransfer);\n" + "}\n" + "\n" + "var source = arguments[0];\n" + "var destination = arguments[1];\n" + "simulateHTML5DragAndDrop(source,destination);", source, target);
            }
            message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_DRAGANDDROP);
            message.setDescription(message.getDescription().replace("%SOURCE%", drag.getIdentifier() + "=" + drag.getLocator()));
            message.setDescription(message.getDescription().replace("%TARGET%", drop.getIdentifier() + "=" + drop.getLocator()));
            return message;
        } else {
            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP_NO_SUCH_ELEMENT);
            message.setDescription(message.getDescription().replace("%ELEMENT%", drag.getIdentifier() + "=" + drag.getLocator()));
            return message;
        }
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP_NO_SUCH_ELEMENT);
        message.setDescription(message.getDescription().replace("%ELEMENT%", drag.getIdentifier() + "=" + drag.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;
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) 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)

Example 80 with TimeoutException

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

the class WebDriverService method doSeleniumActionOpenURL.

@Override
public MessageEvent doSeleniumActionOpenURL(Session session, String host, Identifier identifier, boolean withBase) {
    MessageEvent message;
    String url = "";
    try {
        if (!StringUtil.isNull(identifier.getLocator())) {
            if (withBase) {
                host = StringUtil.cleanHostURL(host);
                url = StringUtil.getURLFromString(host, "", identifier.getLocator(), "");
            } else {
                url = StringUtil.cleanHostURL(identifier.getLocator());
            }
            session.getDriver().get(url);
            message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_OPENURL);
            message.setDescription(message.getDescription().replace("%URL%", url));
        } else {
            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENURL);
            message.setDescription(message.getDescription().replace("%URL%", url));
        }
    } catch (TimeoutException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENURL_TIMEOUT);
        message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_pageLoadTimeout())));
        message.setDescription(message.getDescription().replace("%URL%", url));
        LOG.warn(exception.toString());
    } catch (WebDriverException exception) {
        LOG.warn(exception.toString());
        return parseWebDriverException(exception);
    }
    return message;
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

TimeoutException (org.openqa.selenium.TimeoutException)249 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)109 WebElement (org.openqa.selenium.WebElement)87 NoSuchElementException (org.openqa.selenium.NoSuchElementException)52 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)40 WebDriver (org.openqa.selenium.WebDriver)39 WebDriverException (org.openqa.selenium.WebDriverException)39 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)31 MessageEvent (org.cerberus.engine.entity.MessageEvent)27 ExpectedConditions (org.openqa.selenium.support.ui.ExpectedConditions)27 Reporter (com.coveros.selenified.utilities.Reporter)26 Test (org.junit.Test)25 By (org.openqa.selenium.By)22 Test (org.testng.annotations.Test)20 Element (com.coveros.selenified.element.Element)17 IOException (java.io.IOException)17 AnswerItem (org.cerberus.util.answer.AnswerItem)17 Dimension (org.openqa.selenium.Dimension)14 Point (org.openqa.selenium.Point)14 Constants (com.coveros.selenified.utilities.Constants)13