Released Selenide 5.0.0

Blog

Released Selenide 5.0.0

We are 7 years old!

It finally happened! We released a major Selenide version 5.0.0

The biggest change in Selenide 5.0.0 is a global refactoring. This is internal change. It should not (almost) affect you. For those who are interested - I am going to share refactoring details in a separate post.

What changes are waiting you in Selenide 5.0.0?

You can open two browsers in test

First of all: don’t use this feature!
In most cases, it’s a bad idea to open two or three browsers in a test.

Typically people want it to test multi-user scenarios. Something like that:

  1. In one browser, open an admin panel and modify some setting
  2. In other browser, open a user page and verify that the setting has been applied correctly.

The right solution in this case is to test admin panel separately, and user page separately. Don’t mix different tests into one. When you need to setup environment for test (incl. changing any settings or emulating input from other user), you can use whatever tools (rest call, insert into database etc) but not through UI. You are testing UI - it means that you are not allowed to trust UI.

If you still want to use bad practice, the API looks like this:

SelenideDriver browser1 = new SelenideDriver();
SelenideDriver browser2 = new SelenideDriver();

browser1.open("https://google.com");
browser1.open("http://yandex.ru");

browser1.$(h1).shouldHave(text("Google"));
browser2.$(h1).shouldHave(text("Yandeks"));

See actual example in Selenide own tests

See issue 354 and PR 801

My thanks go to people who played an important role in this long-running refactoring:

NB! Old good open, $, $$ still work, and I still recommend to use them. They do use new SelenideDriver() inside, but they correctly store and destroy it. You just don’t need to reinvent the wheel and solve the same problems again and again.

Let me repeat myself: two browsers in one test is most probably a BAD PRACTICE!


Now Selenide uses Chrome by default

Many years ago, we chose Firefox as a default browser because it was the only browser which did not require installation of a webdriver binary. Nowadays this argument is not valid because 1) Firefox now also requires installation of geckodriver, and 2) Selenide can install webdrivers automatically.

From our experience, Chrome is faster and more stable. That’s why now is Chrome Era.

See issue 811 – thanks to Aliaksandr Rasolka for PR 812


Selenide does not maximize browser by default

At the beginning it seemed to be a good idea to open browser to the full screen size. It should make tests stable: more elements fit to the screen. Many people still think this way.

Actually it makes tests flaky because tests result depends on screen size which is a random uncontrollable variable. Our new recommendation to set browser size explicitly to the minimal size supported by your application.

Selenide 5.0.0 by default sets browsers size to 1366x768 because it is worlds’ most popular resolution by the moment. As usually, you can redefine it as any other setting.

See issue 810 – thanks to Aliaksandr Rasolka for PR 812


Selenide doesn’t open a browser automatically

Methods $ and $$ now throw an exception if browser is not opened yet (or is already closed). The right way is to open a browser first (by calling open(url)) and then search elements ($, $$ etc).

Before this release, methods $ and $$ opened a new browser automatically if it was not open yet. This behaviour could be unexpected sometimes. For example, people got Firefox when they expected Chrome. Or got two browsers when they expected one. Yes, it was a bug in tests, but now Selenide helps to find it faster.

There are known cases when tests started failing after upgrade to Selenide 5.0.0 for two reasons:

  1. Page object fields were declared static, and browser was closed after every test. Static fields were initialized only once. Every following test didn’t re-initialize them, but got from a previous test SelenideElement instances containing a reference to (already closed) webdriver. Solution: make page object fields non-static. Static is evil.
  2. Test class fields (in case of TestNG) were initialized in field declaration, not in setUp method. That’s why I love JUnit. Happy JUnit users can afford such a luxury:
    public class MyTest {
      SelenideElement header = $("h1");
    }
    

    But poor TestNG users are forced to move initialization to @Before-like methods:

    public class MyTest {
      SelenideElement header;
      @BeforeEach
      public void setUp() {
        header = $("h1");
      }
    }
    

    Looks ugly, right? My advice: forget TestNG. JUnit rules.

See issue 809


Cleaned up unused settings and features

See issue 806 – thanks to Aliaksandr Rasolka for PR 812


Removed junit5-api api dependency

Selenide transitively pulled junit5-api dependency to your project, even if you don’t use JUnit5. Apparently you don’t want it. Now it doesn’t.

If you use JUnit5 and some classes disappeared from classpath after upgrade, you will need to add JUnit5 dependency explicitly: "org.junit.jupiter:junit-jupiter-api:5.3.1".


And minor changes:

  • Classes AssertionMode, SelectorMode, FileDownloadMode moved from class Configuration to package com.codeborne.selenide.
  • Now Selenide throws ElementIsNotClickableException instead of ElementNotFoundException (if element could not be clicked because it was covered by another element).
  • Selenide throws error if Configuration.fileDownload == PROXY but Configuration.proxyEnabled == false. You will need to explicitly set Configuration.proxyEnabled=true to download files via proxy.
  • 817 fix “FirefoxDriverFactory overwrites Firefox profile provided by Configuration” – thanks to Boris Osipov for PR 821
  • bugfix: method Selenide.download() should not fail if there is no opened browser yet
  • 825 Upgraded WebDriverManager to 3.0.0 (again)
  • 825 Created a workaround for WebDriverManager, so that it doesn’t call github api too often (getting 403 error)
  • 832 Added support for screenshots outside of “user.dir” in CI server – thanks Alex Yu


Technical changes (which probably will not affect you)

  • Upgraded to htmlunitdriver 2.33.0
  • Moved constants IE, FIREFOX etc. from class WebDriverRunner to its parent class Browsers
  • Moved classes Selenide, WebDriverRunner, Configuration to subfolder statics.
  • Moved default settings initialisation from Configuration to SelenideConfig.
  • when waiting for a condition, catch explicitly only needed exceptions instead of Throwable which is too generic. It does not make sense to wait for 4 seconds in case of IllegalStateException, FileNotFoundException etc.


News

We get 7 years old!

Time does go on. Could we imagine that? Selenide gets 7 at October, 25. Now it’s funny to look at the first commits:


How your upgrade went?

Share your experience, register github issues, discuss your problems in slack and gitter.


Andrei Solntsev

selenide.org

blog comments powered by Disqus

The project is maintained by