#!/usr/bin/env python3 import random import time from playwright.sync_api import sync_playwright, expect # Constants BASE_URL = "http://100.72.13.62/early_access" LOGIN_URL = f"{BASE_URL}/login" def run_test(): with sync_playwright() as p: # headless=False so you can watch on your monitor browser = p.chromium.launch(headless=False, slow_mo=300) context = browser.new_context(accept_downloads=True) page = context.new_page() # --- 1. PARENT FLOW --- print("Starting Parent Flow...") page.goto(LOGIN_URL) page.fill("input[name='username']", "test005") page.fill("input[name='password']", "test005") page.click("button[type='submit']") expect(page).to_have_url(f"{BASE_URL}/dashboard") # Edit DOB of first athlete new_dob = "2015-01-01" page.locator("input[name='dob']").first.fill(new_dob) page.get_by_role("button", name="Save").first.click() expect(page.locator("input[name='dob']").first).to_have_value(new_dob) # Edit Phone Info page.click("#editInfoBtn") rand_phone = "".join([str(random.randint(0, 9)) for _ in range(10)]) page.fill("#Nphone", rand_phone) page.click("#saveInfoBtn") expect(page.get_by_text(f"Phone: {rand_phone}")).to_be_visible() # Timetable page.goto(f"{BASE_URL}/timetable") page.click("button:has-text('Previous Week')") expect(page).to_have_url(f"{BASE_URL}/timetable?weekOffset=-1") page.click("button:has-text('Next Week')") expect(page).to_have_url(f"{BASE_URL}/timetable?weekOffset=0") # Membership & Fundraising checks #page.goto(f"{BASE_URL}/membership") #expect(page.locator("tr[onclick*='stripe.com']")).to_have_count(1, timeout=5000) page.goto(f"{BASE_URL}/fundraising") expect(page.locator(".fundraising-game").first).to_be_visible() # Competitions page.goto(f"{BASE_URL}/competitions") enter_btn = page.locator("button:has-text('Enter Events')").first expect(enter_btn).to_be_visible() enter_btn.click() page.locator("#athlete-select").select_option(index=1) expect(page.locator("table")).to_be_visible() # Emails page.goto(f"{BASE_URL}/emails") page.locator("tr[onclick*='viewEmail']").first.click() expect(page).to_have_url(re.compile(r".*emails\?page=viewEmail.*")) # Logout page.goto(f"{BASE_URL}/dashboard") page.click("button:has-text('Sign Out')") # --- 2. COACH FLOW --- print("Starting Coach Flow...") page.fill("input[name='username']", "test007") page.fill("input[name='password']", "test007") page.click("button[type='submit']") # Dashboard Table Cell page.locator("td.droppable").first.click() expect(page.locator(".session").first).to_be_visible() page.locator("input[name='location']").first.fill("Test Location") # Check Success Message msg = page.locator("#message-container") expect(msg).to_be_visible() expect(msg).to_have_css("display", "block") # Coach Attendance page.goto(f"{BASE_URL}/coachAttendance") page.click("button:has-text('Previous Week')") expect(page).to_have_url(re.compile(r".*weekOffset=-1")) page.locator("#session-select").select_option(index=1) expect(page).to_have_url(re.compile(r".*id=\d+")) page.click("button:has-text('See Athlete Attendance')") expect(page.locator("#athlete-view")).to_have_css("display", "block") # Session Plans page.goto(f"{BASE_URL}/sessionPlans") page.locator("#session-plan-select").select_option(index=1) test_plan = "Automated Test Plan Text" page.fill("#session-plan", test_plan) page.click("button:has-text('Save Session Plan')") page.locator("#session-plan-select").select_option(index=2) # Switch away page.locator("#session-plan-select").select_option(index=1) # Switch back expect(page.locator("#session-plan")).to_have_value(test_plan) # Logout page.goto(f"{BASE_URL}/coachs-site") page.click("button:has-text('Sign Out')") # --- 3. ADMIN FLOW --- print("Starting Admin Flow...") page.fill("input[name='username']", "test008") page.fill("input[name='password']", "test008") page.click("button[type='submit']") # Pods & Alert page.on("dialog", lambda dialog: dialog.accept()) # Automatically click OK on alerts page.click("button:has-text('Find All Pods')") # Excel Downloads with page.expect_download() as download_info: page.click("button[name='downloadSessionsForm']") download = download_info.value print(f"Downloaded Excel to: {download.path()}") # Dynamic Lists list_name = f"TestList_{random.randint(100,999)}" page.fill("#new_list_name", list_name) page.click("button:has-text('Add New List')") expect(page.locator(f"h3:has-text('{list_name}')")).to_be_visible() # User Phone Edit page.goto(f"{BASE_URL}/users") # 1. Target the specific user row (e.g., test005) # This ensures we are editing the right person user_row = page.locator("tr", has_text="test005") # 2. Click the Edit button inside that specific row user_row.locator(".edit-button").click() # 3. The edit form is in the NEXT row (the sibling) # In your HTML, clicking Edit makes the next