-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_browser.py
More file actions
71 lines (58 loc) · 2.19 KB
/
Copy pathtest_browser.py
File metadata and controls
71 lines (58 loc) · 2.19 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
#!/usr/bin/env python3
"""Quick browser test to diagnose Playwright issues."""
from playwright.sync_api import sync_playwright
import sys
print("Testing Playwright browser launch...\n")
try:
print("1. Starting Playwright...")
playwright = sync_playwright().start()
print(" ✓ Playwright started\n")
# Try Firefox first (more stable on macOS)
browser = None
browser_name = None
print("2. Trying Firefox (headless=False)...")
try:
browser = playwright.firefox.launch(
headless=False,
timeout=60000
)
browser_name = "Firefox"
print(" ✓ Firefox launched\n")
except Exception as e:
print(f" ✗ Firefox failed: {e}\n")
print("3. Trying Chromium (headless=False)...")
browser = playwright.chromium.launch(
headless=False,
args=['--no-sandbox', '--disable-dev-shm-usage'],
timeout=60000
)
browser_name = "Chromium"
print(" ✓ Chromium launched\n")
print("3. Creating context...")
context = browser.new_context()
print(" ✓ Context created\n")
print("4. Creating page...")
page = context.new_page()
print(" ✓ Page created\n")
print("5. Navigating to example.com...")
page.goto('https://example.com', timeout=30000)
print(" ✓ Navigation successful\n")
print("6. Getting page title...")
title = page.title()
print(f" ✓ Page title: {title}\n")
input("Press Enter to close browser...")
print("7. Closing browser...")
browser.close()
playwright.stop()
print(" ✓ Browser closed\n")
print(f"✅ All tests passed! Playwright is working correctly with {browser_name}.")
sys.exit(0)
except Exception as e:
print(f"\n❌ Error: {e}\n")
print("Troubleshooting:")
print("1. Run: playwright install firefox")
print("2. Run: playwright install chromium")
print("3. Check Python version (3.9+ required, 3.10+ recommended)")
print("4. Try reinstalling: pip uninstall playwright && pip install playwright")
print("5. On macOS, check if you need to allow browsers in Security settings")
sys.exit(1)