Selenium Flaky Test

Selenide – Answer to Selenium Flaky Tests

Table of Contents

[vc_row][vc_column][vc_column_text]

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

ย  ย  ย  ย }

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”-

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

[/vc_column_text][/vc_column][/vc_row]

Related Blogs