Search in sources :

Example 51 with TimeoutException

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

the class WebDriverService method doSeleniumActionWaitVanish.

@Override
public MessageEvent doSeleniumActionWaitVanish(Session session, Identifier identifier) {
    MessageEvent message;
    try {
        WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);
        wait.until(ExpectedConditions.invisibilityOfElementLocated(this.getBy(identifier)));
        message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAITVANISH_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)

Example 52 with TimeoutException

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

the class WebDriverService method doSeleniumActionRightClick.

@Override
public MessageEvent doSeleniumActionRightClick(Session session, Identifier identifier) {
    MessageEvent message;
    try {
        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) {
                Actions actions = new Actions(session.getDriver());
                actions.contextClick(webElement);
                actions.build().perform();
                message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_RIGHTCLICK);
                message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
                return message;
            }
        }
        return answer.getResultMessage();
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_RIGHTCLICK_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 53 with TimeoutException

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

the class AppiumService method getElement.

private WebElement getElement(Session session, Identifier identifier, boolean visible, boolean clickable) {
    AppiumDriver driver = session.getAppiumDriver();
    By locator = this.getBy(identifier);
    LOG.debug("Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());
    try {
        WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_appium_wait_element()));
        if (visible) {
            if (clickable) {
                wait.until(ExpectedConditions.elementToBeClickable(locator));
            } else {
                wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
            }
        } else {
            wait.until(ExpectedConditions.presenceOfElementLocated(locator));
        }
    } catch (TimeoutException exception) {
        LOG.fatal("Exception waiting for element :" + exception.toString());
        throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator());
    }
    LOG.debug("Finding Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());
    return driver.findElement(locator);
}
Also used : AppiumDriver(io.appium.java_client.AppiumDriver) By(org.openqa.selenium.By) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 54 with TimeoutException

use of org.openqa.selenium.TimeoutException in project devonfw-testing by devonfw.

the class DriverExtention method waitForElement.

public WebElement waitForElement(final By by) throws BFElementNotFoundException {
    BasePage.getAnalytics().sendMethodEvent(BasePage.analitycsCategoryName);
    long startTime = System.currentTimeMillis();
    WebElement element = null;
    try {
        element = webDriverWait().until(new ExpectedCondition<WebElement>() {

            @Override
            public WebElement apply(WebDriver driver) {
                return driver.findElement(by);
            }
        });
    } catch (TimeoutException | NoSuchElementException e) {
        boolean isTimeout = true;
        throw new BFElementNotFoundException(by, isTimeout, BasePage.EXPLICITYWAITTIMER);
    }
    BFLogger.logTime(startTime, "waitForElement()", by.toString());
    return element;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BFElementNotFoundException(com.capgemini.ntc.selenium.core.exceptions.BFElementNotFoundException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 55 with TimeoutException

use of org.openqa.selenium.TimeoutException in project devonfw-testing by devonfw.

the class DriverExtention method waitForPageLoaded.

public void waitForPageLoaded() throws BFElementNotFoundException {
    long startTime = System.currentTimeMillis();
    final String jsVariable = "return document.readyState";
    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript(jsVariable).equals("complete");
        }
    };
    int progressBarWaitTimer = BasePage.PROGRESSBARWAITTIMER;
    WebDriverWait wait = webDriverWait(progressBarWaitTimer);
    try {
        wait.until(expectation);
    } catch (TimeoutException | NoSuchElementException e) {
        boolean isTimeout = true;
        throw new BFElementNotFoundException(By.cssSelector(jsVariable), isTimeout, progressBarWaitTimer);
    }
    BFLogger.logTime(startTime, "waitForPageLoaded");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BFElementNotFoundException(com.capgemini.ntc.selenium.core.exceptions.BFElementNotFoundException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) NoSuchElementException(org.openqa.selenium.NoSuchElementException) 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