Skip to content

vmaxim/selenide

 
 

Repository files navigation

Selenide = Consice API for Selenium WebDriver

<img src=“https://travis-ci.org/codeborne/selenide.png” align=“right” />

What is Selenide?

Selenide is a library for easier using of Selenium WebDriver for automated tests in Java.

@Test
public void testLogin() {
  open("/login");
  $(By.name("user.name")).type("johny");
  $("#submit").click();
  $("#username").shouldHave(text("Hello, Johny!"));
}

Look here for detailed comparision of Selenide and Selenium WebDriver API.

Probably two the most noticeable methods are (inspired from jQuery):

$("#insuranceDetailsHeader") - returns WebElement matching given CSS selector
$$("#insuranceDetailsHeader tr td") - returns list of WebElements matching given CSS selector

How to start?

Just put selenide.jar to your project and import the following methods:

import static com.codeborne.selenide.Selenide.*

Look for Quick Start for details.

What benefits gives Selenide over plain Selenium?

Selenium is not a testing library, it just allows you to manipulate browser. Selenide provides a concise API for using Selenium WebDriver in UI tests:

  • Transparent WebDriver

  • Convenience methods

  • Ajax support

  • Screenshots

You can find more details below.

Transparent WebDriver

You don’t need to operate with WebDriver directly. Selenide for start and shut down the browser automatically whenevery it’s needed.

Convenience methods

Selenide provides concise API for that makes your tests shorter and more readable. Selenide has convenient methods for operating controls like textfield, radiobutton and selectbox.

@Test
public void canFillComplexForm() {
  open("/client/registration");
  $(By.name("user.name")).type("johny");
  selectRadio("user.gender", "male");
  $("#user.preferredLayout").selectOption("plain");
  $("#user.securityQuestion").selectOptionByText("What is my first car?");
}

Ajax support

When testing Ajax applications we often need to wait until some element changes its state. Selenide has built-in methods for waiting.

Any of the following methods waits until the described event happens. Default timeout is 4 seconds.

$("#topic").should(appear);
$("#topic").shouldBe(visible);

$("#topic").should(disappear);
$("h1").shouldHave(text("Hello"));
$(".message").shouldNotHave(text("Wait for loading..."));
$(".password").shouldNotHave(cssClass("errorField"));

etc.

Welcome to the Selenide Wiki for more details.

Resources

Changelog

2.4 (draft)

  • Added method ‘$.pressTab()`

  • Updated to selenium-java:2.34.0

2.3 (Released 9.07.2013)

New features:
  • Added possibility to mock ‘alert’ and ‘confirm’ modal dialogs

  • $$.should-methods can check multiple conditions

  • Collection methods can be chained:

$$("#multirowTable tr").shouldHave(size(2))
   .filterBy(text("Norris")).shouldHave(size(1));
Usability issues:
  • Readable error messages!

  • Save screenshots into subfolders: folder name is “com/package/TestClass/”, file name is “testName.png”/“testName.html”

  • Take screenshots for RemoteWebDriver too (using Augmenter)

  • Added javadoc for all SelenideElement methods

Technical issues:
  • Updated to selenium-java:2.33.0

  • Use “webdriver.quite()” instead of “webdriver.close()” to force closing ChromDriver and IE process

  • Fixed XPath for byText and withText

  • Removed using INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS for IE driver as it seems to be a bad practice

  • Removed “waitUntilAlertDisappears” because it does nothing useful.

  • Removed accident jcommander dependency

  • Build Selenide with Travis CI

2.2 (Released 31.05.2013)

  • Added method WebDriverRunner.setWebDriver(myDriver) to enable using custom WebDriver instance.

  • Added possibility to run HtmlUnit driver emulating different browsers: -Dbrowser=htmlunit:firefox, htmlunit:chrome etc.

  • Added condition $$().shouldBe(empty)

  • Method $$().shouldHave(size(n)) waits until collection gets expected size

  • Method $.setValue() triggers ‘change’ events in IE too

  • Updated to selenium-java:2.31.0

2.1 (Released 2.04.2013)

  • Changed license from GPL 1.0 to LGPL 3.0

  • Added support for TestNG

  • Added support for Selenium FluentWait API

  • Added support for Selenium Actions API

  • Added method $.findAll() returning list of matching elements.

  • Added method $$.findBy

  • Added method $$.shouldHave(texts(“A”, “B”, “C”)) for asserting texts of all matching elements

  • Added method $.data(attr) as a synonym for $.getAttribute(“data-” + attr)

  • Added conditions “name”, “not”, “type”, “id”: $(“#username”).shouldHave(name(“firstName”))

  • text and exactText conditions are case insensitive (reason - in css designer can apply text transformations and tests will fail)

  • introduced textCaseSensitive and exactTextCaseSensitive conditions

  • added open methods to Selenide class that return page object by class

  • Methods $.selectOption and $.selectOptionByValue trigger change event when possible.

  • Class ElementsCollection now contains list of SelenideElements (instead of WebElements).

  • Removed deprecated condition “haveText”. Use $.shouldHave(text(“john”)) instead.

  • Excluded org.webbit, netty, selenium-iphone-driver, selenium-safari-driver from Selenide dependencies to avoid loading too much useless stuff unless it’s really needed.

  • Now Condition implements Predicate<WebElement>. So it can be used for filtering collections.

2.0 (Released 3.03.2013)

  • Drop deprecated classes and methods (DOM, Navigation).

  • Updated to selenium-java:2.31.0

  • Selenide 2.0 is not backward-compatible with Selenide 1.+ Migration guide:

    • import static com.codeborne.selenide.WebDriverRunner.{browser,holdBrowserOpen,remote,startMaximized,reportsFolder}

      • replace by import static com.codeborne.selenide.Configuration.*

    • import static com.codeborne.selenide.DOM.defaultWaitingTimeout

      • replace by import static com.codeborne.selenide.Configuration.*

    • import static com.codeborne.selenide.DOM.*

      • replace by import static com.codeborne.selenide.Selenide.*

    • import static com.codeborne.selenide.Navigation.*

      • replace by import static com.codeborne.selenide.Selenide.open

    • import com.codeborne.selenide.ShouldableWebElement

      • replace by import com.codeborne.selenide.SelenideElement

1.11 (Released 28.02.2013)

  • Mark classes DOM and Navigation as deprecated (going to drop them in Selenide 2.0). The point is that now user only needs to import one class Selenide.

  • Added support for PhantomJS driver

  • Suppress HtmlUnit useless warnings

  • Method $.setValue() triggers onchange event with standard JavaScript instead of jQuery.

  • Condition “empty” checks for both text and value.

  • Added condition “exactText”.

  • Moved jquery-specific workarounds to a separate class JQuery

  • Added selector “by” as a synonym for “byAttribute”

  • Updated to selenium-java:2.30.0

1.10 (Released 11.02.2013)

  • Excluded HtmlUnit dependencies. These have too large size, and not everyone uses them.

  • Added method $$().shouldHaveSize(n)

  • Added methods $.exists(), isDisplayed(), $.text(), $.pressEnter(), $.followLink()

  • Added methods $.selectOption(), $.selectOptionByValue(), $.getSelectedValue(), $.getSelectedText()

  • Changed behaviour of methods byText() and withText(): now spaces in text are ignored

  • Added method $.val(String) as an alternative for $.setValue(String) (opa JQuery style!)

  • Added methods $.waitUntil() and $.waitWhile()

  • Added method Selectors.byAttribute(name, value)

  • Added Conditions appear, readonly and attribute(String)

  • Added method switchTo() for easier supporting frames

  • Method open() can use either absolute or relative URL

  • Added method toWebElement() returning the original WebElement

  • Added annotation BrowserStrategy

  • Methods assertElement, assertVisible, assertHidden in DOM are deprecated.

  • Renamed ShouldableWebElement to SelenideElement (shouldable still exists for compatibility)

  • $$ does not implement WebElement anymore - it was useless feature.

  • Now Selenide kills webdriver if it failed to close normally

  • Moved useful methods to class Selenide. Class DOM will be marked as deprecated in version 1.11 and dropped in 2.0

  • Updated to selenium-java:2.29.1

1.9 (Released 5.01.2013)

  • No need for waitFor/waitUntil methods. All the $(), getElement() and shouldXXX() methods wait for a few seconds until element appears or condition gets satisfied.

  • Added support for PageObjects - see method DOM.page(Class)

  • Added methods $().find() with index parameter

  • Added method $().setValue()

  • Added method DOM.getSelectedRadio()

  • Updated to selenium-java:2.26.0

  • Added initial support for phantomjs headless webkit browser (-Dbrowser=phantomjs)

  • Added support for custom WebDriver initialization by defining com.codeborne.selenide.WebDriverProvider implementation via “browser” system property.

1.8 (Released 29.11.2012)

  • Changed Selectors.byText() behaviour - now it matches THE WHOLE TEXT, not a substring.

  • A new method Selectors.withText() has been added that matches substring.

  • Added option “selenide.start-maximized” (true/false) instead of (deprecated) option “chrome.switches”.

  • Added support for By.CssSelector to method DOM.getJQuerySelector()

1.7 (Released 22.10.2012)

  • Added file uploading functionality (file is taken from test classpath)

  • Added methods $().should(), $().shouldHave, $().shouldBe(), $().shouldNot, $().shouldNotBe, $().find()

  • Added method $().toString() for logging WebElement in human-readable format.

  • Added wait-methods with CSS Selector parameter

  • Added method DOM.confirm() for clicking on confirmation dialog (alert)

  • Added support for Opera browser

  • Added method Navigation.refresh() for reloading current page

  • Added condition “present”, “notPresent”, “exist”.

  • Added selector “byText” and condition “matchesText” for matching elements by regex


Authors

Selenide was created by Codeborne, an software development company based in Tallinn, Estonia.

The main committers are:

License

LGPL 3.0

About

Concise UI Tests with Java!

Resources

License

Stars

Watchers

Forks

Packages

No packages published