Bird
Raised Fist0
Testing Fundamentalstesting~15 mins

Decision table testing in Testing Fundamentals - Build an Automation Script

Choose your learning style10 modes available
Verify discount calculation using decision table
Preconditions (1)
Step 1: Enter purchase amount as 50
Step 2: Select customer type as 'Regular'
Step 3: Click Calculate Discount button
Step 4: Verify discount is 0
Step 5: Enter purchase amount as 150
Step 6: Select customer type as 'Regular'
Step 7: Click Calculate Discount button
Step 8: Verify discount is 10
Step 9: Enter purchase amount as 50
Step 10: Select customer type as 'Premium'
Step 11: Click Calculate Discount button
Step 12: Verify discount is 5
Step 13: Enter purchase amount as 150
Step 14: Select customer type as 'Premium'
Step 15: Click Calculate Discount button
Step 16: Verify discount is 20
✅ Expected Result: Discount is correctly calculated based on purchase amount and customer type according to the decision table rules.
Automation Requirements - Selenium with Python
Assertions Needed:
Verify discount value displayed matches expected discount for each input combination
Best Practices:
Use explicit waits to wait for elements
Use clear and maintainable locators (id or name preferred)
Separate test data from test logic
Use assertions from unittest or pytest
Structure code for readability
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 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:

  • Finds and fills the purchase amount input.
  • Selects the customer type from dropdown.
  • Clicks the calculate button.
  • Waits for the discount output to appear.
  • Asserts the displayed discount matches the expected value.

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.

Common Mistakes - 4 Pitfalls
Using time.sleep() instead of explicit waits
Using brittle XPath locators with full paths
Hardcoding test data inside test steps
Not clearing input fields before sending keys
Bonus Challenge

Now add data-driven testing with 3 more different purchase amounts and customer types.

Show Hint

Practice

(1/5)
1. What is the main purpose of decision table testing in software testing?
easy
A. To improve software performance
B. To write code faster
C. To design user interfaces
D. To organize conditions and actions to cover all possible cases

Solution

  1. Step 1: Understand decision table testing basics

    Decision table testing helps testers list all conditions and their possible actions systematically.
  2. Step 2: Identify the main goal

    The goal is to cover all possible combinations of conditions to avoid missing or conflicting rules.
  3. Final Answer:

    To organize conditions and actions to cover all possible cases -> Option D
  4. Quick Check:

    Decision table = organize all cases [OK]
Hint: Think of decision tables as a checklist for all condition combos [OK]
Common Mistakes:
  • Confusing decision tables with performance testing
  • Thinking it is about coding speed
  • Mixing it up with UI design
2. Which of the following is the CORRECT way to represent a condition in a decision table?
easy
A. Writing long paragraphs explaining the condition
B. Using 'Yes' or 'No' to show condition states
C. Using random numbers without meaning
D. Ignoring conditions and only listing actions

Solution

  1. Step 1: Review how conditions are shown in decision tables

    Conditions are usually shown as simple states like 'Yes' or 'No' to keep clarity.
  2. Step 2: Eliminate incorrect options

    Long paragraphs or random numbers confuse the table. Ignoring conditions defeats the purpose.
  3. Final Answer:

    Using 'Yes' or 'No' to show condition states -> Option B
  4. Quick Check:

    Conditions = Yes/No states [OK]
Hint: Use simple states like Yes/No for conditions in tables [OK]
Common Mistakes:
  • Writing detailed text instead of simple states
  • Using meaningless numbers
  • Skipping conditions entirely
3. Given the decision table below, what is the expected action if Condition A = No and Condition B = Yes?

Condition ACondition BAction
YesYesAction 1
YesNoAction 2
NoYesAction 3
NoNoAction 4
medium
A. Action 3
B. Action 1
C. Action 2
D. Action 4

Solution

  1. Step 1: Locate the row matching Condition A = No and Condition B = Yes

    Check the table row where Condition A is 'No' and Condition B is 'Yes'.
  2. Step 2: Identify the corresponding action

    The matching row shows 'Action 3' as the action.
  3. Final Answer:

    Action 3 -> Option A
  4. Quick Check:

    Conditions No/Yes = Action 3 [OK]
Hint: Match conditions row to find the correct action quickly [OK]
Common Mistakes:
  • Mixing up Yes/No order
  • Choosing action from wrong row
  • Ignoring one condition
4. A tester created a decision table but missed one condition combination. What is the likely problem caused by this mistake?
medium
A. All conditions are tested anyway
B. The software will run faster
C. Some test cases will be missing, causing incomplete testing
D. The decision table will have duplicate rows

Solution

  1. Step 1: Understand the impact of missing condition combinations

    Missing a condition combo means that scenario is not tested.
  2. Step 2: Identify the consequence

    Incomplete testing can let bugs slip through because not all cases are covered.
  3. Final Answer:

    Some test cases will be missing, causing incomplete testing -> Option C
  4. Quick Check:

    Missing combos = incomplete tests [OK]
Hint: Missing combos mean missing tests, not faster software [OK]
Common Mistakes:
  • Thinking missing combos speed up software
  • Assuming all conditions tested anyway
  • Confusing missing combos with duplicates
5. You have a system with three conditions: C1, C2, and C3, each can be Yes or No. How many unique rules (rows) should a complete decision table have to cover all combinations?
hard
A. 8
B. 12
C. 9
D. 6

Solution

  1. Step 1: Calculate total combinations for three binary conditions

    Each condition has 2 states (Yes/No). Total combinations = 2 * 2 * 2 = 8.
  2. Step 2: Understand decision table rows

    Each unique combination corresponds to one rule (row) in the decision table.
  3. Final Answer:

    8 -> Option A
  4. Quick Check:

    2^3 = 8 rules needed [OK]
Hint: Use 2^number_of_conditions for total rules [OK]
Common Mistakes:
  • Adding conditions instead of multiplying
  • Using wrong powers (like 3^2)
  • Confusing rules with actions
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