Introduction To Selenium Software Testing


In the field of agile development, software testing can be a difficult task. Much of the exhaustive testing is conducted manually, which can slow release schedules, as well as make errors more likely. Selenium is a great fit here.
Selenium is an open-source tool that allows you to automate web browsers, which, one could argue, serves to speed up testing by allowing test cases to run quickly. Thus, giving time back to the developers or testers to grid plan the web applications they are verifying for correct workflows in web browsers.
Some of Selenium's use cases allow you to verify login pages, validate UI elements, and user flows. So, it really enables testing to be deeper in the SDLC process by mitigating manual interaction as well as quality time.
What is Selenium?
Selenium is a free (open-source) automated testing framework for web applications, which can run on different browsers and platforms. It supports requesting and script test scripts using many programming languages like Java, Python, C#, Ruby, and JavaScript.
One of the major advantages of Selenium is the cross-browser acceptance, allowing ONE test to run on Chrome, Firefox, Safari, and Edge, with minimal re-writing of code, and it runs on various operating systems. These two reasons are much of the reasons developers and testers around the world have come to love it.
Why is Selenium So Popular for Test Automation?
There are a few reasons why Selenium is special for test automation:
Open-source and free to use
Browser compatibility (Chrome, Firefox, Safari, Edge, etc.)
Compatible with various programming languages
Large documentation and strong community support
Seamlessly works with CI/CD solutions as Jenkins, GitLab, Bamboo
Automation for functional and regression testing
Runs with testing libraries such as TestNG, Junit, PyTest
Core Components of the Selenium Suite
The Selenium suite is made up of four powerful tools, each with a unique purpose:
Selenium IDE (Integrated Development Environment)
Selenium IDE is a browser extension for Chrome and Firefox that allows users to create, edit, and replay test cases as a recording. It is intended for testers who want to create quick test scripts without writing any code. Its most useful for simple automation or exploratory testing or prototyping.
Methodology
You install the extension in Chrome or Firefox.
When you start recording, it captures your actions (clicks, typing, going to a web page).
Selenium IDE takes those actions and is able to convert them into automated test scripts.
You can then replay the script, edit it, or export it in a variety of languages.
Selenium WebDriver
Selenium WebDriver is the principal tool in the Selenium suite. Most likely, you've used WebDriver to write test scripts if you're using Java, Python, C# etc., etc. WebDriver operates through direct control of the browser to mimic real user actions. WebDriver strongly benefits you with larger, more dynamic, and complex testing scenarios.
Methodology
You write a test script in the language of your choice (Python or Java, etc.).
You script sends commands to your browser driver (for example ChromeDriver).
The driver communicates with the browser to perform the required action (clicks, inputs, etc.).
You either watch the tests execute live or log for reporting.
Selenium Grid
Selenium Grid allows for the running of test cases in parallel across many different environments. It helps save time by executing tests against multiple browsers and operating systems at a time, and it is crucial for cross-browser and distributed testing.
Methodology
Set up a hub (the central controller) to schedule/manage where tests are executed.
Set up your multiple nodes (machines or VMs) to run different browsers/OS.
Trigger the tests, and the hub will route the tests to the appropriate node.
You can run multiple tests concurrently, which further enhances the efficiency of the execution of the tests.
Selenium RC
Selenium RC is an older part of automation in the Selenium tool suite that used a proxy server to control browsers. You could write test cases in various programming languages with it, which was pretty cool. Unfortunately, Selenium RC is no longer actively maintained and has now been replaced with Selenium WebDriver due to performance issues.
Methodology
A Selenium RC server was started, which meant it could run as a proxy.
Any test scripts sent commands to that server.
The server, referenced as the command server, translated commands into JavaScript for browser action.
Because it was slow, it was replaced by WebDriver.
Types of Tests You Can Automate with Selenium
Functional Testing
To confirm that each feature of the application works as expected per the business or user requirements. It verifies that the system would perform the correct action with valid input, and would either not do the action or fail gracefully with invalid input.
Example
Testing a login page that a user can log in with valid username and password credentials, and that a user who enters invalid credentials will receive an error message.
Regression Testing
To make sure existing functionality still works following a change to the application such as a bug fix, an update, or an addition in features. This testing will help to reduce the likelihood of unintended side effects, or breaking a feature that was previously working.
Example
After adding a new payment gateway on an e-commerce site you test to ensure the checkout and order confirmation functionality of the existing site is still working.
Cross-Browser Testing
To ensure that your web application has a consistent cross-browser and browser version experience. It identifies layout, compatibility, or functional discrepancies that are worth checking because of browser-specific rendering engines.
Example
Confirming a responsive navigation menu behaves consistently across Chrome, Firefox, Edge, and Safari, in addition to layout, UI elements do not overlap or become broken.
Smoke Testing
To quickly validate the health of an application's core functionalities, after the uploading of a new build or deployment. It validates that main workflows continue to function, and the application is stable enough for you to perform other detailed testing.
Example
After a deployment, check if you can load the homepage, if the login is useable and if the navigation links do not return an error.
UI (User Interface) Testing
UI testing verifies that all visual elements on the interface (buttons, icons, menus, and input terms) show the correct content, work correctly, and adhere to the appropriate design guidelines. UI testing involves both look and feel.
Example
Testing the presence of the “Sign Up” button is the correct styling on it, its clickable functionality, and the redirection to a registration form.
Prerequisites for Getting Started with Selenium
Before writing your first Selenium test script, you should have:
An understanding of programming in general (preferably with Java or Python)
Browser drivers like ChromeDriver (for Chrome) and GeckoDriver (for Firefox)
An IDE such as Eclipse, IntelliJ IDEA, or VS Code
Selenium libraries installed using pip (Python) or Maven/Gradle (Java)
How to Run Selenium Tests: Step-by-Step Guide (Python)
Let’s write a simple Selenium script using Python to open the website and extract the page title.
Step 1: Install Selenium
Open your terminal or command prompt and run:
pip install selenium
Also, download the appropriate WebDriver (e.g., ChromeDriver for Google Chrome) and place it in a known directory. Ensure it's added to your system's PATH
Step 2: Create a Python File
Create a file named ‘sampleseleniumtest.py’ in your project folder.
Step 3: Write Your Selenium Test Code
Paste the following sample code inside your file ‘sampleseleniumtest.py’ :
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
# Step 1: Set up the browser driver (make sure chromedriver is in PATH)
driver = webdriver.Chrome()
# Step 2: Open the Keploy homepage
driver.get("https://keploy.io")
# Step 3: Locate the homepage title
print("Page Title is:", driver.title)
# Step 4: Wait and close browser
time.sleep(3)
driver.quit()
Step 4: Run the Script
In the terminal, navigate to your project directory and execute:
python sampleseleniumtest.py
Step 5: View the Output
You’ll see the browser,
Opens Keploy.io
Displays the homepage with full content
Prints the page title in the terminal
Closes the browser after 3 seconds
Here's what you'll see in your browser when the test runs.
Once testing is done, output in the terminal will be similar to:
DevTools listening on ws://127.0.0.1:56683/devtools/browser/5bf75eb0-8585-4c67-a7e1-f5182c2ffd00
Page Title is: Keploy | Open Source AI-Powered API, Integration, Unit Testing Agent for Developers
Best Practices for Writing Effective Selenium Test Scripts
Implement some techniques to maintain your test scripts and make them efficient:
Follow the POM (Page Object Model) for structured testing.
Break the tests down into smaller reusable units.
Apply explicit waits instead of time.sleep() for consistency.
Develop naming conventions systematically.
catch exceptions for falls off's and errors.
Keep your code DRY (Don't Repeat Yourself).
How to Convert your Curl commands to Selenium Test cases using Keploy
Selenium is amazing! In the previous example, we used a Python script to open a website and extract the page title. Now, let’s explore something different—API Testing.
With the Keploy API Testing Agent, you can create test cases without writing any code. It’s a no-code platform that helps you generate test cases within minutes.
The best part? Keploy uses AI to generate test cases and automatically tests them against your application by hitting its URL.
To get started, you just need to do three simple things.
Provide your Curl commands
Provide Your OpenAPI Schema
Give your Application url (Localhost also works)
To know more: Checkout here
Let’s get our hands dirty and try out Keploy for API Testing! : https://app.keploy.io/home
Login with your credentials. Once you are log in to the Dashboard, you can see the Generate Tests section under API Test Generation, Once you provided all the details click generate test.
Once the Generate test start, you can see the test suite is created once it is done, Go to Test suite Section, Get the curl command for any of the test suite
Once you copied the curl commands let try that to change in to selenium test cases.
Here is my curl command:
curl -X POST 'https://f468-122-166-253-157.ngrok-free.app/petclinic/api/owners' -H 'Content-Type: application/json' -d '{"firstName":"VisitOwner","lastName":"Test","address":"Visit Street 1","city":"VisitCity","telephone":"8383838383"}'
we now have curl command and we can start writing selenium test case for this one.
You can see the below code we have converted the curl command to selenium test case.
const axios = require('axios');
const assert = require('assert');
// The URL of the API
const url = 'https://f468-122-166-253-157.ngrok-free.app/petclinic/api/owners';
// The JSON data to send in the request
const requestBody = {
firstName: "VisitOwner",
lastName: "Test",
address: "Visit Street 1",
city: "VisitCity",
telephone: "8383838383"
};
// Function to make the POST request and validate the response
async function testApiPostRequest() {
try {
// Step 1: Send the POST request using Axios
const response = await axios.post(url, requestBody, {
headers: {
'Content-Type': 'application/json',
},
});
// Step 2: Check if the response status is 201 (created)
assert.strictEqual(response.status, 201, 'Response status is not 201');
// Step 3: Validate the response body
const responseBody = response.data;
assert.strictEqual(responseBody.firstName, "VisitOwner", 'First name mismatch');
assert.strictEqual(responseBody.lastName, "Test", 'Last name mismatch');
assert.strictEqual(responseBody.address, "Visit Street 1", 'Address mismatch');
assert.strictEqual(responseBody.city, "VisitCity", 'City mismatch');
assert.strictEqual(responseBody.telephone, "8383838383", 'Telephone mismatch');
assert.ok(responseBody.id, 'Owner ID is missing');
console.log('API test passed!');
} catch (error) {
console.error('API test failed:', error);
}
}
// Run the API test
testApiPostRequest();
In the above one we have converted the curl commands to the selenium test cases. You can also do more than that if you want to know more please: checkout here
Top Advantages of Using Selenium for Software Testing
Fast, efficient test execution.
Scalable and parallel execution using Selenium Grid.
Continuous integration and continuous delivery tools can plug and play in testing.
Flexible language and platform options.
No licensing costs at all - fully open source.
Conclusion
Selenium is a crucial component in today’s ecosystem of automated software testing tools. Being able to test web applications over many browsers and platforms, it is little wonder that Selenium is so popular with QA teams.
For those who are new to Selenium, as well as anyone who has been using Selenium for a while, knowing how to effectively use Selenium will make you much more productive and produce better applications. So, when should you start? Keep it simple; just write your first test script today and see how easy it is to do automation!
FAQs
1. Is Selenium only for web apps?
Yes. Selenium was created solely for the web, and tools like Appium should be used for mobile.
2. Can I use Selenium without programming?
You need to do some basic scripting. However, you can use Selenium IDE to record and playback scripts, which requires minimal coding.
3. Which language is best for Selenium?
Java and Python are the most popular languages because of their simplicity, and enormous community support.
4. Is Selenium suitable for mobile testing?
Not directly. While you can automate mobile using Selenium, Appium is a better choice for mobile automation and is built on top of Selenium WebDriver.
5. How does Selenium compare to Cypress?
Selenium works with multiple browsers and languages, but Cypress supports mostly JavaScript, mainly runs on Chrome-based browsers, and can be faster and provides better debugging features for front-end developers.
Subscribe to my newsletter
Read articles from Monasri directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Monasri
Monasri
AI & Data Science enthusiast with expertise in Python, SQL, JavaScript, and libraries like Langchain, FastAPI, OpenCV, XGBoost and Scikit-learn. Skilled in developing AI agent systems, fine-tuning LLMs, and predictive modelling. Proficient in automation tools like UiPath and n8n, along with Power BI and Excel for data visualization. Experienced in working with MongoDB and MySQL. Passionate about agentic automation, real-time AI applications, and exploring emerging technologies to build impactful, scalable solutions.