Bird
Raised Fist0
Testing Fundamentalstesting~15 mins

Tester mindset and thinking in Testing Fundamentals - Build an Automation Script

Choose your learning style10 modes available
Verify login functionality with valid and invalid inputs
Preconditions (1)
Step 1: Enter a valid email 'user@example.com' in the email field
Step 2: Enter a valid password 'Password123!' in the password field
Step 3: Click the Login button
Step 4: Verify that the user is redirected to the dashboard page
Step 5: Logout to return to the login page
Step 6: Enter an invalid email 'invalidemail' in the email field
Step 7: Enter a password 'Password123!' in the password field
Step 8: Click the Login button
Step 9: Verify that an error message 'Please enter a valid email address' is displayed
Step 10: Enter a valid email 'user@example.com' in the email field
Step 11: Leave the password field empty
Step 12: Click the Login button
Step 13: Verify that an error message 'Password cannot be empty' is displayed
✅ Expected Result: The login succeeds with valid credentials and redirects to dashboard. Appropriate error messages appear for invalid email and empty password.
Automation Requirements - Selenium with Python
Assertions Needed:
Verify current URL is dashboard URL after successful login
Verify error message text for invalid email
Verify error message text for empty password
Best Practices:
Use explicit waits to wait for elements to be visible or clickable
Use descriptive and stable locators (id or name attributes preferred)
Separate test logic and page locators using Page Object Model
Use assertions with clear messages
Clean up by logging out after successful login
Automated Solution
Testing Fundamentals
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.

Common Mistakes - 4 Pitfalls
Using hardcoded sleep (time.sleep) instead of explicit waits
Using brittle XPath locators that break easily
Mixing test logic and locators in the test method
Not cleaning up after tests (e.g., not logging out)
Bonus Challenge

Now add data-driven testing with 3 different sets of email and password inputs (valid, invalid email, empty password).

Show Hint

Practice

(1/5)
1. What is the main goal of having a tester mindset?
easy
A. To manage the project timeline
B. To write code faster than developers
C. To design the software architecture
D. To think like a user and find problems in the software

Solution

  1. Step 1: Understand the tester mindset purpose

    The tester mindset focuses on thinking like a user and looking for bugs or issues.
  2. 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.
  3. Final Answer:

    To think like a user and find problems in the software -> Option D
  4. Quick Check:

    Tester mindset = find problems like a user [OK]
Hint: Tester mindset = think like user, find bugs fast [OK]
Common Mistakes:
  • Confusing tester mindset with coding skills
  • Thinking tester mindset is about project management
  • Assuming tester mindset means designing software
2. Which of the following is the correct way to write a test case title?
easy
A. Test login with valid username and password
B. loginTest123
C. Check if login works
D. TestCase1

Solution

  1. 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.
  2. Step 2: Evaluate other options for clarity

    The other options are vague or use unclear naming, not best practice.
  3. Final Answer:

    Test login with valid username and password -> Option A
  4. Quick Check:

    Clear descriptive title = Test login with valid username and password [OK]
Hint: Test case title should clearly describe the test [OK]
Common Mistakes:
  • Using vague or generic titles
  • Including technical jargon in titles
  • Using non-descriptive codes or numbers
3. Consider this test scenario: A user tries to submit a form with an empty required field. What should the tester expect?
medium
A. An error message appears asking to fill the required field.
B. The page reloads without any message.
C. The form submits successfully without errors.
D. The form clears all entered data automatically.

Solution

  1. Step 1: Understand form validation rules

    Required fields must be filled; empty submission should trigger an error.
  2. 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.
  3. Final Answer:

    An error message appears asking to fill the required field. -> Option A
  4. Quick Check:

    Empty required field = error message [OK]
Hint: Empty required field triggers error message [OK]
Common Mistakes:
  • Expecting form to submit without validation
  • Assuming page reloads silently
  • Thinking form clears data automatically
4. You wrote a test case but it always passes even when the feature is broken. What is the most likely problem?
medium
A. The feature is actually working fine.
B. The test case is missing assertions to check results.
C. The test environment is down.
D. The test case has too many steps.

Solution

  1. Step 1: Analyze why test always passes despite broken feature

    If a test passes wrongly, it likely lacks proper checks (assertions).
  2. Step 2: Evaluate other options

    Feature broken means B is false; environment down or too many steps don't cause false passes.
  3. Final Answer:

    The test case is missing assertions to check results. -> Option B
  4. Quick Check:

    Missing assertions cause false passes [OK]
Hint: Always include assertions to verify expected results [OK]
Common Mistakes:
  • Assuming feature is fine without checking
  • Ignoring missing assertions
  • Blaming environment without evidence
5. You want to test a login form thoroughly. Which approach best shows a tester mindset?
hard
A. Test only the UI layout without entering data.
B. Test only valid username and password combinations.
C. Test valid, invalid, empty, and boundary inputs to find issues.
D. Test by asking developers if the form works.

Solution

  1. Step 1: Understand thorough testing from tester mindset

    Tester mindset means being curious and testing many scenarios, including edge cases.
  2. 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.
  3. Final Answer:

    Test valid, invalid, empty, and boundary inputs to find issues. -> Option C
  4. Quick Check:

    Test many scenarios = Test valid, invalid, empty, and boundary inputs to find issues. [OK]
Hint: Test many input types, not just happy paths [OK]
Common Mistakes:
  • Testing only valid inputs
  • Ignoring boundary or empty inputs
  • Relying on developers' word only
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard