Pair testing in Testing Fundamentals - Build an Automation Script
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class TestLogin(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') self.wait = WebDriverWait(self.driver, 10) def login(self, email, password): email_field = self.wait.until(EC.presence_of_element_located((By.ID, 'email'))) password_field = self.driver.find_element(By.ID, 'password') login_button = self.driver.find_element(By.ID, 'loginBtn') email_field.clear() email_field.send_keys(email) password_field.clear() password_field.send_keys(password) login_button.click() def test_valid_login(self): self.login('user@example.com', 'Password123') self.wait.until(EC.url_contains('/dashboard')) self.assertIn('/dashboard', self.driver.current_url) def test_invalid_email_format(self): self.login('userexample.com', 'Password123') error = self.wait.until(EC.visibility_of_element_located((By.ID, 'emailError'))) self.assertEqual(error.text, 'Please enter a valid email address.') def test_empty_password(self): self.login('user@example.com', '') error = self.wait.until(EC.visibility_of_element_located((By.ID, 'passwordError'))) self.assertEqual(error.text, 'Password cannot be empty.') def test_wrong_password(self): self.login('user@example.com', 'WrongPass') error = self.wait.until(EC.visibility_of_element_located((By.ID, 'loginError'))) self.assertEqual(error.text, 'Incorrect email or password.') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This test script uses Selenium with Python's unittest framework to automate the login tests.
setUp: Opens the browser and navigates to the login page before each test.
login method: Enters email and password, then clicks login.
test_valid_login: Checks that after valid login, URL contains '/dashboard'.
test_invalid_email_format: Checks error message for invalid email format.
test_empty_password: Checks error message when password is empty.
test_wrong_password: Checks error message for wrong password.
tearDown: Closes the browser after each test.
Explicit waits ensure elements are ready before interaction. Assertions verify expected results. Locators use IDs for clarity and maintainability.
Now add data-driven testing with 3 different sets of login credentials (valid, invalid email, wrong password).
Practice
pair testing in software testing?Solution
Step 1: Understand the definition of pair testing and compare options
Pair testing means two testers work together on one device to collaborate closely. "Two testers work together on one device to find bugs faster." correctly describes this.Final Answer:
Two testers work together on one device to find bugs faster. -> Option CQuick Check:
Pair testing = Two testers, one device [OK]
- Thinking testers work separately in pair testing
- Confusing pair testing with pair programming
- Assuming testers test different features independently
Solution
Step 1: Recall role behavior in pair testing and match options
In pair testing, testers switch roles often to stay active and share knowledge. "Testers switch roles often to keep both active and engaged." correctly states this.Final Answer:
Testers switch roles often to keep both active and engaged. -> Option AQuick Check:
Role switching = Active testers [OK]
- Assuming one tester is passive
- Thinking testers work independently
- Confusing pair testing with bug fixing roles
Solution
Step 1: Analyze the pair testing scenario and identify the benefit
Tester A inputs data, Tester B observes and suggests test cases, showing collaboration. This helps find bugs faster and shares knowledge between testers.Final Answer:
It helps find bugs faster and shares knowledge between testers. -> Option DQuick Check:
Pair testing benefit = Faster bugs + knowledge sharing [OK]
- Thinking it reduces test cases
- Believing only one tester is responsible
- Assuming testers work on different features
Solution
Step 1: Identify the issue in pair testing and its impact
One tester always controls the device, meaning roles are not switching often. This reduces engagement and knowledge sharing.Final Answer:
The testers are not switching roles often, reducing engagement. -> Option AQuick Check:
No role switching = Low engagement [OK]
- Blaming the device instead of process
- Suggesting independent work in pair testing
- Confusing testing roles with coding roles
Solution
Step 1: Identify key pair testing principles and evaluate options
Pair testing: two testers on one device, switch roles often, share knowledge. "Assign two testers to work together on one device, switching roles every 15 minutes, discussing findings continuously." matches all.Final Answer:
Assign two testers to work together on one device, switching roles every 15 minutes, discussing findings continuously. -> Option BQuick Check:
Pair testing best practice = Together + switch roles + discuss [OK]
- Testing separately instead of together
- Not switching roles during testing
- Ignoring communication between testers
Ready to prove it?
Pass the test and this pattern moves unknown
