Preorder Validation UI Automation
Automation Scope
Focused UI automation for Preorder creation with credit limit validation and automatic deduction on CREDIT payment.
Feature File (features/preorder_credit.feature)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Feature: Preorder Creation with Credit Limit Validation
Background:
Given user is logged in as Sales user
And customer "CUST-DEMO-078" has available credit limit of Rp 8000000
Scenario: Successfully create Preorder with CREDIT and credit limit deduction
When user creates Preorder with the following details:
| customer | product | quantity |
| CUST-DEMO-078 | PROD-001 | 8 |
And selects payment method "CREDIT"
Then Preorder should be created successfully with status "SUBMITTED"
And available credit limit should be deducted by the final total
Scenario: Preorder blocked when credit limit is insufficient
Given customer has available credit limit of Rp 2000000
When user creates Preorder with quantity 10 using "CREDIT"
Then Preorder should be blocked
And credit limit exceeded warning should be displayed
Page Object Model (pages/preorder_page.py)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class PreorderPage:
def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(driver, 10)
self.customer_search = (By.ID, "customer-search")
self.product_search = (By.ID, "product-search")
self.quantity_input = (By.NAME, "quantity")
self.payment_method_select = (By.ID, "payment-method")
self.submit_button = (By.CSS_SELECTOR, "[data-testid='submit-preorder']")
self.final_total = (By.CSS_SELECTOR, "[data-testid='final-total']")
self.order_status = (By.CSS_SELECTOR, "[data-testid='order-status']")
self.credit_warning = (By.CSS_SELECTOR, "[data-testid='credit-limit-alert']")
self.remaining_credit = (By.CSS_SELECTOR, "[data-testid='remaining-credit']")
def create_preorder(self, customer, product, quantity):
self.driver.find_element(*self.customer_search).send_keys(customer)
self.driver.find_element(*self.product_search).send_keys(product)
self.driver.find_element(*self.quantity_input).send_keys(str(quantity))
self.driver.find_element(*self.submit_button).click()
def select_payment_method(self, method):
self.driver.find_element(*self.payment_method_select).send_keys(method)
def get_order_status(self):
element = self.wait.until(EC.visibility_of_element_located(self.order_status))
return element.text
def is_credit_warning_displayed(self):
try:
return self.wait.until(EC.visibility_of_element_located(self.credit_warning)).is_displayed()
except Exception:
return False
Step Definitions (features/steps/preorder_steps.py)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from behave import when, then
from pages.preorder_page import PreorderPage
@when("user creates Preorder with the following details:")
def step_create_preorder(context):
row = context.table[0]
context.page = PreorderPage(context.driver)
context.page.create_preorder(row["customer"], row["product"], row["quantity"])
@when('selects payment method "{method}"')
def step_select_payment(context, method):
context.page.select_payment_method(method)
@then('Preorder should be created successfully with status "{status}"')
def step_verify_status(context, status):
assert context.page.get_order_status() == status
@then("available credit limit should be deducted by the final total")
def step_verify_deduction(context):
# Assertion + API/DB check recommended.
pass
@then("credit limit exceeded warning should be displayed")
def step_verify_warning(context):
assert context.page.is_credit_warning_displayed()