|
| 1 | +import pytest |
| 2 | +from selenium.webdriver.common.by import By |
| 3 | +from selenium.webdriver.support.ui import WebDriverWait |
| 4 | +from selenium.webdriver.support import expected_conditions as EC |
| 5 | + |
| 6 | +BASE_URL = "https://finstack-alpha.vercel.app" |
| 7 | + |
| 8 | + |
| 9 | +def test_e2e_login_and_add_expense_transaction(driver): |
| 10 | + """T001: E2E: Login and Add an Expense Transaction""" |
| 11 | + |
| 12 | + wait = WebDriverWait(driver, 30) |
| 13 | + |
| 14 | + # Step 1: Navigate to login page |
| 15 | + driver.get(f"{BASE_URL}/login") |
| 16 | + wait.until(EC.visibility_of_element_located((By.ID, "sign_in"))) |
| 17 | + |
| 18 | + # Step 2: Enter email |
| 19 | + driver.find_element(By.ID, "email").send_keys("testuser@bstackbank.com") |
| 20 | + |
| 21 | + # Step 3: Enter password |
| 22 | + driver.find_element(By.ID, "password").send_keys("Test@1234") |
| 23 | + |
| 24 | + # Step 4: Click Sign In and wait for dashboard |
| 25 | + driver.find_element(By.ID, "sign_in").click() |
| 26 | + wait.until(EC.url_contains("/dashboard")) |
| 27 | + wait.until(EC.visibility_of_element_located( |
| 28 | + (By.XPATH, "//h1[contains(text(), 'Good morning')]") |
| 29 | + )) |
| 30 | + |
| 31 | + # Step 5: Click '+ Add Transaction' button |
| 32 | + add_btn = wait.until(EC.element_to_be_clickable( |
| 33 | + (By.XPATH, "//button[normalize-space()='Add Transaction']") |
| 34 | + )) |
| 35 | + add_btn.click() |
| 36 | + wait.until(EC.visibility_of_element_located( |
| 37 | + (By.CSS_SELECTOR, "[data-slot='dialog-content']") |
| 38 | + )) |
| 39 | + |
| 40 | + # Step 6: Enter amount |
| 41 | + amount_field = wait.until(EC.visibility_of_element_located((By.ID, "amount"))) |
| 42 | + amount_field.clear() |
| 43 | + amount_field.send_keys("150.00") |
| 44 | + |
| 45 | + # Step 7: Enter description |
| 46 | + driver.find_element(By.ID, "description").send_keys("Grocery Shopping") |
| 47 | + |
| 48 | + # Step 8 & 9: Select Category → Food & Dining |
| 49 | + category_btn = driver.find_element( |
| 50 | + By.XPATH, |
| 51 | + "//div[contains(@class,'grid') and contains(@class,'gap-2') and .//text()[contains(.,'Category')]]//button[contains(@class,'border-input')]" |
| 52 | + ) |
| 53 | + category_btn.click() |
| 54 | + wait.until(EC.element_to_be_clickable( |
| 55 | + (By.XPATH, "//div[@role='option' and normalize-space()='Food & Dining']") |
| 56 | + )).click() |
| 57 | + |
| 58 | + # Step 10 & 11: Select Account → Main Checking |
| 59 | + account_btn = driver.find_element( |
| 60 | + By.XPATH, |
| 61 | + "//div[contains(@class,'grid') and contains(@class,'gap-2') and .//text()[contains(.,'Account')]]//button[contains(@class,'border-input')]" |
| 62 | + ) |
| 63 | + account_btn.click() |
| 64 | + wait.until(EC.element_to_be_clickable( |
| 65 | + (By.XPATH, "//div[@role='option' and normalize-space()='Main Checking']") |
| 66 | + )).click() |
| 67 | + |
| 68 | + # Step 12: Submit the transaction — scoped inside the dialog to avoid matching the header button |
| 69 | + submit_btn = wait.until(EC.element_to_be_clickable( |
| 70 | + (By.XPATH, "//*[@data-slot='dialog-content']//button[normalize-space()='Add Transaction']") |
| 71 | + )) |
| 72 | + driver.execute_script("arguments[0].scrollIntoView(true);", submit_btn) |
| 73 | + driver.execute_script("arguments[0].click();", submit_btn) |
| 74 | + |
| 75 | + # Step 13: Verify modal closes and dashboard is shown |
| 76 | + wait.until(EC.invisibility_of_element_located( |
| 77 | + (By.CSS_SELECTOR, "[data-slot='dialog-content']") |
| 78 | + )) |
| 79 | + wait.until(EC.visibility_of_element_located( |
| 80 | + (By.XPATH, "//h1[contains(text(), 'Good morning')]") |
| 81 | + )) |
0 commit comments