Many have heard about
Selenium WebDriver - one of the most popular tools for writing acceptance / integration tests.

Using Selenium, we very quickly noticed that we had to write the same code from time to time to initialize the browser first, close it at the end, take screenshots after each fallen test, etc. (
pruflink ).
Therefore, we decided to allocate this repeating code into a separate library. So
Selenide was
born .
')
What is Selenide
Selenide is a wrapper around Selenium WebDriver that allows you to quickly and easily use it when writing tests, focusing on logic rather than fussing with the browser.
Here is an example of the test. As you can see, the code is minimal. Called "open" - and the browser opened.
@Test public void testLogin() { open("/login"); $(By.name("user.name")).sendKeys("johny"); $("#submitButton").click(); waitUntil(By.id("username"), hasText("Hello, Johny!")); $("#username").shouldHave(cssClass("green-text")); assertThat($("#insuranceDetailsHeader").getText(), equalTo(" ")); assertThat($$("#paymentScheduleTable tr").size(), equalTo(7)); }
When you call the open method, Selenide launches the browser itself and opens the
localhost : 8080 / login page (the port and host are configured, of course). It also ensures that the browser is closed at the end.
Extra Goodies Selenide
Selenide provides additional methods for actions that cannot be done by a single Selenium WebDriver team. These include selecting a radio button, selecting an item from the drop-down list, creating a screen shot, clearing the browser cache, and so on.
@Test public void canFillComplexForm() { open("/client/registration"); setValue(By.name("user.name"), "johny"); selectRadio("user.gender", "male"); selectOption(By.name("user.preferredLayout"), "plain"); selectOptionByText(By.name("user.securityQuestion"), "What is my first car?"); followLink(By.id("submit")); takeScreenShot("complex-form.png"); } @Before public void clearCache() { clearBrowserCache(); }
And the question of Ajax stands out: when testing applications using Ajax, you have to invent a code that is waiting for something (when the button turns green). Selenide provides a rich API for waiting for the onset of various events:
@Test public void pageUsingAjax() { waitFor("#username"); waitUntil("#username", hasText("Hello, Johny!")); waitUntil("#username", hasAttribute("name", "user.name")); waitUntil("#username", hasClass("green-button")); waitUntil("#username", hasValue("Carlson")); waitUntil("#username", appears); waitUntil("#username", disappears); }
I want to try, where to start?
1. Add the Selenide dependency to your project:
<dependency> <groupId>com.codeborne</groupId> <artifactId>selenide</artifactId> <version>1.6</version> </dependency>
2. Import a couple of classes:
include static com.codeborne.selenide.Navigation.* include static com.codeborne.selenide.DOM.*
Done! Write tests, edren-loaf!
Does anyone really use this?
Yes, we
in our company use Selenide in several real projects:
- Java + ANT + JUnit
- Java + Gradle + JUnit
- Scala + ANT + ScalaTest
So you can be sure the project is not raw, really used and supported.
There is also a small reference open-source project in which Selenide is used: the
Hangman game .
Where does such a name come from - Selenide?
Library Selenium took its name from the chemical element (Selenium). And selenides are selenium compounds with other elements.
Here we have:
- Selenide = Selenium + JUnit
- Selenide = Selenium + TestNG
- Selenide = Selenium + ScalaTest
- Selenide = Selenium + anything
Chem on health!
UPD . In March 2013 a version of Selenide 2.0 was released, in which the API was greatly updated. Now using Selenide is even easier and more convenient.
And we launched the site in Russian:
ru.selenide.org