Released Selenide 5.16.0

Blog

Released Selenide 5.16.0

Plugins and error messages

Good night!

We released Selenide 5.16.0.

Plugin system

One of the major plans for this year in Selenide roadmap was to create a plugins system. It took time, but now

the day has come!

Currently there are two Selenide plugins available:

We will describe them in following posts.

Apparently, we are going to create next plugins for Allure, JUnit, TestNG, AShot.
Please share your ideas too!

See issue #1051 and PR #1264, PR 1317 and PR 1321.

Error messages

One of core Selenide functions is forming error messages in case of test failures.
Sometimes these error messages can also be incomplete or unclear, especially in some corner cases.
In this release, we did a whole bunch of fixes for error messages.

Improved error messages for AND and NOT checks

A canonical way to perform a negative check in Selenide is method shouldNotHave.
And if you want to perform multiple checks - just write them in a line using commas:

  $("#username").shouldNotHave(text("admin"));
  $("#username").shouldHave(text("____"), attribute("data-masked"));

But there are alternative methods Condition.not and Condition.and for specific cases. For example, you can declare composite conditions, thus creating DSL for your tests.

  public class MyConditions {
    private static final Condition NONADMIN = not(text("admin"));
    private static final Condition MASKED = and("MASKED", text("___"), attribute("data-masked"));
  }

  public class MyTest {
    $("#username").shouldBe(MASKED);
    $("#username").shouldBe(NONADMIN);
  }

We found that these methods showed incomplete information in test reports:

  | #username |should be(MASKED)                  |PASS |
  | #username |should have(not text)              |PASS |

The problem is that we don’t see the expected text (“admin”) and other conditions.

Now we fixed this problem, and you will see the expected text:

  | #username |should be(MASKED: text '___' and attribute data-masked)      |PASS |
  | #username |should have(not text 'admin')                                |PASS |

Thanks to Pavel Fokin for PR 1306 and PR 1306.


Added information about parents

In Selenide, you can find elements inside other elements. Like this:

  $("#user-table").$("thead").$("trrrr-chah-chah").shouldHave(text("Age"));

But if such a check failed, you could see only the child element’s locator in the error message:

  Element not found {trrrr-chah-chah}

Now we added information about its parents too:

  Element not found {#user-table/thead/trrrr-chah-chah}

Thanks to Petro Ovcharenko for PR 1312.



We added actual texts for ownText and exactOwnText checks

As you remember, in Selenide 5.15.0 we added checks ownText and exactOwnText:

  $("#child_div1").shouldHave(ownText("Sonar"));

But if such check failed, you didn’t see the actual “own text”, but only the whole element’s text with its children:

  Element should have own text 'Sonar' {#child_div1}
  Element: '<div id="child_div1">Son</div>'

Now we added “Actual value” line with element’s own text:

  Element should have own text 'Sonar' {#child_div1}
  Element: '<div id="child_div1">Son</div>'
  Actual value: Son

See issue 1261 and PR 1294.



We throw the right exception if you try to upload a wrong file

If you tried to upload a missing file:

  $("input[type='file']").uploadFile(new File("/foo/bar/xyz.pdf"));

you got an incorrect exception:

  Element not found {input[type='file']}
  ...
  Caused by: InvalidArgumentException: invalid argument: File not found : /foo/bar/xyz.pdf

Not a big deal, but sometimes is might be misleading.

Now we throw the right exception:

  InvalidArgumentException: invalid argument: File not found : /foo/bar/xyz.pdf

See issue 987 and PR 1301.


The root problem that Selenium doesn’t have dedicated exception classes for all possible corner cases. See issues 1293 for example. Also some webdriver implementations can throw non-reasonable exceptions - for example, IEDriver threw Throwable instead of ElementNotFound when I checked it last time.

That’s why we decided to use a conservative strategy in Selenide: if we couldn’t detect the problem precisely, we assume that element not found, and you will see the real problem in the “caused by” block anyway.



Show ClickOptions in the report

As you remember, in Selenide 5.15.0 we added generic methods for clicking with all kinds of options:

  $("#page").click(usingJavaScript().offset(123, 222));

And again, we found that such a line was not readably in report:

  | #page               |click(com.codeborne.selenide.ClickOptions@33617539)         |PASS |

Now we made it readable:

  | #page               |click(method: JS, offsetX: 123, offsetY: 222)               |PASS |

See issue 1302 and PR 1303.


Other changes

We added check $$.shouldHave(exactTextsCaseSensitiveInAnyOrder(...))

There are multiple collection checks in Selenide:

  $$(".employee").shouldHave(texts("john", "bob", "katie"));            // case-insensitive, substring
  $$(".employee").shouldHave(textsInAnyOrder("john", "katie", "bob"));  // case-insensitive, substring, any order
  $$(".employee").shouldHave(exactTexts("john", "bob", "katie"));       // case-insensitive, full string match

Now we got one more:

  // case-sensitive, full string match, any order
  $$(".employee").shouldHave(exactTextsCaseSensitiveInAnyOrder("John", "Bob", "Katie"));

Thanks to Vitali Plagov and PR 1286.


We support hrefs with special symbols

As you remember, in Selenide 5.15.0 we added check href.
But it didn’t support href values with escaped characters, like in the second line:

  $("a").shouldHave(href("/foo/bar/details.html"));    // works
  $("a").shouldHave(href("/files/some%20file.pdf"));   // fails

Now it’s fixed.

See issue 1298.
Thanks to rerednaw and PR 1299.


Allow Chrome to download multiple files

There are such tricky links that cause downloading of two or more files.
We found that Chrome shows a dialog “Are you sure you want all these files?” in this case. And this dialog blocks your test until user clicks “ok”.

The worst thing about this problem is that it is very difficult to repeat it by hand: the browser shows the dialog only the first time, so when running locally, most likely you will not see it, and the test will be green.

To fix this problem, we added an option profile.default_content_setting_values.automatic_downloads=1 when running Chrome browser. This option allows Chrome to download multiple files without any dialogs.

See issue 1307.
Thanks to Alexei Vinogradov and PR 1308.


We allow downloading files with slashes in name

Until now, method download didn’t allow a file which has slash in name:

  File report = $("#report").download();
  
  --> IllegalArgumentException("File name cannot contain slash: 11/08/2020_-_day_transactions.pdf")

It seemed logical to us, because no file system allows creating of such files.
But it turned out that sometimes the slash is quite logical - for example, as a separator in dates. And browsers can download such files. For example, Chrome simply replaces the slashes with underscores.

Now Selenide also does it.

See issue 1322 and PR 1323.


Fixed Guava version 30.0-jre

Oh, Guava!

In Selenide own code, Guava is not used. We don’t directly need it.
But many other libraries still use different versions of Guava: Selenium, LittleProxy, BrowserUpProxy, Checkstyle…

Selenide users periodically experienced problems when Maven or Gradle fetched transitively a wrong Guava version, and Selenide didn’t properly work.
We are tired of it. Now Selenide explicitly declares a dependency on latest Guava version 30.0-jre. We hope it will fix all those endless dependency issues.


We migrated to Github Actions

As in any decent project, Selenide has its own set of automated tests (unit and integration), and they run automatically for all branches on a CI server. We used to use Travis CI which provides a free service for open-source projects. Thank them very much for the years of joint work. :)

But this year, Github started their own CI service “Github actions”. It seemed reasonable to migrate to it.

Now all Selenide builds can be found right on github.

Thanks to Boris Osipov and PR 1319.


The ned

It was a long text, but you mastered it. All good fellows!

As usually, update, try, experiment and feel free to report problems and share ideas.


Andrei Solntsev

selenide.org

blog comments powered by Disqus

The project is maintained by