31SeleniumAutomationSelenium
What is Selenium and what are its components?
Selenium is an open-source automation testing framework used for automating web applications across different browsers and platforms.
Selenium Components
1. Selenium WebDriver:
- Core component for browser automation
- Directly communicates with browsers
- Supports multiple programming languages (Java, Python, C#, JavaScript)
- Supports multiple browsers (Chrome, Firefox, Safari, Edge)
- Most widely used component
2. Selenium IDE:
- Browser extension for record and playback
- Good for quick prototyping
- Limited functionality compared to WebDriver
- Available for Chrome and Firefox
3. Selenium Grid:
- Enables parallel test execution
- Runs tests on multiple machines simultaneously
- Supports different browsers and OS combinations
- Reduces test execution time
Key Features of Selenium
- Open-source and free
- Cross-browser testing support
- Multiple programming language support
- Integration with testing frameworks (TestNG, JUnit, pytest)
- Large community and extensive documentation
- CI/CD integration support
Basic Selenium WebDriver Example (Python)
from selenium import webdriver
from selenium.webdriver.common.by import By
# Initialize driver
driver = webdriver.Chrome()
# Navigate to URL
driver.get("https://example.com")
# Find element and interact
element = driver.find_element(By.ID, "username")
element.send_keys("testuser")
# Click button
driver.find_element(By.ID, "login").click()
# Close browser
driver.quit()
When to Use Selenium
- Web application testing
- Cross-browser compatibility testing
- Regression testing
- Data-driven testing
- Continuous integration pipelines