Monday, September 21, 2015

Concise Selenium Tests in Java using Selenide

There are many wrappers available on Selenium to simplify writing UI tests using Selenium. Selenide is the new Selenium wrapper which supports all features of that Selenium. It allows automation developers to work with elements using jQuery style of notation. It makes Selenium code more readable, and wraps features like waits otherwise have to be written explicitly. I have tried creating a simple test using Selenide, found it's pretty simple to write tests, tests are more readable, don't have to worry for creating WebDriver object, and closing WebDriver object. I would like try Selenide for more complex tests in coming days. Here is a simple test to validate search results of Google's search page for a simple query.

package com.selenidedemo.one;

import org.testng.annotations.Test;
import static com.codeborne.selenide.Selenide.open;
import org.openqa.selenium.By;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Condition.text;

public class SearchTest {
    
 @Test
 public void validateSearchResults() {
  open("http://google.com/");
  $(By.name("q")).val("Mount Everest").pressEnter();
  $$("#ires .g").get(0).shouldHave(text("Mount Everest"));
 }
}

Creating Selenium tests using Selenide library easy. Download and add Selenide jar to your project and start creating the Selenium tests using Selenide functions.

Selenide web site: http://selenide.org/
Documentation: http://selenide.org/documentation.html
Quick Start: http://selenide.org/quick-start.html