Software Testing Learning Hub

Selenium Lesson 4 – Record the Selenium Script using Selenium IDE

Selenium IDE is an integrated development environment to record and playback the selenium scripts to test website on firefox. Its is a Firefox plugin where Tester can Record, Edit and play the Scripts. If you are new then this is right place to start learning Selenium!

Selenium IDE has core selenium functionality by which you can export the recorded scripts in different formats as well and can be used by Advance Selenium user.

Selenium IDE is not only the recording and playback tool but you can edit your scripts and maintain it.

 Features of Selenium IDE:

  • Easy record and playback
  • Intelligent field selection will use IDs, names, or XPath as needed
  • Autocomplete for all common Selenium commands
  • Walk through tests
  • Debug and set breakpoints
  • Save tests as HTML, Ruby scripts, or any other format
  • Support for Selenium user-extensions.js file
  • Option to automatically assert the title of every page
  • NEW! Easy customization through plugins

How to Start with Selenium?  ( note video of this lesson is here

First of All you need to download the Firefox and then Selenum IDE plugin for firefox.

1) you can download the plugin  from http://seleniumhq.org/download/ :

Latest version : http://release.seleniumhq.org/selenium-ide/1.9.0/selenium-ide-1.9.0.xpi

2) Just install the plugin as you install other firefox plugin, Restart your browser.

3) Under Tools menu, you will find the Selenium IDE, Click on it, it will open the Selenium IDE window

Great! now you are Set to learn Selenium IDE. 

following is the basic areas of Selenium IDE window

selenium ide

 

Basic URL : is the Url which you want to test

Test Case Area : where your all tests cases gets maintain

 Script Editing Window :  this is place where your test case will gets recorded and you can able to edit the test case.

Record button :  with the help of this button you can start and stop the recording.

 

Lets Record the simple script…  go the following steps

1) Open the Firefox browser

2) Go to website http://www.qeworks.com

3)  in Firefox menu > go to Tools > select Selenium IDE

4) you will get the Selenium IDE window, make sure that Based URL in Selenium IDE should be http://www.qeworks.com else you will not able to capture the action also make sure that recording button should be pressed.

5) Click on Software testing menu item

6) you will notice following script gets generated.

selenium ide

7) Now Stop the recording by clicking on Record button

8) click on run button again to run the script again

You are Done!

in the next lesson we will see how to read the code generated from this script. to generate the code do following steps.

9)  Now click on File > Export test case as > Java/junit 4/Webdriver

10)  Save the file and open the same in the eclipse or any any ide.

following code will gets

package com.example.tests;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Recording {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();

@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://qeworks.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void testRecording() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("Software Testing")).click();
}

@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}

private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}

 

 

 

in similar recording and playback of scripts can be done using Selenium IDE