Released Selenide 6.9.0

Released Selenide 6.9.0

Faking results
07.10.22


Yo Seleniders!

Let me break your doomscrolling with some good news.

We released Selenide 6.9.0! Basically, they pumped proxies and updated selenium.

Now Selenide proxy can mock server response

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.

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.

Test

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"));

Explanation

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();
}

Constraints

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

  • both site and mock run on https (not http)
  • service is alive and accessible from proxy

In sum

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.


Send authorization header only to specified domain

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:

  • if proxy is not enabled - by adding login/password to URL,
  • and if proxy is enabled - by adding http header 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.


Improved resolving proxy host name

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.18
  • ClientUtil.getConnectableAddress() -> 127.0.0.1

The 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.


Upgraded to Selenium 4.5.0

Notable changes:

  • dropped support for Opera browser
  • added alternative implementation of webdriver transport using JDK 11 HTTP client instead of Netty client
  • added checks for disabled in class Select (now you cannot select a disabled options anymore)
  • removed host name from Selenium exceptions

    arrr, I asked for this change since 2015!!!

See changelog and PR 1967.


Removed support for Opera browser

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.


Removed getAlias from reports

Thanks to Reserved Word for PR 1971.


Restored setting “connection timeout”

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.


Upgraded dependencies

  • LittleProxy from 2.0.12 to 2.0.13
  • slf4j from 2.0.2 to 2.0.3


Not only IT people suffer from constantly changing requirements!


Andrei Solntsev

selenide.org

07.10.22