Changes in Selenide 2.16 and 2.17

Changes in Selenide 2.16 and 2.17

Profiler, Soft asserts and few improvements
05.05.15

Hi Seleniders!

We haven’t written to blog for a while. There have been released 3 new versions of Selenide during this period.

Let me describe changes in versions 2.16 and 2.17

Soft asserts

We finally added SoftAsserts to Selenide. I am still not sure that it’s a good idea, but it was asked a lot. :)

In SoftAssert mode your tests do not fail immediately, but all the checks like $.shouldHave(text("xxx")) will collect errors and report all them at once in the end of test. It allows you to collect all the fails, fix them all and re-run test only once. It could be useful if cost of running tests is too big for you.

To enable Soft asserts in JUnit (see documentation):

public class SoftAssertJUnitTest {
  @Rule public SoftAsserts softAsserts = new SoftAsserts();

To enable Soft asserts in TestNG (see. documentation):

@Listeners(SoftAsserts.class)
public class SoftAssertTestNGTest {

And here is the result.

In the end of test, it shows all the collected errors:

java.lang.AssertionError: Test userCanUseSoftAssertWithJUnit(integration.SoftAssertJUnitTest) failed.
3 checks failed

FAIL #1: Element should have attribute value=777 {#radioButtons input}
Element: '<input name="me" type="radio" value="master"></input>'
Screenshot: file:/Users/andrei/projects/selenide/build/reports/tests/integration/SoftAssertJUnitTest/userCanUseSoftAssertWithJUnit/1425503251321.0.png
Timeout: 0 ms.

FAIL #2: Element not found {#radioButtons select}
Expected: visible
Screenshot: file:/Users/andrei/projects/selenide/build/reports/tests/integration/SoftAssertJUnitTest/userCanUseSoftAssertWithJUnit/1425503252361.1.png
Timeout: 0 ms.
Caused by: NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#radioButtons select"}

FAIL #3: Element not found {#xxx}
Expected: visible
Screenshot: file:/Users/andrei/projects/selenide/build/reports/tests/integration/SoftAssertJUnitTest/userCanUseSoftAssertWithJUnit/1425503252697.2.png
Timeout: 0 ms.
Caused by: NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#xxx"}

    at org.junit.Assert.fail(Assert.java:88)
    at com.codeborne.selenide.junit.SoftAsserts.after(SoftAsserts.java:54)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)
        ....
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Profiler

Now Selenide can create a report about all actions performed during the test. The report includes execution time of every action in milliseconds. It allows you better understand what happens, and what steps take too much time.

Here is an example report:

+--------------------+--------------------------------------------+----------+----------+
|Element             |Subject                                     |Status    |ms.       |
+--------------------+--------------------------------------------+----------+----------+
|open                |http://0.0.0.0:23762/page_jquery.html       |PASSED    |131       |
|#multirowTable      |find elements(by text: Chack)               |PASSED    |100       |
|#multirowTable tr   |find elements(by text: Chack)               |PASSED    |100       |
|#multirowTable tr   |find(by text: Chack)                        |PASSED    |0         |
|by text: Chack      |get attribute(class)                        |PASSED    |139       |
+--------------------+--------------------------------------------+----------+----------+

To enable this report, you need to add the following rule to your tests:

@Rule
public TestRule prettyReportCreator = new PrettyReportCreator();

This is an experimental functionality. Only JUnit is supported by now.

Please try it and give your feedback.

Thanks to kumarunster for this pull request!


Fixed function $.closest()

Now the search for parent element by CSS class works correctly:

  $(By.name("firstName")).closest(".active");


Method $.toString() now logs all attributes

Method $.toString() logged only defined set of attributes: id, class, type etc. The problem is that Selenium webdriver doesn’t provide API for listing all attributes.

But we found a way! Now method $.toString() prints out all attributes (using JavaScript hack):

      assertEquals("<div class=\"invisible-with-multiple-attributes\" " +
          "data-animal-id=\"111\" id=\"gopher\" ng-class=\"widget\" ng-click=\"none\" " +
          "onchange=\"console.log(this);\" onclick=\"void(0);\" placeholder=\"Animal\" " +
          "displayed:false></div>", $("#gopher").toString());

Upgraded to Selenium 2.45.0.

Please note that this release disables native events in Firefox.


And what’s up with you?


05.05.15