-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture_screenshots.py
More file actions
213 lines (166 loc) · 6.95 KB
/
capture_screenshots.py
File metadata and controls
213 lines (166 loc) · 6.95 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python3
"""
Automated Screenshot Capture for Info Naut
Uses Playwright to capture screenshots and record GIF
"""
import asyncio
import time
from pathlib import Path
from playwright.async_api import async_playwright
# Configuration
BASE_URL = "http://localhost:3001"
OUTPUT_DIR = Path("docs/images")
SCREENSHOTS = {
"dashboard.png": "/dashboard",
"knowledge-base.png": "/dashboard/knowledge",
"chat-interface.png": "/dashboard/chat",
"api-docs.png": "http://localhost:8000/docs",
}
async def capture_screenshots():
"""Capture all screenshots automatically"""
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
async with async_playwright() as p:
print("Launching browser...")
browser = await p.chromium.launch(headless=False)
context = await browser.new_context(viewport={"width": 1920, "height": 1080})
page = await context.new_page()
print(f"\n{'='*60}")
print("INFO NAUT - Automated Screenshot Capture")
print(f"{'='*60}\n")
# Wait for app to be ready
print("Navigating to application...")
await page.goto(BASE_URL, wait_until="networkidle")
await asyncio.sleep(3)
# Capture each screenshot
for filename, url in SCREENSHOTS.items():
print(f"Capturing: {filename}")
full_url = url if url.startswith("http") else f"{BASE_URL}{url}"
await page.goto(full_url, wait_until="networkidle")
await asyncio.sleep(2)
output_path = OUTPUT_DIR / filename
await page.screenshot(path=str(output_path), full_page=False)
print(f" [OK] Saved to {output_path}")
# Capture attribution view (need to click to expand)
print(f"\nCapturing: attribution.png")
try:
await page.goto(f"{BASE_URL}/dashboard/chat", wait_until="networkidle")
await asyncio.sleep(2)
# Try to find and click on sources/attribution
attribution = page.locator('text=Sources').or_(page.locator('text=Citations'))
if await attribution.count() > 0:
await attribution.first.click()
await asyncio.sleep(1)
output_path = OUTPUT_DIR / "attribution.png"
await page.screenshot(path=str(output_path), full_page=False)
print(f" [OK] Saved to {output_path}")
except Exception as e:
print(f" [WARN] Could not capture attribution (chat may be empty): {e}")
print(f"\n{'='*60}")
print(f"Screenshots saved to: {OUTPUT_DIR.absolute()}")
print(f"{'='*60}\n")
await browser.close()
async def record_demo_gif():
"""Record a demo GIF of the application workflow"""
print(f"\n{'='*60}")
print("INFO NAUT - Demo GIF Recording")
print(f"{'='*60}\n")
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
context = await browser.new_context(
viewport={"width": 1280, "height": 720},
record_video_dir=str(OUTPUT_DIR),
record_video_size={"width": 1280, "height": 720}
)
page = await context.new_page()
print("Recording demo workflow...")
# 1. Landing page
print(" [1/7] Landing page")
await page.goto(BASE_URL, wait_until="networkidle")
await asyncio.sleep(3)
# 2. Navigate to Knowledge Base
print(" [2/7] Navigate to Knowledge Base")
await page.click('text=Knowledge Base')
await asyncio.sleep(2)
# 3. Click New Knowledge Base
print(" [3/7] Create Knowledge Base")
try:
await page.click('text=New Knowledge Base')
await asyncio.sleep(1)
# Fill in KB details
await page.fill('input[name="name"]', 'Product Documentation')
await page.fill('textarea[name="description"]', 'All product manuals and guides')
await asyncio.sleep(1)
await page.click('button:has-text("Create")')
await asyncio.sleep(3)
except Exception as e:
print(f" (KB creation step skipped: {e})")
# 4. Navigate to Chat
print(" [4/7] Navigate to Chat")
await page.click('text=Chat')
await asyncio.sleep(2)
# 5. Start New Chat
print(" [5/7] Start New Chat")
try:
await page.click('text=New Chat')
await asyncio.sleep(1)
except:
print(" (New Chat button not found)")
# 6. Type and send question
print(" [6/7] Ask question")
try:
input_box = page.locator('textarea, input[type="text"]').last
await input_box.fill('What are the main features of Info Naut?')
await asyncio.sleep(2)
# Try to submit
await page.keyboard.press('Enter')
await asyncio.sleep(5)
except Exception as e:
print(f" (Question step skipped: {e})")
# 7. Show response
print(" [7/7] Display response with citations")
await asyncio.sleep(3)
print("\nStopping recording...")
await context.close()
# Get video file
video_path = list(OUTPUT_DIR.glob("*.webm"))
if video_path:
print(f"\n[OK] Video recorded: {video_path[0]}")
print("\nTo convert to GIF, run:")
print(f" ffmpeg -i {video_path[0]} -vf \"fps=10,scale=1280:-1:flags=lanczos\" -loop 0 docs/images/demo.gif")
await browser.close()
print(f"\n{'='*60}")
print("Demo recording complete!")
print(f"{'='*60}\n")
def main():
"""Main entry point"""
import sys
if len(sys.argv) > 1 and sys.argv[1] == "--video":
asyncio.run(record_demo_gif())
else:
asyncio.run(capture_screenshots())
if __name__ == "__main__":
print("""
================================================================
INFO NAUT - Screenshot Automation Tool
================================================================
Usage:
python capture_screenshots.py # Capture screenshots
python capture_screenshots.py --video # Record demo video
Requirements:
pip install playwright
playwright install chromium
Make sure the app is running:
- Backend: http://localhost:8000
- Frontend: http://localhost:3001
""")
try:
main()
except KeyboardInterrupt:
print("\n\nInterrupted by user")
except Exception as e:
print(f"\n\nError: {e}")
print("\nMake sure:")
print(" 1. App is running (http://localhost:3001)")
print(" 2. Playwright is installed: pip install playwright")
print(" 3. Browser is installed: playwright install chromium")