-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_playwright.py
More file actions
75 lines (63 loc) · 2.18 KB
/
test_playwright.py
File metadata and controls
75 lines (63 loc) · 2.18 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
#!/usr/bin/env python3
"""
Test script for Playwright integration
Run this to verify Playwright is working correctly
"""
import asyncio
import sys
import os
# Add backend to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
from backend.preprocessing.scraper import fetch
from backend.config import PLAYWRIGHT_HEADLESS, PLAYWRIGHT_BROWSER
def test_playwright_fetch():
"""Test basic Playwright fetch functionality"""
print("🧪 Testing Playwright integration...")
print(f"Browser: {PLAYWRIGHT_BROWSER}")
print(f"Headless: {PLAYWRIGHT_HEADLESS}")
# Test URLs
test_urls = [
"https://httpbin.org/html",
"https://example.com",
"https://httpbin.org/json"
]
for url in test_urls:
print(f"\n🔍 Testing: {url}")
try:
html = fetch(url, retries=1, timeout=10)
if html:
print(f"✅ Success: Got {len(html)} characters")
# Check for basic HTML structure
if "<html" in html.lower() or "<!doctype" in html.lower():
print("✅ Valid HTML detected")
else:
print("⚠️ No HTML structure found")
else:
print("❌ Failed: No content returned")
except Exception as e:
print(f"❌ Error: {e}")
print("\n🎉 Playwright test complete!")
def test_playwright_import():
"""Test if Playwright can be imported"""
try:
from playwright.async_api import async_playwright
print("✅ Playwright import successful")
return True
except ImportError as e:
print(f"❌ Playwright import failed: {e}")
print("Please install Playwright: pip install playwright")
return False
def main():
print("🦕 DataSaurus Playwright Test")
print("=" * 40)
# Test import
if not test_playwright_import():
sys.exit(1)
# Test basic functionality
try:
test_playwright_fetch()
except Exception as e:
print(f"❌ Test failed: {e}")
sys.exit(1)
if __name__ == "__main__":
main()