Selenium IDE Introduction

  

Selenium IDE (Integrated Development Environment) is a browser-based tool used to record, edit, and play back test cases for web applications. It's primarily used for creating automated tests without writing any code, making it ideal for beginners in automation testing.


Key Features of Selenium IDE:


Record and Playback
 - You can interact with a web application while Selenium IDE records your actions (like clicks, typing, navigation) as test steps.
 - These steps can then be replayed to automate the test.

Easy to Use
 - No programming knowledge required.
 - It uses a simple GUI with a list of recorded steps.

Script Editing
 - You can edit test steps or add custom commands manually.
 - Supports assertions, control flow (like if-else, while loops), and variables.

Export Test Cases
 - You can export recorded tests to different programming languages like Java, Python, C#, and JavaScript for use with Selenium WebDriver.

Cross-Browser Support
 - Available as extensions for Chrome and Firefox.

Plugins and Command-Line Runner
 - Supports plugins for extended functionality.
 - Can be run in CI/CD pipelines using the Selenium IDE command-line runner (SIDE Runner).


Advantages:

  • Beginner-friendly.
  • Speeds up test case creation.
  • Supports debugging and breakpoints.
  • Reusable test components (test suites, test cases).


Limitations:

  • Not suitable for complex test scenarios.
  • Less flexible than WebDriver for dynamic web elements.
  • Limited browser support compared to Selenium WebDriver.

Below are key benefits of using Selenium IDE:


1. Easy to Use – No Coding Required

  • Selenium IDE provides a user-friendly GUI.

  • Test cases can be created just by recording user interactions with the browser—no need to write code manually.

  • Ideal for beginners or manual testers transitioning to automation.


2. Rapid Test Development

  • Allows quick recording and playback of test scripts.

  • Great for creating proof-of-concept or smoke tests with minimal effort.


3. Cross-Browser Support

  • Available as browser extensions for Chrome and Firefox.

  • Tests can be executed across multiple browsers to ensure compatibility.


4. Debugging Capabilities

  • Supports breakpoints, step-by-step execution, and log inspection.

  • Makes it easy to troubleshoot failed test cases.


5. Control Flow Support

  • Built-in support for conditional statements (if, else), loops (while, do), and error handling.

  • Adds logic and flexibility to your test cases.


6. Export Test Cases to WebDriver Code

  • Recorded test cases can be exported to programming languages like Java, Python, C#, or JavaScript.

  • Helps testers transition to Selenium WebDriver for more advanced testing needs.


7. Reusability and Modularity

  • You can create test suites, reuse test cases, and use commands like run to modularize tests.


8. Integration with CI/CD Pipelines

  • Selenium IDE tests can be executed via the SIDE Runner (Command-line test runner).

  • Enables integration with Jenkins, GitHub Actions, or other CI tools for continuous testing.


9. Open Source and Free

  • Completely free and open-source, with active community support.

  • No licensing cost involved.


10. Portable and Lightweight

  • Being a browser extension, it’s easy to install and use without complex setup.


Advantages and Limitations of Selenium

  

Below are some advantages of Selenium:


1. Open Source and Free

  • Selenium is completely free to use, with no licensing costs.
  • It is maintained by a strong open-source community.
  • Ideal for both startups and enterprises.


2. Supports Multiple Programming Languages

  • Test scripts can be written in Java, Python, C#, Ruby, JavaScript, Kotlin, etc.
  • Allows teams to work in languages they are already familiar with.


3. Cross-Browser Testing

  • Supports all major browsers:
  • Google Chrome
  • Mozilla Firefox
  • Microsoft Edge
  • Safari
  • Opera
  • Helps ensure consistent behavior across different browsers.


4. Cross-Platform Compatibility

  • Works on Windows, macOS, Linux, and UNIX.
  • Allows you to write once and run anywhere (with minimal changes).


5. Framework and Tool Integration

  • Integrates well with tools and frameworks like:
  • TestNG, JUnit, PyTest (testing frameworks)
  • Maven, Gradle (build tools)
  • Jenkins, GitHub Actions (CI/CD pipelines)
  • Docker, Selenium Grid (parallel & distributed execution)
  • Allure, ExtentReports (reporting)


6. Supports Parallel and Distributed Testing

  • Using Selenium Grid, you can run tests in parallel across different environments and machines.
  • This speeds up execution and improves test coverage.


7. Strong Community Support

  • Vast global community and plenty of tutorials, forums, and documentation.
  • Quick updates, bug fixes, and community plugins are readily available.


8. Flexible and Extensible

  • You can create custom extensions or integrate with third-party libraries.
  • Works with BDD tools like Cucumber and SpecFlow.


9. No GUI Required

  • Supports headless browser testing using tools like Headless Chrome or HTMLUnitDriver.
  • Useful for running tests on servers or CI environments without a UI.


10. Real Browser Automation

  • Selenium controls real browsers (not simulations), ensuring tests behave like real users.
  • More reliable for end-to-end testing.


11. Supports Modern Features (Selenium 4+)

  • W3C WebDriver protocol for better browser compatibility
  • Relative locators (near, above, below, toLeftOf, toRightOf)
  • Improved debugging tools and browser-level logging
  • Chrome DevTools Protocol (CDP) integration


Below are some limitations of Selenium:

1. Only Supports Web Applications

  • Selenium cannot automate desktop or mobile applications directly.
  • For mobile apps, you need tools like Appium.
  • For desktop apps, tools like WinAppDriver, AutoIT, or Winium are required.


2. No Built-in Reporting

  • Selenium does not provide built-in test result reporting.
  • You need to integrate with external tools like:
  • TestNG / JUnit (Java) for test result tracking
  • Allure, ExtentReports, or custom logging for detailed reports


3. No Built-in Test Case Management

  • Selenium lacks features like test case organization, prioritization, and test suite management.
  • You need to use external test management tools (e.g., TestRail, Zephyr).


4. Handling Captchas, Barcode, or OTP

  • Selenium cannot solve Captchas, barcodes, or OTP fields by itself.
  • These are intentionally designed to block automation.


5. Requires Programming Knowledge

  • Unlike some other tools (e.g., TestComplete, Katalon), Selenium requires knowledge of programming (Java, Python, etc.) and frameworks (TestNG, JUnit).
  • Not ideal for non-technical users or manual testers without coding experience.


6. Browser Compatibility Issues

  • Sometimes different browsers interpret actions differently.
  • Maintaining browser drivers (ChromeDriver, GeckoDriver, etc.) can be a hassle.
  • Browser version updates may break tests until drivers are updated.


7. Maintenance Overhead

  • Selenium scripts can become fragile and hard to maintain if the web application's UI changes frequently.
  • Requires design patterns like Page Object Model (POM) or Page Factory to manage changes efficiently.


8. No Native Image-Based Testing

  • Selenium cannot verify images, logos, or visual components directly.
  • For image comparisons, you need tools like Sikuli, Applitools, or Percy.


9. Performance Testing Limitations

  • Selenium is not designed for performance or load testing.
  • Tools like JMeter, Gatling, or LoadRunner are better suited for those purposes.


10. Limited Support for File Upload/Download

  • Upload/download testing requires workarounds, such as:
  • AutoIT for handling OS-level dialogs
  • Setting browser preferences to auto-download files

Selenium Architecture

  

Selenium WebDriver Architecture – Overview

Selenium WebDriver follows a client-server architecture and allows direct communication between test scripts and browsers.


Components of the Architecture:

  1. Test Script (Client Layer)

    • Written in any supported language (Java, Python, C#, etc.)

    • Uses Selenium APIs

  2. Selenium WebDriver

    • Acts as a bridge between the test script and the browser

    • Sends commands from test scripts to the browser driver

  3. Browser Driver

    • Each browser has its own driver (e.g., ChromeDriver, GeckoDriver for Firefox)

    • Accepts commands via HTTP (JSON Wire Protocol or W3C protocol)

    • Converts commands into actions performed on the browser

  4. Real Browser

    • Chrome, Firefox, Edge, Safari, etc.

    • Executes the actions like clicking, typing, navigating, etc.


Selenium Architecture Diagram 










Working of Selenium Architecture:

  1. Test script sends a command (e.g., click button).

  2. WebDriver forwards it to the browser-specific driver.

  3. The driver communicates with the browser via native APIs.

  4. The browser executes the command.

  5. Response is sent back via the same path.

Selenium Overview

  

Introduction

Selenium is an open-source automation testing framework specifically designed to automate web browser interactions. It allows testers and developers to automate web-based applications for functional and regression testing across various browsers and platforms.

It cannot be used for desktop or mobile app automation (though it can be combined with Appium for mobile).

Selenium tests are written in various languages: Java, Python, C#, Ruby, JavaScript, Kotlin, etc.


History of Selenium

  • Selenium Core (2004): Created by Jason Huggins. It was JavaScript-based and used for in-browser testing.
  • Selenium RC (Remote Control): Introduced to overcome the same-origin policy. Became outdated.
  • Selenium WebDriver (2008): A more stable and modern approach to browser automation. Directly communicates with the browser.
  • Selenium Grid Introduced to run tests in parallel across different machines and environments.
  • Selenium 4 (2021): Latest version, includes W3C WebDriver standard, improved IDE, relative locators, and better debugging tools.


Advantages of Selenium:


1. Open Source and Free

  • Selenium is completely free to use, with no licensing costs.
  • It is maintained by a strong open-source community.
  • Ideal for both startups and enterprises.


2. Supports Multiple Programming Languages

  • Test scripts can be written in Java, Python, C#, Ruby, JavaScript, Kotlin, etc.
  • Allows teams to work in languages they are already familiar with.


3. Cross-Browser Testing

  • Supports all major browsers:
  • Google Chrome
  • Mozilla Firefox
  • Microsoft Edge
  • Safari
  • Opera
  • Helps ensure consistent behavior across different browsers.


4. Cross-Platform Compatibility

  • Works on Windows, macOS, Linux, and UNIX.
  • Allows you to write once and run anywhere (with minimal changes).


5. Framework and Tool Integration

  • Integrates well with tools and frameworks like:
  • TestNG, JUnit, PyTest (testing frameworks)
  • Maven, Gradle (build tools)
  • Jenkins, GitHub Actions (CI/CD pipelines)
  • Docker, Selenium Grid (parallel & distributed execution)
  • Allure, ExtentReports (reporting)


6. Supports Parallel and Distributed Testing

  • Using Selenium Grid, you can run tests in parallel across different environments and machines.
  • This speeds up execution and improves test coverage.


7. Strong Community Support

  • Vast global community and plenty of tutorials, forums, and documentation.
  • Quick updates, bug fixes, and community plugins are readily available.


8. Flexible and Extensible

  • You can create custom extensions or integrate with third-party libraries.
  • Works with BDD tools like Cucumber and SpecFlow.


9. No GUI Required

  • Supports headless browser testing using tools like Headless Chrome or HTMLUnitDriver.
  • Useful for running tests on servers or CI environments without a UI.


10. Real Browser Automation

  • Selenium controls real browsers (not simulations), ensuring tests behave like real users.
  • More reliable for end-to-end testing.


11. Supports Modern Features (Selenium 4+)

  • W3C WebDriver protocol for better browser compatibility
  • Relative locators (near, above, below, toLeftOf, toRightOf)
  • Improved debugging tools and browser-level logging
  • Chrome DevTools Protocol (CDP) integration

Selenium Introduction

 

Selenium Introduction

Selenium is a powerful and widely-used open-source automation testing tool used primarily for web applications. It supports multiple browsers, programming languages, and operating systems, making it a popular choice among testers and developers for automating web-based applications.


What is Selenium?

Selenium is a suite of tools that automate web browser interactions. It allows you to write test scripts in various programming languages such as Java, Python, C#, Ruby, and JavaScript, and run them across multiple browsers like Chrome, Firefox, Safari, and Edge.


Components of Selenium:

  • Selenium IDE: A Chrome/Firefox plugin for record-and-playback of interactions with the browser. Great for beginners.
  • Selenium RC: Older tool that has been replaced by WebDriver. Not used in modern testing.
  • Selenium WebDriver: A tool that provides APIs for automating browser actions. Most commonly used component.
  • Selenium Grid: Allows running tests on different machines and browsers in parallel (distributed testing).


Features of Selenium:

  • Open-source and free to use.
  • Cross-browser support (Chrome, Firefox, Safari, etc.).
  • Cross-platform support (Windows, macOS, Linux).
  • Supports multiple languages (Java, Python, C#, etc.).
  • Integrates with testing frameworks like TestNG, JUnit, and automation tools like Maven, Jenkins, Docker, etc.
  • Supports parallel test execution using Selenium Grid.


How Selenium Works?

  • Selenium sends commands (via language bindings) to the browser driver (example: ChromeDriver).
  • The browser driver translates these commands into actions in the actual browser.
  • The browser performs the action and sends the result back to Selenium.


Selenium is generally used for:

  • Automated functional/regression testing of web apps.
  • Browser compatibility testing.
  • Integration in CI/CD pipelines (e.g., Jenkins).
  • Web scraping (although not intended for it, WebDriver is often used for scraping dynamic sites).


Languages and Tools Commonly Used with Selenium:

  • Languages: Java, Python, C#, Ruby, JavaScript.
  • Tools: TestNG/JUnit (testing frameworks), Maven/Gradle (build tools), Jenkins (CI/CD), Git (version control).

Integration of Cucumber, Playwright and TestNG

 

Integrating Cucumber, Playwright, and TestNG in Java enables you to write BDD (Behavior Driven Development) style tests using Gherkin (.feature files), automate browser interactions using Playwright, and manage execution using TestNG.


Tools Used:

  • Cucumber for BDD feature files and step definitions

  • Playwright for Java for browser automation

  • TestNG for test execution and reporting

  • Maven for dependency management


Below are the steps showing integration of Cucumber, Playwright and TestNG



pom.xml:


<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>cucumber-playwright-testng</artifactId>
  <version>1.0</version>

  <dependencies>
    <!-- Cucumber Dependencies -->
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>7.14.0</version>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-testng</artifactId>
      <version>7.14.0</version>
    </dependency>

    <!-- TestNG -->
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>7.9.0</version>
      <scope>test</scope>
    </dependency>

    <!-- Playwright Java -->
    <dependency>
      <groupId>com.microsoft.playwright</groupId>
      <artifactId>playwright</artifactId>
      <version>1.44.0</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Surefire for TestNG -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.2.5</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>



login.feature (Gherkin feature file)


Feature: Login to Application

  Scenario: Open login page and check title
    Given I launch the application
    Then I should see the page title as "Example Domain"





PlaywrightFactory.java


package utils;

import com.microsoft.playwright.*;

public class PlaywrightFactory {
    public static Playwright playwright;
    public static Browser browser;
    public static Page page;

    public static void init() {
        playwright = Playwright.create();
        browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
        page = browser.newPage();
    }

    public static void close() {
        browser.close();
        playwright.close();
    }
}





LoginSteps.java


package steps;

import com.microsoft.playwright.Page;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.*;
import utils.PlaywrightFactory;

import static org.testng.Assert.assertEquals;

public class LoginSteps {
    Page page;

    @Before
    public void setup() {
        PlaywrightFactory.init();
        page = PlaywrightFactory.page;
    }

    @Given("I launch the application")
    public void i_launch_the_application() {
        page.navigate("https://example.com");
    }

    @Then("I should see the page title as {string}")
    public void i_should_see_the_page_title_as(String expectedTitle) {
        String actualTitle = page.title();
        assertEquals(actualTitle, expectedTitle);
    }

    @After
    public void tearDown() {
        PlaywrightFactory.close();
    }
}






TestRunner.java (Cucumber TestNG runner)


package runners;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;

@CucumberOptions(
    features = "src/test/resources/features",
    glue = "steps",
    plugin = {"pretty", "html:target/cucumber-reports.html"},
    monochrome = true
)
public class TestRunner extends AbstractTestNGCucumberTests {
    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }
}





testng.xml


<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Cucumber Playwright TestNG Suite">
  <test name="Cucumber Tests">
    <classes>
      <class name="runners.TestRunner"/>
    </classes>
  </test>
</suite>

Difference between Appium and Selenium

 


Selenium and Appium are both automation tools used for testing applications, but they serve different purposes and target different platforms. Here's a detailed comparison:


FeatureSeleniumAppium
Target PlatformsWeb applications onlyMobile applications (Android & iOS) and web apps
Main Use CaseAutomating browser-based testingAutomating mobile app testing (native, hybrid, web)
Web ApplicationsYes it supportsMobile browsers only like Chrome, Safari
Native Mobile ApplicationsNoYes
Hybrid Mobile ApplicationsNoYes
DependenciesBrowser drivers onlyAndroid SDK, Xcode (for iOS), Node.js, etc.
Languages SupportedJava, Python, C#, Ruby, etc.Same as Selenium
Test Framework CompatibilityJUnit, TestNG, PyTest, etc.Compatible with same tools
Element LocatorsXPath, ID, CSS, Class, TagName, etc.All Selenium locators + Mobile-specific ones
SpeedFast and stable for web automationSlightly slower due to mobile overhead



Which One Should You Use?

  • Use Selenium if you are testing only web applications on desktop browsers.

  • Use Appium if you need to test mobile applications (native or hybrid), or mobile versions of web apps.

How to Run JUnit Test in Selenium

  

Below is the code and explanation of JUnit Test with Selenium WebDriver in Java. 



What is JUnit?

JUnit is a popular testing framework in Java used to write and run repeatable test cases. When integrated with Selenium WebDriver, JUnit helps automate UI/browser tests with setup and teardown capabilities.


Key JUnit Annotations:

AnnotationPurpose
@BeforeRuns before each test method
@AfterRuns after each test method
@BeforeClassRuns once before all tests
@AfterClassRuns once after all tests
@TestMarks a test method
@IgnoreIgnores the test method


Simple Selenium Test with JUnit

Maven Dependencies in pom.xml

If you're using Maven, include below dependencies


<dependencies>
    <!-- Selenium WebDriver -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.20.0</version>
    </dependency>

    <!-- JUnit 4 -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>



Full Example Using JUnit + Selenium



import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearchTest {

    WebDriver driver;

    @Before
    public void setUp() {
        // Set the path to your chromedriver executable if needed
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
    }

    @Test
    public void testGoogleSearch() {
        // Navigate to Google
        driver.get("https://www.google.com");

        // Find the search box and enter text
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("JUnit Selenium");

        // Submit the search form
        searchBox.submit();

        // Wait for results and assert
        try {
            Thread.sleep(2000); // use WebDriverWait in real tests
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // Check title contains the search keyword
        String title = driver.getTitle();
        assertTrue("Title should contain search term", title.contains("JUnit Selenium"));
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.quit(); // Close the browser
        }
    }
}

What This Code Does:

  • @Before: Sets up WebDriver before each test.

  • @Test: Opens Google, performs a search, and verifies the result.

  • @After: Quits the browser after each test.


To Run the Test:

  • If using IDE: Right-click > Run As > JUnit Test

  • If using Maven: Use mvn test (requires Surefire plugin)