Selenide – Answer to Selenium Flaky Tests

Selenium Flaky Test

Selenide – Answer to Selenium Flaky Tests

Background –

Today one of the best UI automation testing tool is Selenium but we automation engineers face one important challenge with it which is ‘synchronization’ issue. This issue leads to increase script maintenance effort as many a time tests gets failed without any actual bug in 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-webdriver API for example Protractor, webdriverJS, Selenide etc.

In this blog we will see how Selenide would be a better choice over Selenium when it comes to handle 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 primary reason of flaky tests.

 

Selenide Benefits –

Some of the Selenide benefits are –

  • Smart Wait – When testing Ajax applications we often need to wait until some element changes its state. Selenide has built-in methods for wait and has default timeout of 4 seconds which can be configured.
  • Transparent WebDriver – No need to operate with Webdriver directly, Selenide will launch and shutdown browser automatically whenever is needed.
  • Automated screenshots – On test failure Selenide will automatically captures screenshot.
  • 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 make test shorter and more reliable.

 

Steps to Create Sample Test Script

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

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

  • If you are dealing with 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 TestNg library in your project
  • Create one class in your project and add below code to run sample test

         //Below import code to be added above class name

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

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

        //Below method to be added inside your class

        @Test

        public void googleSearch()

        {

           open(“https://www.google.com”);

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

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

       }

Share this post