Automated Testing Lab Manual
1. Introduction to Automated Testing
2. Environment Setup
3. Writing Test Cases
4. Executing Test Cases
5. Advanced Testing Techniques
1. Introduction to Automated Testing
Objective:
To understand the basics of automated testing and its importance in software
development.
Key Concepts:
• Automated Testing: A process of using tools to execute pre-scripted tests on
software.
• Types of Automated Testing: Unit, Integration, Regression, System Testing.
• Benefits:
o Saves time compared to manual testing.
o Increases accuracy by reducing human error.
o Enables continuous testing in CI/CD pipelines.
• Tools: Selenium, JUnit, TestNG, Cypress.
2. Environment Setup
Objective:
To set up the necessary tools and frameworks for automated testing.
Tools Required:
1. Programming Language: Python or Java.
2. IDE: Visual Studio Code, PyCharm, or IntelliJ IDEA.
3. Testing Tool: Selenium WebDriver.
4. Browser Drivers: ChromeDriver or GeckoDriver (for Firefox).
Step-by-Step Instructions:
1. Install Python or Java:
o Download Python from python.org or Java from java.com.
2. Install an IDE:
o Download Visual Studio Code (code.visualstudio.com) or PyCharm
(jetbrains.com).
3. Install Selenium WebDriver (for Python):
o Open the terminal/command prompt and run:
pip install selenium
4. Download ChromeDriver:
o Visit chromedriver.chromium.org and download the version matching your
Chrome browser.
5. Verify Installation:
o Open your IDE and write the following script to check Selenium:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
print("Selenium setup successful!")
driver.quit()
3. Writing Test Cases
Objective:
To create and execute automated test scripts.
Step-by-Step Instructions:
1. Basic Script for Login Testing:
o Open your IDE and create a new Python file (e.g., login_test.py).
o Copy and paste the following code:
from selenium import webdriver
from selenium.webdriver.common.by import By
# Setup WebDriver
driver = webdriver.Chrome()
driver.get("https://example.com/login")
# Perform login
driver.find_element(By.ID, "username").send_keys("test_user")
driver.find_element(By.ID, "password").send_keys("password123")
driver.find_element(By.ID, "loginButton").click()
# Verify login success
assert "Dashboard" in driver.title, "Login failed!"
print("Login test executed successfully!")
driver.quit()
2. Exercise:
o Modify the script to perform login on a different website.
o Add a test case for invalid credentials.
4. Test Execution
Objective:
To execute automated test cases and analyze the results.
Step-by-Step Instructions:
1. Run the Test Case:
o Open a terminal in the IDE and navigate to the file location.
o Execute the script by typing:
python login_test.py
2. Analyze Results:
o Check for any assertion failures or errors in the console output.
3. Exercise:
o Add print statements to log each step.
o Write a test to verify the presence of a specific element on the webpage.
5. Advanced Testing Techniques
Objective:
To learn data-driven testing and error handling.
Step-by-Step Instructions:
1. Data-Driven Testing using CSV:
o Create a file test_data.csv with the following content:
username,password
test_user1,password1
test_user2,password2
o Update your Python script:
import csv
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
# Open the CSV file
with open('test_data.csv', 'r') as file:
reader = csv.DictReader(file)
for row in reader:
driver.get("https://example.com/login")
driver.find_element(By.ID, "username").send_keys(row['username'])
driver.find_element(By.ID, "password").send_keys(row['password'])
driver.find_element(By.ID, "loginButton").click()
print(f"Test executed for user: {row['username']}")
driver.quit()
2. Handling Exceptions:
o Add try-except blocks to handle errors:
try:
driver.find_element(By.ID, "loginButton").click()
except Exception as e:
print(f"Error: {e}")
3. Exercise:
o Write a test script to test multiple inputs for a search bar.