Selenide – Answer to Selenium Flaky Tests

Back to Blog
Selenium Flaky Test

Selenide – Answer to Selenium Flaky Tests

Background

Today one of the best UI automation testing tools is Selenium but we automation engineers face one important challenge with it which is the ‘synchronization’ issue. This issue leads to increase script maintenance effort as many a time tests get failed without any actual bug in the application. This can happen due to a lot of different reasons for example Ajax is used to dynamically update the application page or due to the ‘async’ activities of the front-end framework like ‘Angular/React’ etc.

Recently a lot of new implementations have come in to address different challenges that we face with selenium-web driver API for example Protractor, web drivers, Selenide, etc.

In this blog, we will see how Selenide would be a better choice over Selenium when it comes to handling synchronization issues.

Selenide Introduction

Selenide is an automated testing tool developed on top of Selenium-Webdriver. It better handles dynamics content, Ajax, javascript, timeouts, etc. which are the primary reasons for flaky tests.

Selenide Benefits

  • Smart Wait – When testing Ajax applications we often need to wait until some element changes its state. Selenide has built-in methods for waiting and has a default timeout of 4 seconds which can be configured.
  • Transparent WebDriver – No need to operate with Webdriver directly, Selenide will launch and shut down the browser automatically whenever needed.
  • Automated screenshots – On test failure Selenide will automatically capture screenshots.
  • Better Error Messages – Selenide error messages are more detailed and understandable.
  • Ajax Support – When testing Ajax applications we often need to wait until some element changes its state. Selenide has built-in methods for waiting.
  • Convenience methods – It provides concise API which makes tests shorter and more reliable.

Steps to Create Sample Test Script

  • Create a Java project or Maven project and accordingly use the below configuration –
  • You can download and add selenide.jar to your project, here is the download link 

           https://mvnrepository.com/artifact/com.codeborne/selenide/4.2.1 

  • If you are dealing with a maven project, then you can add dependency in pom.xml
<dependency>

            <groupId>com.codeborne</groupId>

           <artifactId>selenide</artifactId>

           <version>5.2.8</version>

          <scope>test</scope>

        </dependency>
  • Add the TestNg library to your project
  • Create one class in your project and add the below code to run a sample test

         //Below import code to be added above the class name

 import static com.codeborne.selenide.Selenide.*;

        import static com.codeborne.selenide.Condition.*;

        //Below method to be added to your class

        @Test

        public void googleSearch()

        {

           open("https://www.google.com");

          $(By.name(“q”)).val(“testing”);

         $(By.name(“btnK”)).click();

       }

—————————————————————————————————————————————————-

Our Engineers have written some other detailed articles on selenium you might find of interest:

Share this post

Back to Blog