Java Code Examples for com.codeborne.selenide.WebDriverRunner#driver()

The following examples show how to use com.codeborne.selenide.WebDriverRunner#driver() . 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: SelenideAddons.java    From neodymium-library with MIT License 5 votes vote down vote up
/**
 * Returns an supplier that will return all results if any. It will return elements that are found by parentSelector
 * and have a result for subElementSelector. It does NOT return the subelements, it is meant to be a workaround for
 * poor CSS where the parent is only recognizable by looking at its children, but we don't need the children.
 * Important, this is meant to be lazy so don't call get() when you setup a field or so, only when you really need
 * the element. It reselects all the time!
 *
 * @param parentSelector
 *            The selector that is used to find subElementSelector
 * @param subElementSelector
 *            The selector that is shall have the element selected by parentSelector
 * @return an supplier that will return the result later
 */
public static Supplier<ElementsCollection> parentsBySubElement(final By parentSelector, final By subElementSelector)
{
    return new Supplier<ElementsCollection>()
    {
        @Override
        public ElementsCollection get()
        {
            List<SelenideElement> list = $$(parentSelector).stream().filter(e -> {
                return e.$(subElementSelector).exists();
            }).collect(Collectors.toList());
            return new ElementsCollection(new WebElementsCollectionWrapper(WebDriverRunner.driver(), list));
        };
    };
}
 
Example 2
Source File: SelenideAddons.java    From neodymium-library with MIT License 5 votes vote down vote up
/**
 * Returns an supplier that will return all results if any. It will return elements that are found by parentSelector
 * and have a no result for subElementSelector. It does NOT return the subelements, it is meant to be a workaround
 * for poor CSS where the parent is only recognizable by looking at its children, but we don't need the children.
 * Important, this is meant to be lazy so don't call get() when you setup a field or so, only when you really need
 * the element. It reselects all the time!
 *
 * @param parentSelector
 *            The selector that is used to find subElementSelector
 * @param subElementSelector
 *            The selector that shall not be contained by the parentSelector
 * @return an supplier that will return the result later
 */
public static Supplier<ElementsCollection> parentsWithoutSubElement(final By parentSelector, final By subElementSelector)
{
    return new Supplier<ElementsCollection>()
    {
        @Override
        public ElementsCollection get()
        {
            List<SelenideElement> list = $$(parentSelector).stream().filter(e -> {
                return !e.$(subElementSelector).exists();
            }).collect(Collectors.toList());
            return new ElementsCollection(new WebElementsCollectionWrapper(WebDriverRunner.driver(), list));
        };
    };
}
 
Example 3
Source File: SelenideAddons.java    From neodymium-library with MIT License 5 votes vote down vote up
/**
 * The missing wrapper to generate screenshots and save the html source code if a jUnit assertion fails.<br>
 * <br>
 * <p>
 * Sample: Assert that page title is correct and dump the page source and a screenshot in case of a mismatch
 * <code> wrapAssertionError(()-&gt;{Assert.assertEquals("MyPageTitle", Selenide.title());});</code>
 * </p>
 * 
 * @param runnable
 *            The lambda containing an assertion
 */
public static void wrapAssertionError(final Runnable runnable)
{
    try
    {
        runnable.run();
    }
    catch (AssertionError e)
    {
        Driver driver = WebDriverRunner.driver();
        String message = "No error message provided by the Assertion.";
        if (StringUtils.isNotBlank(e.getMessage()))
        {
            message = e.getMessage();
        }
        else
        {
            AssertionError wrapper = new AssertionError(message, e.getCause());
            wrapper.setStackTrace(e.getStackTrace());
            e = wrapper;
        }
        SelenideLogger.commitStep(new SelenideLog("Assertion error", message), e);
        if (!driver.config().assertionMode().equals(AssertionMode.SOFT))
        {
            throw UIAssertionError.wrap(driver, e, 0);
        }
    }
}