Changes in Selenide 2.20

Changes in Selenide 2.20

Protection against webdriver hanging and standard logging

Hi all!

We have released Selenide 2.20. Let me tell you what’s new there.

Protection against webdriver hanging

Sometimes we experience problems with webdriver: it hangs when trying to open or close browser. This thread just remains endlessly in the same state: “Forwarding newSession on session null to remote”. I guess it’s a bug in webdriver.

We added protection against this problem in Selenide 2.20.

Now Selenide runs opening/closing browser in a separate thread and limits its time. By default opening browser cannot take more than 15 seconds, and closing browser cannot take more than 5 seconds. In case of failure, Selenide re-tries (up to 3 times) and only then throws an exception.

Thank you @admizh for this suggestion!

See Issue 199 and Issue 204

Selenide now uses java.util.logging for logging

Up to now, Selenide used System.out and System.err for printing its messages.

Actually I think that this is good enough for testing. It’s simple and reliable.

But people often use different libraries/frameworks, and want to use common logging mechanism across all tests. That’s why we migrated Selenide to use “standard” mechanism java.util.logging (JUL).

To be honest, I don’t like jul. I think that log4j or slf4j is much better. But Selenium already uses JUL, so it seemed reasonable to use JUL also in Selenide instead of adding new dependencies.

Good news is that you don’t need to do anything to use the new logging. It works automatically. It prints logs to standard system output (aka console) by default. But it’s not beautiful:

Jul 25, 2015 10:48:21 PM com.codeborne.selenide.impl.WebDriverThreadLocalContainer createDriver
INFO: Create webdriver: 1 -> FirefoxDriver: firefox on MAC (3e54e3de-b212-2a45-93ad-712aae6ee853)

To make it more readable (if you haven’t yet configured JUL in your project), you can add the following line in the beginning of your tests:

System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tT %4$s %5$s%6$s%n");

If you prefer slf4j, just add dependency org.slf4j:jul-to-slf4j:1.7.12 to your project and these lines in the beginning of your tests:


Now Selenide logs will look better:

22:48:15 INFO  INFO: Create webdriver: 1 -> FirefoxDriver: firefox on MAC (3e54e3de-b212-2a45-93ad-712aae6ee853)

See Issue 195

Fixed Cookies usage when downloading file

Thank you @philipp-kolesnikov for this pull request!

Added support for element collections to Page Objects

Now you can declare an elements collection in your page object:

public class SearchResultsPage {
  @FindBy(css = "#ires li.g")
  private ElementsCollection results;

See Issue 186

Thank you @rishaselfing for the suggestion!

P.S. Let me remind that it’s probably simpler to write page objects without annotations:

public class SearchResultsPage {
  private ElementsCollection results = $$("#ires li.g");

Method $(“select”).shouldHave(text(“…”)) now checks the selected option

Up to now, the $("select").shouldHave(text("...")) check was quite useless, because it checked texts of all <option> elements, not only selected ones. Now it checks only texts of selected option(s).

And method $("select").getText() returns only texts of selected option(s).

See Issue 134

Added method for taking screenshot of one element or region

Sometimes screenshots appear to be useless. When page is too big, the required element does not always fit to the screenshot. In this case you can find useful the new function for taking screenshot of one element.

It’s so easy to use:

    File screenshot = $("#some-div").screenshot();

See Issue 66

All methods $(String, ...) made deprecated

Please be sure that you don’t use deprecated methods. We are going to remove then in one of next Selenide versions (probably in Selenide 3.0).

Now there is a better way to add explanation to your checks using because function:

$("h1").shouldHave(text("Some wrong test").because("it's wrong text"));
$("h1").waitUntil(hidden.because("it's sensitive information"), 100);

Removed cglib-nodep from Selenide dependencies

We found what cglib-nodep dependency is too old and useless. And it can sometimes conflict with other project dependencies. It seems that it doesn’t support Java 8 and haven’t been updated for 5 years.

So we removed cglib-nodep from Selenide dependencies.

If you still need cglib-nodep for some reason, just add dependency cglib:cglib-nodep:jar:3.1 to your project.

I need your help!

Please vote for my submission to SeleniumConf 2015 conference here!

And what’s up with you?

Andrei Solntsev