📌

E2E Testing là gì?

Định nghĩa

End-to-End Testing mô phỏng hành vi người dùng thực tế, kiểm tra toàn bộ flow từ UI đến backend, database.

💡 Use cases:
• User login/logout flow
• Checkout process (e-commerce)
• Form submissions
• Multi-page workflows

So sánh Frameworks

Framework Ưu điểm Nhược điểm
Cypress Dễ dùng, debug tốt Chỉ JS, không multi-tab
Playwright Multi-browser, multi-lang Learning curve
Selenium Mature, nhiều ngôn ngữ Chậm, setup phức tạp
🎭

Playwright

Setup & Test Example

# Install
npm init playwright@latest
// tests/login.spec.js
import { test, expect } from '@playwright/test';

test('user can login', async ({ page }) => {
    await page.goto('https://example.com/login');
    
    await page.fill('[name="email"]', '[email protected]');
    await page.fill('[name="password"]', 'password123');
    await page.click('button[type="submit"]');
    
    await expect(page).toHaveURL('/dashboard');
    await expect(page.locator('.welcome')).toContainText('Welcome');
});
🌲

Cypress

Setup & Test Example

# Install
npm install cypress --save-dev
npx cypress open
// cypress/e2e/login.cy.js
describe('Login', () => {
    it('logs in successfully', () => {
        cy.visit('/login');
        
        cy.get('[name="email"]').type('[email protected]');
        cy.get('[name="password"]').type('password123');
        cy.get('button[type="submit"]').click();
        
        cy.url().should('include', '/dashboard');
        cy.contains('Welcome').should('be.visible');
    });
});
🐍

Selenium + Python

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://example.com/login")

driver.find_element(By.NAME, "email").send_keys("[email protected]")
driver.find_element(By.NAME, "password").send_keys("password123")
driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()

assert "dashboard" in driver.current_url
driver.quit()