Let me break your doomscrolling with some good news.
We released Selenide 6.9.0! Basically, they pumped proxies and updated selenium.
As you know, Selenide can run its own embedded proxy server. It listens requests between browser and other world. We mostly used it in read-only mode (logging, downloading files). But now you can also change the traffic. Namely, you can replace server response. It may be useful to mock the response of some service.
Let’s look at some simple abstract example.
Let’s say you’re testing a site showing the results of a referendum. It’s a html page on address, say, https://referendum.ru, which calls service https://cik.ru to fetch json with voting results.
Since the results are not known in advance, but the site needs to be tested here and now, we want to check how it will look in different corner cases.
open();
getSelenideProxy().responseMocker().mockText("cik-mock",
urlStartsWith(GET, "https://cik.ru/api/gov/no/referendum"),
() -> "{votes: 2133326, for: 99.23, against: 0.77}");
open("https://referendum.ru");
$("#votesFor").shouldHave(text("99.23%"));
$("#h3").shouldHave(text("not only satisfy but also surprised"));
Look at the first parameter cik-mock. This is name of the mock.
You can use it later to cancel the mock (to avoid occasional effects on the following tests):
@AfterEach
void tearDown() {
getSelenideProxy().responseMocker().reset("cik-mock");
}
Or you can just cancel all the mocks for safety:
@AfterEach
void tearDown() {
getSelenideProxy().responseMocker().resetAll();
}
If you site and mocked service run on same domain, there is no constraints.
But if the site calls a service on another domain, mock will work only if
Using mocks is a powerful technique letting us verify different corner cases that are hard or even impossible to reproduce otherwise
(“146% votes for”, “no one showed up to vote”, “service is unavailable” etc.)
Do not be shy about your desire to correct, clean up, add something. It will work as you want.
See issue 1254 and PR 1978.
Some site you need to test are protected by BasicAuth. Selenide allows to open such sites with overloaded method open:
open("https://referendum.ru/admin", BASIC,
new BasicAuthCredentials("saver-of-the-world", "gojda!!!"));
This method can overcome BasicAuth:
Authorization to requests from browser to server.But here’s the problem. Recently we realized that Selenide sent Authorization header not only to the app under test, but also to all other services (e.g. S3 or Google authentication).
Now Selenide will send Authorization only to needed domain. But you will also need to specify the domain in constructor:
open("https://referendum.ru/admin", BASIC,
new BasicAuthCredentials("referendum.ru", "saver-of-the-world", "gojda!!!"));
See issue 1974 and PR 1975.
When you enable proxy in Selenide (e.g. by setting Configuration.proxyEnabled = true), it will run embedded proxy server on random port. And open a browser with instructions to use proxy HOST:PORT. The question is, which HOST to use?
Until now, we used expression ClientUtil.getConnectableAddress() to resolve the host name (it’s default behaviour of BrowserUpProxy). But from this release, we will use new NetworkUtils().getNonLoopbackAddressOfThisMachine() (it’s Selenium internal method). I’m too lazy to figure out what their specifics are, but they may return different results on my machine:
new NetworkUtils().getNonLoopbackAddressOfThisMachine() -> 192.168.0.18ClientUtil.getConnectableAddress() -> 127.0.0.1The first one is definitely better when the browser runs on different machine or in a container. The proxy will just not be accessible by address 127.0.0.1 from other machine.
If none expression works properly for you, you can always specify host name explicitly by setting
Configuration.proxyHost = "my.comp.eu";
See PR 1970.
Notable changes:
disabled in class Select (now you cannot select a disabled options anymore)arrr, I asked for this change since 2015!!!
As a consequence of the Selenium upgrade, we also had to drop Opera support. I guess the reason is that Opera uses Chrome engine and is not very different from Chrome. If you still need to run tests in Opera - it’s possible, just use chromedriver.
See PR 1967.
getAlias from reportsThanks to Reserved Word for PR 1971.
Few people need this, so feel free to skip it.
We used to have two settings for the webdriver http client: “connection timeout” and “read timeout”. The first one had to be removed when upgrading to Selenium 4, because it was cut out there. Now it was resuscitated in Selenium 4.5.0, well, so we resuscitated also.
See PR 1977.
Not only IT people suffer from constantly changing requirements!