theabrar / selenide

Concise UI Tests with Java!

Home Page:http://selenide.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Selenide = Concise 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.8 (Released 15.02.2014)

Non-backward compatible changes:
  • #96 Method ‘WebDriverRunner.setWebDriver()` does not close previous webdriver. You are responsible for webdriver lifecycle if you are using setWebDriver().

  • #63 Method ‘Condition.actualValue()` is optional (it’s not needed in most cases). It makes creating custom conditions even more easier.

Improvements:
  • #95 #79 - Selenide automatically takes screenshots on any test failure, not only if ‘$.shouldXXX` method fails.

  • Un-deprecated WebDriverProvider. It still can be useful.

  • #89 Do not exclude cglib dependency - it’s needed for taking screenshots with RemoteWebDriver

New features:
  • #93 User can get text and html of hidden element with new methods $.innerText() and $.innerHtml()

  • #77 Added methods back() and forward()

  • #71 Added method setSelected(boolean) for checking checkboxes

  • #86 - added methods $.is(condition), $.has(condition)

  • #62 Added composite condition AND

  • #94 SelenideElement implements WrapsElement

  • #88 Method $(WebElement parent, By selector, int index) made public. Added method $(WebElement parent, By selector).

  • #82 Added setting “selenide.browser” as a synonym for “browser”

  • Method executeJavaScript() can accept multiple arguments

2.7 (Released 31.12.2013)

  • #59 Automatically take screenshot on any failures. More exactly, when any of methods $.shouldXXX(condition) fails.

  • #59 When running tests in Jenkinks, Selenide shows public URL of screenshots (using BUILD_URL variable provided by Jenkins). It’s incredibly convenient because you can watch screenshots right in the Jenkins report.

  • #59 Added method getScreenshots() for retrieving all taken screenshots

  • Upgraded to Selenium 2.39.0

2.6.1 (Released 29.11.2013)

  • The most wanted feature is finally here! Added method $.download() for downloading file by “href” attribute!

2.6 (Released 26.11.2013)

  • Added method $.scrollTo()

2.5 (Released 11.11.2013)

  • Created annotations for TestNG that automatically create browser per test/per class

  • Added method $.attr(“name”) as a synonym for $.getAttribute(“name”).

  • Added method $.name() as a synonym for $.attr(“name”)

  • Better support for PhantomJS: ignore alerts and confirms

  • All webdrivers accept SSL certificates by default

  • Selenide clearly says if timeout is mistakenly given in seconds instead of milliseconds.

  • Condition constructor has been simplified (for easier creation of custom conditions)

  • Upgraded to Selenium 2.37.1

2.4 (Released 16.09.2013)

New features:
  • Allow multiple WebDriver instances in parallel threads inside single VM. This allows running parallel tests.

  • All text checks like ‘shouldHave(text(..))` ignore whitespaces!

  • Added method for adding WebDriverEventListeners

  • Added method ‘$.pressTab()`

  • CollectionCondition#texts matches substrings

  • Added method CollectionCondition#exactTexts

  • Maximize PhantomJS driver “window” by default

  • Better error messages for wrapped elements in PageObjects

Bugfixes:
  • Method “$$.findBy” waits until element matches the condition

  • Method $.append() first waits until element gets visible

Technical issues:
  • Updated to selenium-java:2.35.0

  • Moved implementation details from WebDriverRunner class to separate WebDriverThreadLocalContainer, ScreenShotLaboratory and Cleanup classes that are not static and can be overridden if needed.

  • WebDriverProvider is deprecated

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!

http://selenide.org

License:GNU Lesser General Public License v3.0