Verify discount calculation using decision table
Preconditions (1)
✅ Expected Result: Discount is correctly calculated based on purchase amount and customer type according to the decision table rules.
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 DiscountCalculatorTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://example.com/discount-calculator') self.wait = WebDriverWait(self.driver, 10) def test_discount_calculation(self): test_cases = [ {'amount': '50', 'customer_type': 'Regular', 'expected_discount': '0'}, {'amount': '150', 'customer_type': 'Regular', 'expected_discount': '10'}, {'amount': '50', 'customer_type': 'Premium', 'expected_discount': '5'}, {'amount': '150', 'customer_type': 'Premium', 'expected_discount': '20'} ] for case in test_cases: amount_input = self.wait.until(EC.presence_of_element_located((By.ID, 'purchaseAmount'))) amount_input.clear() amount_input.send_keys(case['amount']) customer_select = self.wait.until(EC.presence_of_element_located((By.ID, 'customerType'))) for option in customer_select.find_elements(By.TAG_NAME, 'option'): if option.text == case['customer_type']: option.click() break calculate_button = self.wait.until(EC.element_to_be_clickable((By.ID, 'calculateBtn'))) calculate_button.click() discount_output = self.wait.until(EC.visibility_of_element_located((By.ID, 'discountValue'))) self.assertEqual(discount_output.text, case['expected_discount'], f"Discount for amount {case['amount']} and customer {case['customer_type']} should be {case['expected_discount']}") def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This test script uses Selenium with Python's unittest framework to automate the discount calculator page.
In setUp, the browser opens the page and sets an explicit wait.
The test_discount_calculation method loops through all decision table cases. For each case, it:
Explicit waits ensure elements are ready before interacting.
Locators use IDs for clarity and maintainability.
The test data is separated in a list for easy updates.
Finally, tearDown closes the browser after tests.
Now add data-driven testing with 3 more different purchase amounts and customer types.
decision table testing in software testing?| Condition A | Condition B | Action |
|---|---|---|
| Yes | Yes | Action 1 |
| Yes | No | Action 2 |
| No | Yes | Action 3 |
| No | No | Action 4 |
Pass the test and this pattern moves unknown