Practical 13: Selenium IDE
Aim
Install Selenium IDE (Integrated Development Environment). Record the steps for logging in to a website. Add checks for the page contents, run the test again and export it as Java code.
Theory
Selenium IDE records actions such as opening a page, typing and clicking. It can replay those actions as a test.
An assertion checks whether a result matches what you expected. For a login test, this could check that the welcome message appears. Recording clicks alone does not check that the login worked.
Selenium IDE works like the macro recorder on a phone or a voice recorder: press Record, do the steps yourself (open the site, type the name, click Login), press Stop. Press Play and the browser repeats exactly what you did – as many times as you want.
| Component | Purpose |
|---|---|
| Selenium IDE | Browser extension (Chrome/Firefox/Edge) for record-and-playback – no programming needed |
| Selenium RC (Remote Control) | Legacy (Selenium 1) server that injected JavaScript to drive browsers – deprecated |
| Selenium WebDriver | Programmatic API (Application Programming Interface) (Java, Python, C#, JS…) that drives browsers natively through drivers – current standard |
| Selenium Grid | Runs tests in parallel on many machines/browsers |
Selenium IDE records user actions as commands in a table of Command – Target – Value:
| Command | Target | Value | Meaning |
|---|---|---|---|
open |
/login |
Navigate to a URL (Uniform Resource Locator) | |
type |
id=username |
student |
Type text into an element |
click |
css=button[type=submit] |
Click an element | |
assert text |
css=h1 |
Dashboard |
Stop the test if the text differs |
verify text |
css=.welcome |
Welcome, student |
Log a failure but continue |
assert element present |
id=logout |
Element must exist | |
wait for element visible |
css=.alert |
5000 |
Explicit wait |
store text |
css=.cart-count |
count |
Save into variable ${count} |
echo |
${count} |
Print a value to the log |
An assert check stops the test if it fails. A verify check records the failure and continues. Use assert when later steps depend on the result. Use verify when you want to check several independent values.
Locator strategies
| Locator | Example | Notes |
|---|---|---|
id= |
id=username |
Fastest, most reliable |
name= |
name=password |
|
css= |
css=form#login button.primary |
Flexible, fast |
xpath= |
xpath=//button[text()='Login'] |
Powerful, can be brittle |
linkText= |
linkText=Forgot password? |
For anchor links |
Selenium IDE records several locators per element and lets you choose the most robust one.
Requirements
The .test addresses refer to the simulated practice app. Outside the simulator, use a running test app and its actual addresses and page elements.
- Google Chrome / Microsoft Edge / Firefox (latest).
- Selenium IDE extension from the Chrome Web Store / Firefox Add-ons.
- Application under test: VLP Demo Store (in the virtual lab) or any practice login page.
- Valid user:
student/Pass@123.
- Valid user:
Procedure
Part A – Install Selenium IDE
- Open the Chrome Web Store, search Selenium IDE → Add to Chrome → Add extension.
- Click the Selenium IDE icon in the toolbar. Choose Record a new test in a new project.
- Project name:
DemoStoreTests→ OK.
Part B – Record the login scenario
- Base URL:
https://demo.virtuallp.test→ Start recording. A new browser window opens with a “Selenium IDE is recording…” banner. - In the application:
- click Login,
- type
studentin Username andPass@123in Password, - click Sign in.
- On the dashboard, right-click the heading Welcome, student → Selenium IDE → Assert → Text (adds an assertion while recording).
- Return to Selenium IDE and click Stop recording; name the test
Login valid user.
Part C – Add assertions and edit commands
- Select the last row → right-click → Insert new command:
assert title|Dashboard – VLP Demo Storeverify element present|id=logoutassert text|css=.user-name|student
- Change fragile XPath targets to
id=orcss=locators using the target drop-down. - Add a negative test: duplicate the test (
Login invalid password), change the password towrong, and replace the dashboard assertions withassert text|css=.alert-error|Invalid username or password.
Part D – Run the tests
- Click Run current test (▶). Each command turns green if passed and red if failed; the Log panel shows details.
- Click Run all tests to run the suite. Adjust the test execution speed slider if pages load slowly.
- Intentionally break an assertion (expect
Dashbord) and observe the failure message, then fix it.
Part E – Export to Java
- Right-click the test → Export → Java JUnit → tick Include origin tracing code comments (optional) → Export → save
LoginvaliduserTest.java.
Exported code (Java JUnit 4 + WebDriver)
// Generated by Selenium IDE
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.*;
public class LoginvaliduserTest {
private WebDriver driver;
private Map<String, Object> vars;
@Before
public void setUp() {
driver = new ChromeDriver();
vars = new HashMap<String, Object>();
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void loginvaliduser() {
driver.get("https://demo.virtuallp.test/");
driver.manage().window().setSize(new Dimension(1280, 800));
driver.findElement(By.linkText("Login")).click();
driver.findElement(By.id("username")).sendKeys("student");
driver.findElement(By.id("password")).sendKeys("Pass@123");
driver.findElement(By.cssSelector("button[type=submit]")).click();
assertThat(driver.getTitle(), is("Dashboard – VLP Demo Store"));
{
List<WebElement> elements = driver.findElements(By.id("logout"));
assert(elements.size() > 0);
}
assertThat(driver.findElement(By.cssSelector(".user-name")).getText(), is("student"));
}
}
The .side project file (JSON (JavaScript Object Notation)) can be saved with Save project and re-opened or run on CI with selenium-side-runner:
npm install -g selenium-side-runner
selenium-side-runner DemoStoreTests.side
Virtual lab · Testing Tools · 30 min
Record, assert and replay tests with Selenium IDE
Install the Selenium IDE extension, record a login on the VLP Demo Store, add assertions, build a negative test, watch a broken assertion fail, run the suite and export the test to Java JUnit.
Output / Observations
Example output for the settings in this lesson:
- Log:
1. open on / OK,2. click on linkText=Login OK, …8. assertText on css=.user-name with value student OK→ 'Login valid user' completed successfully. - The negative test passes when the error alert text matches.
- A changed expectation produces “assertText on css=h1 with value Dashbord Failed: Actual value 'Dashboard' did not match 'Dashbord'” and the test stops.
Conclusion
Replay the recorded login and check the pass or fail result. Change an expected value to see a failure, then correct it. Open the exported Java file and find the same browser actions and checks.
Viva questions
- What are the components of the Selenium suite? Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid.
- What is record and playback? What are its limitations? Recording user actions and replaying them; tests are brittle, hard to reuse, have little logic or data-driving, and break when the UI (User Interface) changes.
- Differentiate
assertandverifycommands. assert stops the test on failure; check records the failure and continues. - List the locator strategies supported by Selenium IDE. Which is preferred and why? id, name, linkText, css, xpath (and others); id is preferred because it is unique, fast and stable.
- What is a
.sidefile? The JSON project file in which Selenium IDE saves tests and suites. - How can a Selenium IDE test be run from the command line? With the Selenium side runner:
selenium-side-runner project.side. - Why are exported tests usually refactored before use in a framework? To add waits, Page Objects, reusable methods, test data and proper assertions instead of fixed recorded steps.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.