Java Code Examples for org.openqa.selenium.TimeoutException#getCause()

The following examples show how to use org.openqa.selenium.TimeoutException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PageComponent.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a 'wait' proxy that determines if this page component is visible
 * 
 * @return page component if visible; otherwise 'null'
 */
public static Coordinator<PageComponent> componentIsVisible() {
    return new Coordinator<PageComponent>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        @SuppressWarnings("squid:S1774")
        public PageComponent apply(final SearchContext context) {
            PageComponent component = verifyContext(context);
            return (component.isDisplayed()) ? component : null;
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "page component to be visible";
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new ComponentStillInvisibleTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 2
Source File: PageComponent.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a 'wait' proxy that determines if this page component is hidden
 * 
 * @return page component if hidden; otherwise 'null'
 */
public static Coordinator<PageComponent> componentIsHidden() {
    return new Coordinator<PageComponent>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        @SuppressWarnings("squid:S1774")
        public PageComponent apply(final SearchContext context) {
            PageComponent component = verifyContext(context);
            return (component.isInvisible()) ? component : null;
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "page component to be absent or hidden";
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new ComponentStillDisplayedTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 3
Source File: Coordinators.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a 'wait' proxy that determines if a new window has opened
 * 
 * @param initialHandles initial set of window handles
 * @return new window handle; 'null' if no new window found
 */
public static Coordinator<String> newWindowIsOpened(final Set<String> initialHandles) {
    return new Coordinator<String>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        public String apply(final SearchContext context) {
            Set<String> currentHandles = WebDriverUtils.getDriver(context).getWindowHandles();
            currentHandles.removeAll(initialHandles);
            if (currentHandles.isEmpty()) {
                return null;
            } else {
                return currentHandles.iterator().next();
            }
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "new window to be opened";
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new NoWindowAppearedTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 4
Source File: Coordinators.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a 'wait' proxy that determines if the specified window has closed
 * 
 * @param windowHandle handle of window that's expected to close
 * @return 'true' if the specified window has closed; otherwise 'false'
 */
public static Coordinator<Boolean> windowIsClosed(final String windowHandle) {
    return new Coordinator<Boolean>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        public Boolean apply(final SearchContext context) {
            Set<String> currentHandles = WebDriverUtils.getDriver(context).getWindowHandles();
            return ! currentHandles.contains(windowHandle);
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "window with handle '" + windowHandle + "' to be closed";
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new WindowStillExistsTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 5
Source File: Coordinators.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * An expectation for checking that an element is present on the DOM of a page. This does not
 * necessarily mean that the element is visible.
 * 
 * @param locator used to find the element
 * @return the WebElement once it is located
 */
public static Coordinator<WebElement> presenceOfElementLocated(final By locator) {
    return new Coordinator<WebElement>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        public WebElement apply(SearchContext context) {
            return context.findElement(locator);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "presence of element located by: " + locator;
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new ElementNotPresentTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 6
Source File: Coordinators.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * An expectation for checking that an element, known to be present on the
 * DOM of a page, is visible. Visibility means that the element is not only
 * displayed but also has a height and width that is greater than 0.
 *
 * @param element the WebElement
 * @return the (same) WebElement once it is visible
 */
public static Coordinator<WebElement> visibilityOf(final WebElement element) {
    return new Coordinator<WebElement>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        public WebElement apply(SearchContext context) {
            return elementIfVisible(element);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "visibility of " + element;
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new ElementAbsentOrHiddenTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 7
Source File: Coordinators.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Boolean wrapper for a condition, which returns 'true' if the expectation is met.
 * 
 * @param condition expected condition
 * @return 'true' if the specified condition returns a 'positive' result
 */
public static Coordinator<Boolean> has(final Function<SearchContext, ?> condition) {
    return new Coordinator<Boolean>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        public Boolean apply(SearchContext context) {
            Object result = condition.apply(context);
            if (result != null) {
                if (result instanceof Boolean) {
                    return (Boolean) result;
                } else {
                    return true;
                }
            }
            return false;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "condition to be valid: " + condition;
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            if (condition instanceof Coordinator) {
                return ((Coordinator<?>) condition).differentiateTimeout(e);
            }
            return new ConditionStillInvalidTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 8
Source File: Coordinators.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Inverse wrapper for a condition, which returns 'false' if the expectation is met.
 * 
 * @param condition expected condition
 * @return 'true' if the specified condition returns a 'negative' result
 */
public static Coordinator<Boolean> not(final Function<SearchContext, ?> condition) {
    return new Coordinator<Boolean>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        public Boolean apply(SearchContext context) {
            Object result = condition.apply(context);
            return result == null || result == Boolean.FALSE;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "condition to not be valid: " + condition;
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new ConditionStillValidTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 9
Source File: Coordinators.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a 'wait' proxy that determines if the specified element reference has gone stale.
 *
 * @param element the element to wait for
 * @return 'false' if the element reference is still valid; otherwise 'true'
 */
public static Coordinator<Boolean> stalenessOf(final WebElement element) {
    return new Coordinator<Boolean>() {
        private final ExpectedCondition<Boolean> condition = conditionInitializer();

        // initializer for [condition] field
        private final ExpectedCondition<Boolean> conditionInitializer() {
            if (element instanceof WrapsElement) {
                return ExpectedConditions.stalenessOf(((WrapsElement) element).getWrappedElement());
            } else {
                return ExpectedConditions.stalenessOf(element);
            }
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public Boolean apply(final SearchContext ignored) {
            return condition.apply(null);
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return condition.toString();
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new ElementStillFreshTimeoutException(e.getMessage(), e.getCause());
        }
    };
}
 
Example 10
Source File: JsUtility.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a 'wait' proxy that determines if the current document is in 'ready' state.
 * 
 * @return 'true' if the document is in 'ready' state; otherwise 'false'
 */
public static Coordinator<Boolean> documentIsReady() {
    return new Coordinator<Boolean>() {
        
        /**
         * {@inheritDoc}
         */
        @Override
        public Boolean apply(final SearchContext context) {
            return (Boolean) WebDriverUtils.getExecutor(context).executeScript(DOCUMENT_READY);
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "document to be ready";
        }
        
        /**
         * {@inheritDoc}
         */
        @Override
        public TimeoutException differentiateTimeout(TimeoutException e) {
            return new DocumentNotReadyTimeoutException(e.getMessage(), e.getCause());
        }
    };
}