Comprehensive guide to modern testing frameworks for web, mobile, and API automation
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).
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 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.
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 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.
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();
});
});
| 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 |