-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_admin_browser_use.py
More file actions
146 lines (119 loc) Β· 5.77 KB
/
test_admin_browser_use.py
File metadata and controls
146 lines (119 loc) Β· 5.77 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
Admin E2E Testing using browser-use
Tests all admin sub-pages and functional operations
"""
import asyncio
from browser_use import Agent
from playwright.async_playwright import async_playwright
BASE_URL = "https://timorup.jasonwill.workers.dev"
ADMIN_EMAIL = "admin@timorup.com"
ADMIN_PASSWORD = "admin12345"
async def test_admin_pages():
"""Test all admin sub-pages"""
print("π Starting Admin E2E Tests with browser-use\n")
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True)
context = await browser.new_context()
page = await context.new_page()
try:
# Step 1: Login
print("π Step 1: Logging in as admin...")
await page.goto(f"{BASE_URL}/login", wait_until="networkidle")
await page.wait_for_timeout(2000)
# Fill login form
await page.fill('input[name="email"]', ADMIN_EMAIL)
await page.fill('input[name="password"]', ADMIN_PASSWORD)
await page.click('#submit-btn')
await page.wait_for_timeout(3000)
url_after_login = page.url
print(f" After login URL: {url_after_login}")
# Check cookies
cookies = await context.cookies()
print(f" Cookies set: {len(cookies)}")
# Step 2: Test all admin pages
admin_pages = [
"/admin",
"/admin/dashboard",
"/admin/businesses",
"/admin/listings",
"/admin/listings/new",
"/admin/non-profits",
"/admin/public-sectors",
"/admin/categories",
"/admin/heroes",
"/admin/blogs",
"/admin/media",
"/admin/users",
"/admin/reviews",
"/admin/service-packages",
"/admin/subscriptions",
"/admin/settings",
"/admin/ai-tools"
]
print("\nπ Testing all admin pages...")
results = []
for path in admin_pages:
try:
await page.goto(f"{BASE_URL}{path}", wait_until="networkidle", timeout=15000)
await page.wait_for_timeout(1000)
title = await page.title()
body_text = await page.text_content("body")
has_error = "[object Object]" in body_text
is_login = "login" in title.lower()
results.append({
"path": path,
"title": title,
"has_error": has_error,
"requires_login": is_login
})
status = "β" if has_error else "π" if is_login else "β"
print(f" {status} {path} - {title[:50]}")
except Exception as e:
print(f" β {path} - Error: {str(e)[:50]}")
results.append({"path": path, "error": str(e)})
# Step 3: Test interactive elements
print("\nπ±οΈ Testing interactive elements...")
interactive_pages = [
"/admin/businesses",
"/admin/categories",
"/admin/heroes"
]
for path in interactive_pages:
try:
await page.goto(f"{BASE_URL}{path}", wait_until="networkidle", timeout=15000)
await page.wait_for_timeout(1000)
buttons = await page.query_selector_all("button")
inputs = await page.query_selector_all("input")
forms = await page.query_selector_all("form")
print(f" π {path}:")
print(f" - Buttons: {len(buttons)}")
print(f" - Inputs: {len(inputs)}")
print(f" - Forms: {len(forms)}")
# Try clicking first button
if buttons:
btn_text = await buttons[0].text_content()
try:
await buttons[0].click()
await page.wait_for_timeout(1000)
print(f" - Clicked button: '{btn_text.strip()[:30]}' -> OK")
except Exception as e:
print(f" - Clicked button: '{btn_text.strip()[:30]}' -> Error: {str(e)[:50]}")
except Exception as e:
print(f" β {path} - Error: {str(e)[:50]}")
# Summary
print("\nβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
print("π TEST RESULTS SUMMARY")
print("βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
ok = len([r for r in results if not r.get("has_error") and not r.get("requires_login") and not r.get("error")])
login_req = len([r for r in results if r.get("requires_login")])
errors = len([r for r in results if r.get("has_error") or r.get("error")])
print(f"β Loaded successfully: {ok}/{len(results)}")
print(f"π Requires login: {login_req}")
print(f"β Errors: {errors}")
if login_req > 0:
print("\nβ οΈ Some pages require login - auth may not be working")
print(" This is a separate issue from the SSR fix")
finally:
await browser.close()
if __name__ == "__main__":
asyncio.run(test_admin_pages())