Error guessing 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 LoginPage: def __init__(self, driver): self.driver = driver self.email_input = (By.ID, 'email') self.password_input = (By.ID, 'password') self.login_button = (By.ID, 'login-btn') self.error_message = (By.ID, 'error-msg') def enter_email(self, email): self.driver.find_element(*self.email_input).clear() self.driver.find_element(*self.email_input).send_keys(email) def enter_password(self, password): self.driver.find_element(*self.password_input).clear() self.driver.find_element(*self.password_input).send_keys(password) def click_login(self): self.driver.find_element(*self.login_button).click() def get_error_message(self): wait = WebDriverWait(self.driver, 10) error_element = wait.until(EC.visibility_of_element_located(self.error_message)) return error_element.text class TestLoginErrorGuessing(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') self.login_page = LoginPage(self.driver) def tearDown(self): self.driver.quit() def test_invalid_email_format(self): self.login_page.enter_email('user@@example.com') self.login_page.enter_password('Password123!') self.login_page.click_login() error = self.login_page.get_error_message() self.assertEqual(error, 'Invalid email format', 'Error message for invalid email is incorrect') def test_empty_password(self): self.login_page.enter_email('user@example.com') self.login_page.enter_password('') self.login_page.click_login() error = self.login_page.get_error_message() self.assertEqual(error, 'Password cannot be empty', 'Error message for empty password is incorrect') def test_short_password(self): self.login_page.enter_email('user@example.com') self.login_page.enter_password('123') self.login_page.click_login() error = self.login_page.get_error_message() self.assertEqual(error, 'Password too short', 'Error message for short password is incorrect') if __name__ == '__main__': unittest.main()
This test script uses Selenium WebDriver with Python's unittest framework.
The LoginPage class follows the Page Object Model. It stores locators and methods to interact with the login page elements. This keeps the test code clean and easy to maintain.
Each test method performs one error guessing scenario by entering invalid inputs and clicking the login button.
Explicit waits are used to wait for the error message to appear before reading its text. This avoids flaky tests.
Assertions check that the error messages shown match the expected text for each invalid input.
The setup and teardown methods open and close the browser for each test, ensuring a fresh start.
This approach follows best practices like using descriptive locators, explicit waits, and clear assertion messages.
Now add data-driven testing with 3 different invalid input sets for email and password
Practice
Error guessing in software testing?Solution
Step 1: Understand the concept of error guessing
Error guessing is a technique where testers use their experience to predict where bugs might be.Step 2: Compare options with the concept
Only Guessing where errors might occur based on experience matches the idea of using experience to guess errors, others describe different testing methods.Final Answer:
Guessing where errors might occur based on experience -> Option CQuick Check:
Error guessing = Experience-based bug prediction [OK]
- Confusing error guessing with automated testing
- Thinking error guessing ignores tester knowledge
- Believing error guessing is random testing
Solution
Step 1: Identify error guessing test case traits
Error guessing focuses on inputs or actions likely to cause errors, like empty fields.Step 2: Evaluate each option
Test input with empty fields to check validation tests empty input, a common error source. Others are unrelated or random.Final Answer:
Test input with empty fields to check validation -> Option DQuick Check:
Empty input tests = Error guessing [OK]
- Choosing tests unrelated to error conditions
- Confusing UI checks with error guessing
- Selecting random or unplanned tests
Solution
Step 1: Identify inputs likely to cause errors
Empty username and password fields often cause validation errors.Step 2: Compare options for error likelihood
Username: '', Password: '' uses empty inputs, which is a common error guess. Others are normal inputs.Final Answer:
Username: '', Password: '' -> Option BQuick Check:
Empty inputs = Common error guess [OK]
- Choosing normal valid inputs
- Ignoring empty or boundary inputs
- Assuming random inputs are best
Solution
Step 1: Understand error guessing effectiveness
Error guessing works best when testers guess likely error spots based on experience.Step 2: Analyze why tests fail to find bugs
If guesses are in unlikely places, bugs won't be found. Other options don't explain this well.Final Answer:
You guessed errors in unlikely places -> Option AQuick Check:
Wrong guess spots = No bugs found [OK]
- Thinking more tests always find more bugs
- Believing automation replaces error guessing
- Focusing on UI style instead of error sources
Solution
Step 1: Identify error-prone inputs for calculator
Calculators often fail with large numbers, zero, or division by zero.Step 2: Evaluate options for error guessing effectiveness
Very large numbers, zero, and dividing by zero targets these error-prone inputs, while others do not or are invalid inputs.Final Answer:
Very large numbers, zero, and dividing by zero -> Option AQuick Check:
Edge and invalid inputs = Best error guesses [OK]
- Testing only normal inputs
- Ignoring division by zero errors
- Using completely invalid inputs without context
Ready to prove it?
Pass the test and this pattern moves unknown
