Testing in Scrum sprints 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 FeatureTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://test-environment.example.com/feature') self.wait = WebDriverWait(self.driver, 10) def test_feature_functionality(self): driver = self.driver wait = self.wait # Wait for feature page main element to load main_element = wait.until(EC.visibility_of_element_located((By.ID, 'feature-main'))) self.assertTrue(main_element.is_displayed(), 'Feature main element should be visible') # Perform main action: fill input and submit input_field = driver.find_element(By.ID, 'input-data') input_field.clear() input_field.send_keys('Test data') submit_button = driver.find_element(By.ID, 'submit-btn') submit_button.click() # Wait for success message success_msg = wait.until(EC.visibility_of_element_located((By.ID, 'success-msg'))) self.assertEqual(success_msg.text, 'Submission successful', 'Success message should appear') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This test script uses Selenium with Python's unittest framework to automate the manual test case.
setUp() opens the browser and navigates to the feature page in the test environment.
The test test_feature_functionality waits explicitly for the main feature element to appear to ensure the page loaded correctly.
It then fills the input field with test data and clicks the submit button to perform the main action.
After submission, it waits for the success message and asserts that the message text matches the expected result.
tearDown() closes the browser after the test.
This structure follows best practices: explicit waits avoid timing issues, clear assertions verify expected outcomes, and the code is easy to read and maintain.
Now add data-driven testing with 3 different input values for the feature input field.