Good night!
Today we have a big major release Selenide 6.13.0.
- Added method
$.cached()
- Added http status for server response mock
- Added method
inNewBrowser
for running code in a new browser - Added method
$.doubleClick(options)
- Added condition
$.shouldHave(innerText())
- Added collection condition
$$.shouldHave(attributes(...))
- Clear error message in methods
$.select*()
- Fixed bug in
$$.subList()
- Updated dependencies
- News
Added method $.cached()
Sometimes you need to write quite complex code for finding an element.
And it might work slowly, especially if you find it from a long collection applying specific filtering.
Something like this:
ElementsCollection subscriptions = $$("div.subs-expands")
.filter(childExactText(
By.xpath(".//div[contains(@class,'data')]//div[contains(@class,'heading')]"),
orderNumber)
);
SelenideElement target = subscriptions
.filter(childAttributeValue(...))
.find(childExactText(....));
Every call to target
is apparently slow.
Now you can speed up such tests by caching the target
element:
SelenideElement target = subscriptions
.filter(..)
.find(..)
.cached();
Obviously, you can cache it only if you are sure that it’s not updated/reloaded during the test.
If it still gets reloaded, you will get the famous StaleElementReferenceException
.
See issue 2171, issue 1927 and PR 2189.
Added http status to server response mock
Selenide has method for mocking a server response:
getSelenideProxy().responseMocker().mockText("login-mock",
urlContains(POST, "/login"), () -> "{role: admin}");
It allowed to mock only response body, response status was always 200 (“OK”).
Now you can set another status too:
getSelenideProxy().responseMocker().mockText("login-mock",
urlContains(POST, "/login"), 403, () -> "{role: looser}");
See issue 2227 and PR 2234.
Added method inNewBrowser
for running a code snippet in a new browser
Sometimes you want to run a code block in a new browser.
Usually I say it’s a bad practice. Actions like data preparation etc. should not be performed via UI (we are testing UI -> we cannot trust UI). Instead, you should use some reliable way: using API, query to database etc.
Still, for this purpose we have method using
. But to use it, you
need to open your custom webdriver with some specific settings. But what if you don’t specific settings? What if you
need a standard webdriver with usual Selenide settings - just a new instance of browser?
Now you can use method inNewBrowser
for that:
open("https://site.com/login/as/user/bob");
inNewBrowser(() -> {
open("https://site.com/login/as/admin");
$(by("value", "bob")).find("[name=is_admin]").setEnabled();
});
$("h1").shouldHave(text("Hello, chat admin!"));
See issue 2213 and PR 2236.
Added method $.doubleClick(options)
We already had method $.doubleClick()
which could only click the center of given element.
Now it got an advanced bro with options
parameter. The options are the same as for usual $.click
method:
$(".btn").doubleClick(usingDefaultMethod());
$(".btn").doubleClick(usingJavaScript());
$(".btn").doubleClick(usingDefaultMethod().offset(66, 33));
$(".btn").doubleClick(usingJavaScript().offset(66, 33).withTimeout(ofSeconds(9)));
See issue 2133. Thanks to aakachurin for PR 2135.
Added condition $.shouldHave(innerText())
It allows to check texts of hidden elements.
Probably it’s a bad idea: if real users cannot see the element then you don’t need to test it.
But if you really want, you can now use condition innerText
:
$("#theHiddenElement")
.shouldHave(innerText("Can you see the hidden text?"));
// Usual $("#theHiddenElement").text() returns an empty string here: "";
See issue 2220 and PR 2223.
Added collection condition $$.shouldHave(attributes(...))
$$("#numbers option").shouldHave(attributes("value",
"one", "two", "three", "four", "five"));
See issue 2091. Thanks to Alexey Lakovych for PR 2091. See also PR 2230.
Added a clear error message in methods $.select*()
Selenide has convenient methods for working with dropdowns:
$("select#gender").selectOptionContainingText("Female");
Recently we changed their implementation to JavaScript - it’s faster and stable.
But it turned out that if you mistakenly call such a method for a non-<select>
, a very incomprehensible error took off:
$("ul").selectOptionContainingText("Kelly Snyder");
--> JavascriptException:
javascript error:
undefined is not iterable (cannot read property Symbol(Symbol.iterator))
Now this error message will be clear:
IllegalArgumentException: Cannot select option from a non-select element
See issue 2231 and PR 2233.
Fixed bug in method $$.subList()
As you know, Selenide has methods for checking the whole collection of elements with one line:
$$("#numbers").shouldHave(texts("One", "Two", "Three", "Four", "Five"));
Method $$
returns an object ElementsCollection
, which (unfortunately) is inherited from AbstractList<SelenideElement>
.
Thus, it inherits few unexpected methods that we initially didn’t think about.
One of such methods is subList
:
$$(".user").subList(1, 4).iterator();
This iterator returns two, not three elements. It truncates the last element. Oops… ¯\_(ツ)_/¯
Now this bug is fixed. Iterator will return all elements.
See issue 2239 and PR 2240.
Updated dependencies
- bump Selenium from 4.8.1 to 4.8.3 – see CHANGELOG
- bump LittleProxy from 2.0.16 to 2.0.17
- bump BrowserUpProxy from 2.2.8 to 2.2.9
- bump nettyVersion from 4.1.90.Final to 4.1.91.Final
News
Today we have few videos about Selenide
- ChatGPT: How to download file in Selenide
- Flaky tests
- Selenide channel by NaveenAutomationLabs
selenide.org
04.04.23