Automated regression testing in Java with Selenium IDE, Selenium WebDriver and Selenide

After an update it is often desirable to check whether existing features of an application are still working correctly. This process is called ‘regression testing’. Several tools can be used to automate this process. This blog will focus on Selenium IDE, Selenium WebDriver and Selenide which can be used for front-end/ black-box testing of browserapplications.

Selenium IDE

Selenium IDE is a Firefox plugin which can be used to record interactions with a web application. After installation an icon will appear in your taskbar:
Clicking this icon will open Selenium IDE:
The selected red button on the right hand corner indicates that the program is recording. At the top the base URL of the application which you wish to test is shown. When interacting with the website, commands are added to the table:Selenium3
You can replay the recording by clicking the green arrow in the left:
However, sometimes Selenium IDE does not recognize its own code when replaying a test case. In that case, the specific line which is the cause of the problem will turn red:Selenium5
This issue can be solved by selecting the specific red line and choosing a different type of target:
Unfortunately, I have encountered several instances in which none of the available options solved this issue.

However, Selenium IDE does have the option to convert the code to several other formats, including Java. In order to make this possible, it is necessary to click options> options> and check the ‘enable experimental features’ option. After this, one can select the desired format under options>format. Choosing the option ‘Java/Junit4/WebDriver’ will result in the following source code:Selenium7

Selenium WebDriver

The code which is generated by Selenium IDE is based on the Selenium WebDriver. In order to use this generated code in your preferred IDE, it is required to download the .jar files of the Selenium Standalone Server and the Selenium Client & WebDriver and to add them to your path (or: copy them to your project and selecting ‘build path’). Then, the code can be copied into a new class. The names of the class and the package should be updated. The unused methods at the bottom of the script and the unused variables at the top may be deleted:

import static;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestWebdriver {
  private WebDriver driver;
  private String baseUrl;
  private StringBuffer verificationErrors = new StringBuffer();

  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

  public void testUntitled() throws Exception {
    driver.get(baseUrl + "/?gfe_rd=cr&ei=HGF6Vqn1CoqX-AawvpzgCA&gws_rd=ssl");
    driver.findElement(By.linkText("Cheese - Wikipedia")).click();

  public void tearDown() throws Exception {
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {

After this, the code can be run as a regular JUnit test (which is beyond the scope of this blog). By default, WebDriver uses Firefox to execute the code. However, one can download plugins for other browsers as well.

Like Selenium IDE, Selenium WebDriver might throw errors stating that it was unable to locate a specific element, e.g. the element on line 27 of the above code. In my experience, xpaths are most reliable when locating elements. Firebug can be used to find the xpath of a specific element. So, line 27 of the above code should be changed to:


In addition, dynamic pages which use scripts to show, hide or change the state of certain fields, may raise errors when the script has not finished yet and the selected element is not yet present, visible or clickable. One way to solve this is to set an implicit waiting time (as in done in the generated script above on line 19). This implies that when a certain element is not found, the driver waits for the set amount of time. When this amount of time has passed, it will search again. Only when the element is still not visible, the program will throw an exception. A downside of this method is that it might unnecessarily slow down your application, since it might take less time for the element to show up than the set amount of time. Also, after having set this time, it will be used during the entire lifetime of the driver-object.

Another common way to handle this issue is to set an explicit waiting time. This means that you define a maximum of time to wait for a certain condition to be met:

WebDriverWait myWait = new WebDriverWait(driver, 45); // amount of seconds
		  ExpectedCondition<Boolean> conditionToCheck = new ExpectedCondition<Boolean>()
		      public Boolean apply(WebDriver input) {
		    	  WebElement element = input.findElement(By.xpath("/html/body/div/div[5]/div[4]/div[7]/div[1]/div[3]/div/div[2]/div[2]/div/div/ol/div[1]/div[1]/div/h3/a")); // element
		    	boolean displayed = element.isDisplayed(); // condition
		          return (displayed);

However, the downside is that this will diminish the simplicity and readability of your code.

It is also possible to call Threat.sleep(amountOfMilliseconds), but this should be avoided as much as possible, since it will also severely slow down the program.


Another way to deal with waitingtime is to use Selenide, which is built on top of Selenium WebDriver. The .jar file can be downloaded or you can add the dependency to your Maven project. In addition, you should add the following imports:

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

Then, lines 25-27 of the generated code can be replaced with:

WebDriverRunner.setWebDriver(driver);// set the Selenide driver
$("lst-ib")).shouldBe(present, visible).setValue("cheese");
$(By.xpath("/html/body/div/div[5]/div[4]/div[7]/div[1]/div[3]/div/div[2]/div[2]/div/div/ol/div[1]/div[1]/div/h3/a")).shouldBe(present, visible).click(); 

Now, the programm will continue as soon as shouldBe(condition(s)) is met. By default, Selenide waits for 4 seconds, but this can be configured by setting Configuration.timeout = amountOfMilliseconds;.

In addition, Selenide has some extra features, such as searching by text:

$(byText("<YOUR TEXT>"));

This requires you to add the following import statement:

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

So, Selenium IDE, Selenium WebDriver and Selenide can be combined when creating regression tests.

One thought on “Automated regression testing in Java with Selenium IDE, Selenium WebDriver and Selenide

  1. Really nice blog!!
    Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.If anyone want to lean more, he/she can visit Selenium Testing

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About Paula van Strien