A Really Quick Start with Selenide
This year I’ve learned Selenide, the Selenium WebDriver based framework that helps you to write compact and concise automation code in java. I’ve talked to Andrei Solntsev who is the author of the framework and watched some of his talks, realizing deep understanding of testing and development processes from the Selenide developers. So let’s just use it!
Wait a moment, there is a litte problem. If you visit “Quick Start” section of the site, you will get some code snippet suggesting, you should use on of the advanced development tools like maven, gradle or ivy. Is it really a must? Not at all! To get started and write effective test with Selenide you need only the basics of test automations: Java, Eclipse and a bit of Selenium. Do you have spare 5–10 minutes? It’s enough, just have a look.
We will need:
- Download the latest version Selenium Client for Java (http://www.seleniumhq.org/download/ ) and selenide.jar ( find the latest http://search.maven.org/#search%7Cga%7C1%7Cselenide and download .jar).
Update (a bit quicker): instead of Selenium Client for Java download Selenium Server — selenium-server-standalone-x.y.z.jar ~35Mb
- Start Eclipse and create new Java Project (File->New->Java Project). Enter project name e.g. SelenideQuickStart. Press Finish.
- Unpack selenium-java-x.y.z.zip and add all jars (selenium-java-x.y.z.jar, and content of lib folder), as well as selenide-x.y.jar to the project (Project Properties -> Java Build Path -> Libraries).
- Update. If you downloaded selenium-server-standalone-x.y.z.jar, just add it instead of the Selenium Client for Java, to have the list much shorter:
- Server edition of Selenium (.jar) contains fully unpacked jar-files of the client edition along with additional classes & packages, it is sometime more difficult to resolve conflicts with third-party libraries, if you testing project needs them. Fortunately, testing projects rarely depend on the other third-party jars, so it should be not a problem for automation.
- Create JUnit test (File->New>JUnit Test Case). Choose JUnit Test 4, enter package, e.g. com.selenide.quickstart and the test class name, e.g. GoogleTest. Press Finish.
- Agree to add JUnit 4 to the project.
- Exchange the standard test code for the following. This test enters “selenide” into Google search field, compares the results and takes a screenshot of the result page.
- // import Selenide Classes
- import staticcom.codeborne.selenide.Condition.*;
- import staticcom.codeborne.selenide.Selenide.*;
- import org.junit.Test;
- import org.openqa.selenium.By;
- // open google start page
- // enter “selenide” in the search field (CSS Selector q)
- // and press Enter
- // first element should be visible
- // and contain the following text
- $(“#ires li.g”).shouldBe(visible)
- .shouldHave(text(“Selenide: concise UI tests in Java”));
- // makes screenshot of the result’s page
- We are done! Start test (as JUnit Test) Run->Run. The Firefox browser opens for a few seconds and runs the test. Look at the result:
- Let’s find the screenshot. Selenide saves png-image and html-page in the folder build/reports/tests. You can open it e.g. in Navigator (Window->Show View->Navigator). Sometime you need to refresh the view with F5 (or File->Refresh).
We have written he working test with Selenide within a few minutes, avoiding learning the deepth of the developers’ frameworks.
Got curios? Watch the video from the authors (1 hour) to learn the advanced features of the Selenide.
Or do you want to quickly write concise Selenium based tests without any IDE? Subscribe to my blog, I am going to write about it soon!
Originally published at blog.vinogradov-it.de on December 29, 2014.