0
0
Testing Fundamentalstesting~15 mins

System testing in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify complete system functionality after integration
Preconditions (3)
Step 1: Launch the application
Step 2: Login with valid user credentials: username 'user1', password 'Password123!'
Step 3: Navigate to the dashboard page
Step 4: Create a new record with name 'Test Record' and description 'System test entry'
Step 5: Save the new record
Step 6: Verify the new record appears in the records list
Step 7: Edit the record to change the name to 'Updated Record'
Step 8: Save the changes
Step 9: Verify the updated name appears in the records list
Step 10: Delete the record
Step 11: Confirm the record is removed from the list
Step 12: Logout from the application
✅ Expected Result: The system should allow login, record creation, editing, deletion, and logout without errors. All changes should reflect correctly in the UI.
Automation Requirements - Selenium WebDriver with Python
Assertions Needed:
Verify successful login by checking dashboard URL or welcome message
Verify new record appears in the list after creation
Verify record name updates correctly after editing
Verify record is removed after deletion
Verify logout redirects to login page
Best Practices:
Use explicit waits to handle dynamic page elements
Use Page Object Model to organize locators and actions
Use meaningful and stable locators (id, name, CSS selectors)
Include setup and teardown methods for browser management
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 SystemTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.wait = WebDriverWait(self.driver, 10)

    def test_system_functionality(self):
        driver = self.driver
        wait = self.wait

        # Launch application
        driver.get('https://example.com/login')

        # Login
        wait.until(EC.visibility_of_element_located((By.ID, 'username'))).send_keys('user1')
        driver.find_element(By.ID, 'password').send_keys('Password123!')
        driver.find_element(By.ID, 'login-button').click()

        # Verify dashboard loaded
        wait.until(EC.url_contains('/dashboard'))
        self.assertIn('/dashboard', driver.current_url)

        # Create new record
        wait.until(EC.element_to_be_clickable((By.ID, 'new-record-button'))).click()
        wait.until(EC.visibility_of_element_located((By.ID, 'record-name'))).send_keys('Test Record')
        driver.find_element(By.ID, 'record-description').send_keys('System test entry')
        driver.find_element(By.ID, 'save-record-button').click()

        # Verify new record in list
        record_locator = (By.XPATH, "//table//td[text()='Test Record']")
        wait.until(EC.visibility_of_element_located(record_locator))
        self.assertTrue(driver.find_element(*record_locator).is_displayed())

        # Edit record
        edit_button_locator = (By.XPATH, "//table//td[text()='Test Record']/following-sibling::td/button[@class='edit']")
        driver.find_element(*edit_button_locator).click()
        name_field = wait.until(EC.visibility_of_element_located((By.ID, 'record-name')))
        name_field.clear()
        name_field.send_keys('Updated Record')
        driver.find_element(By.ID, 'save-record-button').click()

        # Verify updated record name
        updated_record_locator = (By.XPATH, "//table//td[text()='Updated Record']")
        wait.until(EC.visibility_of_element_located(updated_record_locator))
        self.assertTrue(driver.find_element(*updated_record_locator).is_displayed())

        # Delete record
        delete_button_locator = (By.XPATH, "//table//td[text()='Updated Record']/following-sibling::td/button[@class='delete']")
        driver.find_element(*delete_button_locator).click()
        # Confirm deletion alert
        alert = wait.until(EC.alert_is_present())
        alert.accept()

        # Verify record removed
        wait.until(EC.invisibility_of_element_located(updated_record_locator))
        elements = driver.find_elements(*updated_record_locator)
        self.assertEqual(len(elements), 0)

        # Logout
        driver.find_element(By.ID, 'logout-button').click()

        # Verify redirected to login
        wait.until(EC.url_contains('/login'))
        self.assertIn('/login', driver.current_url)

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

This test script uses Selenium WebDriver with Python's unittest framework to automate the system test.

setUp: Opens the browser and prepares explicit waits.

test_system_functionality: Automates the manual test steps precisely:

  • Launches the app and logs in with given credentials.
  • Waits for dashboard URL to confirm login success.
  • Creates a new record and verifies it appears in the list.
  • Edits the record's name and verifies the update.
  • Deletes the record and confirms it is removed.
  • Logs out and verifies redirection to login page.

Explicit waits ensure elements are ready before actions, avoiding flaky tests.

Locators use IDs and XPath with stable attributes for reliability.

tearDown: Closes the browser after test completion.

This structure follows best practices for maintainability and clarity.

Common Mistakes - 4 Pitfalls
Using time.sleep() instead of explicit waits
Using brittle XPath locators with absolute paths
Not verifying page state after each action
Not closing the browser after tests
Bonus Challenge

Now add data-driven testing with 3 different user credentials and record data sets

Show Hint