com.codeborne.selenide.Driver Java Examples

The following examples show how to use com.codeborne.selenide.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 6 votes vote down vote up
/**
 * The missing regular expression condition for attributes.<br>
 * <br>
 * <p>
 * Sample: Assert that given element's value attribute matches given regular expression
 * <code>$("input").should(matchValue("Hello\s*John"))</code>
 * </p>
 *
 * @param attributeName
 *            The name of the attribute that should be matched with the regex
 * @param regex
 *            e.g. Kicked.*Chuck Norris - in this case ".*" can contain any characters including spaces, tabs, CR
 *            etc.
 * @return a Selenide {@link Condition}
 */
public static Condition matchAttribute(final String attributeName, final String regex)
{
    return new Condition("match " + attributeName)
    {
        @Override
        public String toString()
        {
            return this.getName() + " '" + regex + '\'';
        }

        @Override
        public boolean apply(Driver driver, WebElement element)
        {
            return Html.text.matches(getAttributeValue(element, attributeName), regex);
        }
    };
}
 
Example #2
Source File: CheckBoxChecked.java    From masquerade with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(Driver driver, WebElement element) {
    WebElement input = element;

    if (!INPUT_TAG_NAME.equals(input.getTagName())) {
        input = element.findElement(byCssSelector("input[type=\"checkbox\"]"));
    }

    return input != null
            && INPUT_TAG_NAME.equals(input.getTagName())
                    ? driver.executeJavaScript("return arguments[0].checked", input)
                    : false;
}
 
Example #3
Source File: SpecificCondition.java    From masquerade with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(Driver driver, WebElement element) {
    SpecificConditionHandler handler = SpecificConditionContext.getHandler();
    if (handler == null) {
        throw new RuntimeException(
                "SpecificCondition must be checked ony in SpecificConditionHandler implementations");
    }

    return handler.apply(this);
}
 
Example #4
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);
        }
    }
}
 
Example #5
Source File: SelenideAppiumFieldDecorator.java    From selenide-appium with MIT License 5 votes vote down vote up
private DefaultElementByBuilder byBuilder(Driver driver) {
  if (driver == null
    || !HasSessionDetails.class.isAssignableFrom(driver.getWebDriver().getClass())) {
    return new DefaultElementByBuilder(null, null);
  }
  else {
    HasSessionDetails d = (HasSessionDetails) driver.getWebDriver();
    return new DefaultElementByBuilder(d.getPlatformName(), d.getAutomationName());
  }
}
 
Example #6
Source File: N2oDrawer.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
@Override
public boolean apply(Driver driver, WebElement element) {
    return getAttributeValue(element).contains(attributeName + ": " + expectedAttributeValue);
}
 
Example #7
Source File: N2oDrawer.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
@Override
public String actualValue(Driver driver, WebElement element) {
    return String.format("style=\"%s\"", getAttributeValue(element));
}
 
Example #8
Source File: SelenideAppiumFieldDecorator.java    From selenide-appium with MIT License 4 votes vote down vote up
public SelenideAppiumFieldDecorator(Driver driver) {
  super(driver.getWebDriver());
  this.driver = driver;
  this.factory = new DefaultElementLocatorFactory(driver.getWebDriver());
  this.builder = byBuilder(driver);
}