Documentation

Released Selenide 3.10!

Blog

Documentation

Poor software doesn't have documentation. Brilliant software doesn't need documentation.

We are proud to claim that Selenide is so simple that you don't need to read tons of documentation.
The whole work with Selenide consists of three simple things!

Three simple things:

1. Open the page
2. $(find element).doAction()
3. $(find element).checkCondition()

  open("/login");
  $("#submit").click();
  $(".message").shouldHave(text("Hello"));

Use the power of IDE

Selenide API consists of few classes. We suggest you to stop reading, open your IDE and start typing.

Just type: $(selector). - and IDE suggest you all the options.

Selenide API: Just start typing

Use the power of nowdays development environments instead of bothering with documentation!


Selenide API

Here is a full Selenide javadoc.

Just for reference, these are Selenide classes you will probably need for work:

com.codeborne.selenide.Selenide [src] [javadoc]

The main class for using Selenide library. The basic methods are open, $ and $$ (import static com.codeborne.selenide.Selenide.* for readability):

Defining SelenideElement doesn’t trigger the search in DOM yet, so you can save the locators in variables for later use at any place. With a SelenideElement instance, you can either do action with it (click, setValue etc.) or check a condition: shouldHave(text("abc")). Both will trigger the search of the elements in DOM.

There is also a number of other less frequently used methods in Selenide class: sleep(), refresh() and title().

Look for more documentation in Wiki (soon).

com.codeborne.selenide.SelenideElement [src] [javadoc]

SelenideElement is a wrapper around Selenium WebElement, giving it some additional convenience methods to do Selenide magic.

You can chain SelenideElements with $ eg. $("#page").$("#table").$("#header") which doesn’t trigger DOM search.

Assertions trigger the DOM search and returning SelenideElement allowing fluent interface.

  • should(Condition)
  • shouldBe(Condition)
  • shouldHave(Condition)
  • shouldNot(Condition)
  • shouldNotBe(Condition)
  • shouldNotHave(Condition)

Actions on the elements (e.g.):

  • click()
  • doubleClick()
  • pressEnter(String)
  • selectOption(String text)
  • selectOptionByValue(String value)
  • setValue(String)
  • val(String)
  • append(String)

Getting status and values of elements (e.g.):

  • val()
  • data()
  • text()
  • isDisplayed()
  • exists()
  • getSelectedOption()
  • getSelectedText()
  • getSelectedValue()

Other useful commands (e.g.):

  • waitUntil(Condition, milliseconds)
  • waitWhile(Condition, milliseconds)
  • uploadFromClasspath(String fileName)
  • download()
  • toWebElement()

Look for more documentation in Wiki (soon).

com.codeborne.selenide.Condition [src] [javadoc]

Conditions are used in should/waitUntil/waitWhile constructions. We recommend to static import com.codeborne.selenide.Condition.* to get full advantage of readible test code.

  • visible appear // e.g. $(“input”).shouldBe(visible)
  • present exist
  • hidden disappear not(visible)
  • readonly // e.g. $(“input”).shouldBe(readonly)
  • attribute(String)
  • name // e.g. $(“input”).shouldHave(name(“fname”))
  • value // e.g. $(“input”).shouldHave(value(“John”))
  • type // $(“#input”).shouldHave(type(“checkbox”))
  • id // $(“#input”).shouldHave(id(“myForm”))
  • empty // $(“h2”).shouldBe(empty)
  • options
  • cssClass(String)
  • focused
  • enabled
  • disabled
  • selected
  • matchText(String regex)
  • text(String substring)
  • exactText(String wholeText)
  • textCaseSensitive(String substring)
  • exactTextCaseSensitive(String wholeText)

Look for more documentation in Wiki (soon).

You can easily add custom conditions by extending class com.codeborne.selenide.Condition.

For example:

public static Condition css(final String propName, final String propValue) {
    @Override
    public boolean apply(WebElement element) {
      return propValue.equalsIgnoreCase(element.getCssValue(propName));
    }

    @Override
    public String actualValue(WebElement element) {
        return element.getCssValue(propName);
    }
};

// Example usage:
$("h1").shouldHave(css("font-size", "16px"));

com.codeborne.selenide.Selectors [src] [javadoc]

This class contains additional By selectors that are missing in standard Selenium WebDriver API. We recommend static import used selectors.

  • byText - search by exact text
  • withText - search by text (substring)
  • by - search by attribute
  • byTitle - search by “title” attribute
  • byValue - search by “value” attribute
// Example usage:
$(byText("Login")).shouldBe(visible));
$(By.xpath("//div[text()='Login']")).shouldBe(visible); // you can use any org.openqa.selenium.By.* selector 

Look for more documentation in Wiki (soon).

com.codeborne.selenide.ElementsCollection [src] [javadoc]

This is the class returned by $$ method. It contains a list of web elements with additionals methods:

Assertions, which trigger the DOM search

  • shouldBe - e.g. $$(".errors").shouldBe(empty)
  • shouldHave - e.g. $$("#mytable tbody tr").shouldHave(size(2))

Addtitional filtering, they still do not trigger DOM search and can be safely saved in a variable.

  • get(int) - returns n-th element as SelenideElement and still do not trigger DOM search or Collection bounds check
  • find - e.g. $$("#multirowTable tr").findBy(text("Norris"))
  • filter - e.g. $$("#multirowTable tr").filterBy(text("Norris"))
  • exclude - e.g. $$("#multirowTable tr").excludeWith(text("Chuck"))

Look for more documentation in Wiki (soon).

com.codeborne.selenide.WebDriverRunner [src] [javadoc]

This class contains some browser related functions (e.g.):

  • isChrome()
  • isFirefox()
  • isHeadless()
  • url() - returns current url
  • source() - returns whole HTML source of the actual window
  • getWebDriver()

Look for more documentation in Wiki (soon).

com.codeborne.selenide.Configuration [src] [javadoc]

This class contains configurations for test runs e.g.:

  • timeout - (String) can be changed in runtime
  • browser (e.g. chrome, ie, firefox)
  • baseUrl
  • reportsFolder

You can also pass the configuration parameters in as system properties to make use of CI Jobs (e.g. -Dselenide.baseUrl=http://staging-server.com/start)

Look for more documentation in Wiki (soon).

See more details on these and other classes in javadoc

Stay tuned!



blog comments powered by Disqus

The project is maintained by