Search in sources :

Example 46 with TimeoutException

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

the class WebDriverService method doSeleniumActionUrlLogin.

@Override
public MessageEvent doSeleniumActionUrlLogin(Session session, String host, String uri) {
    MessageEvent message;
    host = StringUtil.cleanHostURL(host);
    String url = StringUtil.getURLFromString(host, "", uri, "");
    try {
        session.getDriver().get(url);
        message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_URLLOGIN);
        message.setDescription(message.getDescription().replace("%URL%", url));
    } catch (TimeoutException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_URLLOGIN_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 (Exception e) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_URLLOGIN);
        message.setDescription(message.getDescription().replace("%URL%", url) + " " + e.getMessage());
    }
    return message;
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) CerberusEventException(org.cerberus.exception.CerberusEventException) TimeoutException(org.openqa.selenium.TimeoutException) AWTException(java.awt.AWTException) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 47 with TimeoutException

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

the class WebDriverService method doSeleniumActionDoubleClick.

@Override
public MessageEvent doSeleniumActionDoubleClick(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.doubleClick(webElement);
                actions.build().perform();
                message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_DOUBLECLICK);
                message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
                return message;
            }
        }
        message = answer.getResultMessage();
        return message;
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DOUBLECLICK_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 48 with TimeoutException

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

the class WebDriverService method doSeleniumActionManageDialog.

@Override
public MessageEvent doSeleniumActionManageDialog(Session session, Identifier identifier) {
    MessageEvent message;
    try {
        if ("ok".equalsIgnoreCase(identifier.getLocator())) {
            // Accept javascript popup dialog.
            session.getDriver().switchTo().alert().accept();
            session.getDriver().switchTo().defaultContent();
            message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSE_ALERT);
            return message;
        } else if ("cancel".equalsIgnoreCase(identifier.getLocator())) {
            // Dismiss javascript popup dialog.
            session.getDriver().switchTo().alert().dismiss();
            session.getDriver().switchTo().defaultContent();
            message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSE_ALERT);
            return message;
        }
    } catch (NoSuchWindowException exception) {
        // Add try catch to handle not exist anymore alert popup (like when popup is closed).
        LOG.debug("Alert popup is closed ? " + exception.toString());
    } catch (TimeoutException exception) {
        LOG.warn(exception.toString());
    } catch (WebDriverException exception) {
        LOG.debug("Alert popup is closed ? " + exception.toString());
        return parseWebDriverException(exception);
    }
    return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSE_ALERT);
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 49 with TimeoutException

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

the class WebDriverService method doSeleniumActionKeyPress.

@Override
public MessageEvent doSeleniumActionKeyPress(Session session, Identifier identifier, String property) {
    MessageEvent message;
    try {
        if (!StringUtil.isNullOrEmpty(identifier.getLocator())) {
            AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);
            if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
                WebElement webElement = (WebElement) answer.getItem();
                if (webElement != null) {
                    webElement.sendKeys(Keys.valueOf(property));
                    message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS);
                    message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
                    message.setDescription(message.getDescription().replace("%DATA%", property));
                    return message;
                }
            }
            return answer.getResultMessage();
        } else {
            try {
                // disable headless application warning for Robot
                this.disableHeadlessApplicationControl();
                // create wait action
                WebDriverWait wait = new WebDriverWait(session.getDriver(), 01);
                // focus the browser window for Robot to work
                if (this.focusBrowserWindow(session)) {
                    // wait until the browser is focused
                    wait.withTimeout(TIMEOUT_FOCUS, TimeUnit.MILLISECONDS);
                }
                // gets the robot
                Robot r = new Robot();
                // converts the Key description sent through Cerberus into the AWT key code
                int keyCode = KeyCodeEnum.getAWTKeyCode(property);
                if (keyCode != KeyCodeEnum.NOT_VALID.getKeyCode()) {
                    // if the code is valid then presses the key and releases the key
                    r.keyPress(keyCode);
                    r.keyRelease(keyCode);
                    // wait until the action is performed
                    wait.withTimeout(TIMEOUT_WEBELEMENT, TimeUnit.MILLISECONDS);
                    message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT);
                } else {
                    // the key enterer is not valid
                    message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE);
                    LOG.debug("Key " + property + "is not available in the current environment");
                }
                message.setDescription(message.getDescription().replace("%KEY%", property));
            } catch (AWTException ex) {
                LOG.warn(ex);
                message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_ENV_ERROR);
            }
        }
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NO_SUCH_ELEMENT);
        message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
        LOG.debug(exception.toString());
    } 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());
    } catch (WebDriverException exception) {
        LOG.warn(exception.toString());
        return parseWebDriverException(exception);
    }
    return message;
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement) AnswerItem(org.cerberus.util.answer.AnswerItem) Robot(java.awt.Robot) NoSuchElementException(org.openqa.selenium.NoSuchElementException) AWTException(java.awt.AWTException) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 50 with TimeoutException

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

the class WebDriverService method doSeleniumActionWait.

@Override
public MessageEvent doSeleniumActionWait(Session session, Identifier identifier) {
    MessageEvent message;
    try {
        WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);
        wait.until(ExpectedConditions.presenceOfElementLocated(this.getBy(identifier)));
        message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT);
        message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
        return message;
    } catch (TimeoutException 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;
    }
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException)

Aggregations

TimeoutException (org.openqa.selenium.TimeoutException)72 WebElement (org.openqa.selenium.WebElement)37 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)30 NoSuchElementException (org.openqa.selenium.NoSuchElementException)23 Test (org.junit.Test)17 MessageEvent (org.cerberus.engine.entity.MessageEvent)16 By (org.openqa.selenium.By)15 WebDriverException (org.openqa.selenium.WebDriverException)13 IOException (java.io.IOException)10 AnswerItem (org.cerberus.util.answer.AnswerItem)10 WebDriver (org.openqa.selenium.WebDriver)10 BFElementNotFoundException (com.capgemini.ntc.selenium.core.exceptions.BFElementNotFoundException)6 Actions (org.openqa.selenium.interactions.Actions)5 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)5 URISyntaxException (java.net.URISyntaxException)4 TimeUnit (java.util.concurrent.TimeUnit)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)3 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)3 NgWebElement (com.github.sergueik.jprotractor.NgWebElement)2