Tester mindset and thinking 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, 'loginBtn') self.error_message = (By.ID, 'errorMsg') def enter_email(self, email): WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.email_input)).clear() self.driver.find_element(*self.email_input).send_keys(email) def enter_password(self, password): WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.password_input)).clear() self.driver.find_element(*self.password_input).send_keys(password) def click_login(self): WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(self.login_button)).click() def get_error_message(self): return WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.error_message)).text class DashboardPage: def __init__(self, driver): self.driver = driver self.logout_button = (By.ID, 'logoutBtn') def click_logout(self): WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(self.logout_button)).click() class TestLogin(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') self.login_page = LoginPage(self.driver) self.dashboard_page = DashboardPage(self.driver) def tearDown(self): self.driver.quit() def test_login_valid_and_invalid(self): # Valid login self.login_page.enter_email('user@example.com') self.login_page.enter_password('Password123!') self.login_page.click_login() WebDriverWait(self.driver, 10).until(EC.url_contains('/dashboard')) self.assertIn('/dashboard', self.driver.current_url, 'Failed to navigate to dashboard after login') # Logout self.dashboard_page.click_logout() WebDriverWait(self.driver, 10).until(EC.url_contains('/login')) # Invalid email self.login_page.enter_email('invalidemail') self.login_page.enter_password('Password123!') self.login_page.click_login() error_text = self.login_page.get_error_message() self.assertEqual(error_text, 'Please enter a valid email address', 'Incorrect error message for invalid email') # Empty password self.login_page.enter_email('user@example.com') self.login_page.enter_password('') self.login_page.click_login() error_text = self.login_page.get_error_message() self.assertEqual(error_text, 'Password cannot be empty', 'Incorrect error message for empty password') if __name__ == '__main__': unittest.main()
The code uses Selenium WebDriver with Python's unittest framework to automate the login test case.
We define Page Object Model classes LoginPage and DashboardPage to keep locators and actions organized.
Explicit waits ensure elements are ready before interacting, avoiding flaky tests.
The test method test_login_valid_and_invalid covers all manual test steps: valid login, logout, invalid email, and empty password cases.
Assertions check the URL after login and verify error messages for invalid inputs with clear messages.
Setup and teardown methods open and close the browser cleanly for each test run.
Now add data-driven testing with 3 different sets of email and password inputs (valid, invalid email, empty password).
Practice
Solution
Step 1: Understand the tester mindset purpose
The tester mindset focuses on thinking like a user and looking for bugs or issues.Step 2: Compare options with this purpose
Only To think like a user and find problems in the software matches this goal; others relate to coding, design, or management, not testing mindset.Final Answer:
To think like a user and find problems in the software -> Option DQuick Check:
Tester mindset = find problems like a user [OK]
- Confusing tester mindset with coding skills
- Thinking tester mindset is about project management
- Assuming tester mindset means designing software
Solution
Step 1: Identify clear and descriptive test case titles
A good test case title clearly describes what is tested, like Test login with valid username and password.Step 2: Evaluate other options for clarity
The other options are vague or use unclear naming, not best practice.Final Answer:
Test login with valid username and password -> Option AQuick Check:
Clear descriptive title = Test login with valid username and password [OK]
- Using vague or generic titles
- Including technical jargon in titles
- Using non-descriptive codes or numbers
Solution
Step 1: Understand form validation rules
Required fields must be filled; empty submission should trigger an error.Step 2: Match expected behavior with options
Only An error message appears asking to fill the required field. describes the correct behavior: showing an error message.Final Answer:
An error message appears asking to fill the required field. -> Option AQuick Check:
Empty required field = error message [OK]
- Expecting form to submit without validation
- Assuming page reloads silently
- Thinking form clears data automatically
Solution
Step 1: Analyze why test always passes despite broken feature
If a test passes wrongly, it likely lacks proper checks (assertions).Step 2: Evaluate other options
Feature broken means B is false; environment down or too many steps don't cause false passes.Final Answer:
The test case is missing assertions to check results. -> Option BQuick Check:
Missing assertions cause false passes [OK]
- Assuming feature is fine without checking
- Ignoring missing assertions
- Blaming environment without evidence
Solution
Step 1: Understand thorough testing from tester mindset
Tester mindset means being curious and testing many scenarios, including edge cases.Step 2: Compare options for coverage
Test valid, invalid, empty, and boundary inputs to find issues. covers valid, invalid, empty, and boundary inputs, showing thoroughness.Final Answer:
Test valid, invalid, empty, and boundary inputs to find issues. -> Option CQuick Check:
Test many scenarios = Test valid, invalid, empty, and boundary inputs to find issues. [OK]
- Testing only valid inputs
- Ignoring boundary or empty inputs
- Relying on developers' word only
Ready to prove it?
Pass the test and this pattern moves unknown
