Changes in 2.13 and 2.14

Blog

Changes in 2.13 and 2.14

Fast setValue, image check, custom error messages, upgrade to Selenium 2.43.1

Hi Seleniders!

In September we released two versions of Selenide: 2.13 and 2.14. There is not so much new functions, but there is one new function that I want to discuss with you. Let’s start with it.

Fast method $.setValue

In Codeborne we analyzed performance of tests in few real projects and discovered that the most slow part of tests is filling text fields (not XPath search as many of us think). In other words, method $.setValue (or WebElement.sendKeys) is the bottleneck. It’s because Selenium emulates keypress of every single key with all related events: keyDown, keyUp etc. - thus making method sendKeys quite slow.

It’s possible to disable generating events, but in this case some functionality will be broken that uses these events: autocompletion, autosuggestions etc.

We have found a solution. Let’s Selenide have two separate methods: $.sendKeys and $.setValue. The first one will work like Selenium by default: slowly and with generating events. The second one will be fast, setting values to text fields using JavaScript. So test author can decide in which case which method is needed. In most cases the fast method $.setValue can be used, because there is not so much autocompletions comparing to “regular” text fields.

In our projects using of fast $.setValue method gave 10% of performance improvement.

NB! This is experimental feature. It can be enabled by flag -Dselenide.fastSetValue=true. By default it’s disabled, thus $.setValue works exactly the same as $.sendKeys.

Added method for checking images $("img").isImage()

Method $("img").isImage() returns true if the image has been correctly loaded. The method can be used only for <img> elements.

An example of usage can be found in test ImageTest.

NB! The functions does not work in HtmlUnit.

Added possibility to add descriptions to asserts (like in JUnit and TestNG asserts)

Now you can add a custom message to all should-methods:

$("#kpp").shouldBe("Private customers cannot have KPP", empty);

In case of test failure this description will be added to the error message:

Element should be empty {By.id: kpp} because Private customers cannot have KPP
Element: '<input id="kpp">012973891263</input>'
Screenshot: file:/Users/andrei/projects/selenide/build/reports/tests/integration/SelenideMethodsTest/waitUntilMethodMayContainOptionalMessageThatIsPartOfErrorMessage/1411898416054.0.png
Timeout: 4 s.

I am not sure that this feature is designed in the most convenient way. So, I am waiting for your suggestions. How could it be made more easy to use?

Maybe this API would be more convenient?

$("#kpp").shouldBe(empty.because("Private customers cannot have KPP"));

But in this case you will need to duplicate the description if you want to check multiple conditions in a line.

One more option:

$("#kpp").because("Private customers cannot have KPP").shouldBe(empty);

And finally, the “because” word is doubtful: in different situations you may find more appropriate to use other words.

What do you think?

Added wrappers be and have.

Now you have alternative way to write checks:

$("#username").should(have(text("Ivan")));
$("br").should(be(empty));

It may be useful when using Selenide with frameworks like EasyB that also use terms shouldBe or shouldHave for their needs.


Upgraded to Selenium 2.43.1.

Many testers have been waiting for this upgrade for a while. First of all, because of FireFox 32 support. And also because of new InternetExplorer driver.

We have not encountered any problems with the new Selenium 2.43.1.


And what’s up with you?


blog comments powered by Disqus

The project is maintained by