Selenium WebDriver

Multi-language Web Testing Industry Standard
Web Cross-browser Open Source

Overview

Selenium WebDriver is the most widely-used open-source framework for automating web browsers. It provides a programming interface to create and execute test cases by controlling browsers programmatically. Selenium supports multiple browsers (Chrome, Firefox, Safari, Edge) and multiple programming languages (Java, Python, C#, JavaScript, Ruby).

Key Features

  • Cross-browser testing support
  • Multiple language bindings
  • Large community support
  • Integration with CI/CD tools
  • Parallel test execution
  • Cloud testing platforms support

Advantages

  • Mature and stable framework
  • Extensive documentation
  • Large community and ecosystem
  • Supports all major browsers
  • Free and open source

Limitations

  • Slower execution compared to newer tools
  • Requires more setup and configuration
  • Limited built-in reporting
  • Can be flaky with dynamic content
  • Steeper learning curve

Example Code (Java)

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;

public class SeleniumExample {
    public static void main(String[] args) {
        // Initialize WebDriver
        WebDriver driver = new ChromeDriver();
        
        // Navigate to URL
        driver.get("https://example.com");
        
        // Find element and perform action
        driver.findElement(By.id("username")).sendKeys("testuser");
        driver.findElement(By.id("password")).sendKeys("password123");
        driver.findElement(By.id("login-btn")).click();
        
        // Assertion
        String title = driver.getTitle();
        assert title.contains("Dashboard");
        
        // Close browser
        driver.quit();
    }
}

Cypress

JavaScript Fast & Modern Developer Friendly
Web JavaScript Real-time

Overview

Cypress is a next-generation front-end testing framework built for modern web applications. It runs directly in the browser, providing fast, reliable, and easy-to-debug tests. Cypress offers a complete end-to-end testing experience with automatic waiting, real-time reloads, and time-travel debugging.

Key Features

  • Automatic waiting and retries
  • Real-time test execution
  • Time-travel debugging
  • Built-in network stubbing
  • Screenshot and video recording
  • Easy setup and configuration

Advantages

  • Fast test execution
  • Excellent debugging experience
  • Easy to learn and use
  • Automatic waiting eliminates flakiness
  • Great documentation and examples

Limitations

  • JavaScript/TypeScript only
  • Limited multi-browser support (improving)
  • Cannot test multiple tabs
  • Same-origin policy restrictions
  • Cloud execution requires paid plan

Example Code (JavaScript)

describe('Login Test', () => {
  beforeEach(() => {
    cy.visit('https://example.com/login');
  });

  it('should login successfully with valid credentials', () => {
    // Type username
    cy.get('#username').type('testuser');
    
    // Type password
    cy.get('#password').type('password123');
    
    // Click login button
    cy.get('#login-btn').click();
    
    // Assert successful login
    cy.url().should('include', '/dashboard');
    cy.get('.welcome-message').should('contain', 'Welcome');
  });

  it('should show error with invalid credentials', () => {
    cy.get('#username').type('invalid');
    cy.get('#password').type('wrong');
    cy.get('#login-btn').click();
    
    cy.get('.error-message').should('be.visible');
  });
});

Playwright

Multi-language Microsoft Modern
Web Mobile API

Overview

Playwright is a modern automation framework developed by Microsoft that enables reliable end-to-end testing for web applications. It supports all modern browsers (Chromium, WebKit, Firefox) with a single API, offers powerful auto-waiting mechanisms, and provides built-in support for mobile emulation and API testing.

Key Features

  • Cross-browser & cross-platform
  • Auto-wait for elements
  • Network interception
  • Mobile device emulation
  • Multiple contexts and tabs
  • Built-in test runner

Advantages

  • Excellent browser compatibility
  • Fast and reliable execution
  • Powerful API with great features
  • Active development and updates
  • Built-in parallelization

Limitations

  • Newer framework (smaller community)
  • Limited third-party integrations
  • Steeper learning curve initially
  • Larger browser binaries
  • Some features still evolving

Example Code (TypeScript)

import { test, expect } from '@playwright/test';

test.describe('Login Tests', () => {
  test('successful login', async ({ page }) => {
    // Navigate to login page
    await page.goto('https://example.com/login');
    
    // Fill credentials
    await page.fill('#username', 'testuser');
    await page.fill('#password', 'password123');
    
    // Click login button
    await page.click('#login-btn');
    
    // Wait for navigation and verify
    await expect(page).toHaveURL(/.*dashboard/);
    await expect(page.locator('.welcome-message'))
      .toContainText('Welcome');
  });

  test('failed login shows error', async ({ page }) => {
    await page.goto('https://example.com/login');
    await page.fill('#username', 'invalid');
    await page.fill('#password', 'wrong');
    await page.click('#login-btn');
    
    await expect(page.locator('.error-message'))
      .toBeVisible();
  });
});

Framework Comparison

Feature Selenium Cypress Playwright
Languages Supported Java, Python, C#, JavaScript, Ruby JavaScript, TypeScript JavaScript, Python, Java, C#
Browser Support Chrome, Firefox, Safari, Edge, IE Chrome, Edge, Firefox, Electron Chromium, WebKit, Firefox
Speed Moderate Fast Very Fast
Setup Complexity Medium-High Low Low-Medium
Auto-Waiting No (manual waits needed) Yes Yes
Debugging Basic Excellent (Time-travel) Excellent (Inspector)
Mobile Testing Via Appium Limited (viewport only) Emulation supported
API Testing Via REST Assured Built-in Built-in
Community Size Very Large Large Growing
Best For Enterprise, Legacy systems Modern web apps, Fast feedback Cross-browser, Full-stack testing