Archive: - docker-compose.yml, Dockerfile.playwright - scripts/ (legacy test scripts) - docs/, .test/ (old documentation and tests) - IMPROVEMENT_PROPOSAL.md (superseded by .kilo/) - BROWSER_VISIBILITY.md, README.Docker.md - cleanup-packages.sh, fix-permissions.sh, install-apaw.sh Keep in root: - .kilo/ (active system) - .claude/ (Claude Code runtime) - AGENTS.md (agent reference) - README.md (main documentation) - src/ (utility code) - package.json, tsconfig.json (project config)
165 lines
5.1 KiB
Python
165 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
E2E Test Example: Login Flow with Screenshot Upload to Gitea
|
|
|
|
This test demonstrates:
|
|
1. Browser automation with Playwright
|
|
2. Screenshot capture on error
|
|
3. Upload screenshots to Gitea issues
|
|
"""
|
|
|
|
import json
|
|
import urllib.request
|
|
import urllib.error
|
|
import base64
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
# Configuration
|
|
GITEA_URL = "https://git.softuniq.eu/api/v1"
|
|
GITEA_USER = "NW"
|
|
GITEA_PASSWORD = "eshkink0t" # Note: zero not 'o'
|
|
REPO_OWNER = "UniqueSoft"
|
|
REPO_NAME = "APAW"
|
|
|
|
|
|
def get_gitea_token():
|
|
"""Get Gitea API token using basic auth"""
|
|
credentials = base64.b64encode(f"{GITEA_USER}:{GITEA_PASSWORD}".encode()).decode()
|
|
|
|
req = urllib.request.Request(
|
|
f"{GITEA_URL}/users/{GITEA_USER}/tokens",
|
|
data=json.dumps({"name": f"screenshot-{os.getpid()}", "scopes": ["all"]}).encode(),
|
|
headers={'Content-Type': 'application/json', 'Authorization': f'Basic {credentials}'},
|
|
method='POST'
|
|
)
|
|
|
|
with urllib.request.urlopen(req) as r:
|
|
return json.loads(r.read())['sha1']
|
|
|
|
|
|
def upload_screenshot_to_gitea(issue_number, screenshot_path, description="Error screenshot"):
|
|
"""
|
|
Upload a screenshot to Gitea and post comment with reference.
|
|
"""
|
|
token = get_gitea_token()
|
|
|
|
with open(screenshot_path, 'rb') as f:
|
|
file_content = f.read()
|
|
|
|
filename = os.path.basename(screenshot_path)
|
|
|
|
boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW"
|
|
|
|
body = f'--{boundary}\r\n'.encode()
|
|
body += f'Content-Disposition: form-data; name="attachment"; filename="{filename}"\r\n'.encode()
|
|
body += b'Content-Type: image/png\r\n\r\n'
|
|
body += file_content
|
|
body += f'\r\n--{boundary}--\r\n'.encode()
|
|
|
|
req = urllib.request.Request(
|
|
f"{GITEA_URL}/repos/{REPO_OWNER}/{REPO_NAME}/issues/{issue_number}/assets",
|
|
data=body,
|
|
headers={
|
|
'Content-Type': f'multipart/form-data; boundary={boundary}',
|
|
'Authorization': f'token {token}'
|
|
},
|
|
method='POST'
|
|
)
|
|
|
|
with urllib.request.urlopen(req) as r:
|
|
result = json.loads(r.read())
|
|
uuid = result['uuid']
|
|
|
|
# Post comment with screenshot reference
|
|
comment_body = f"""## 📸 {description}
|
|
|
|

|
|
|
|
**File**: `{filename}`
|
|
**Size**: {os.path.getsize(screenshot_path)} bytes
|
|
**Uploaded**: {datetime.now().isoformat()}
|
|
"""
|
|
|
|
req = urllib.request.Request(
|
|
f"{GITEA_URL}/repos/{REPO_OWNER}/{REPO_NAME}/issues/{issue_number}/comments",
|
|
data=json.dumps({"body": comment_body}).encode(),
|
|
headers={'Content-Type': 'application/json', 'Authorization': f'token {token}'},
|
|
method='POST'
|
|
)
|
|
|
|
with urllib.request.urlopen(req) as r:
|
|
return json.loads(r.read())
|
|
|
|
|
|
def create_test_screenshot(error_message, test_name):
|
|
"""Create a test screenshot (SVG placeholder)"""
|
|
screenshot_path = f".test/screenshots/current/{test_name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
|
|
|
|
svg_content = f"""<svg xmlns="http://www.w3.org/2000/svg" width="800" height="600">
|
|
<rect width="800" height="600" fill="#f0f0f0"/>
|
|
<rect x="50" y="50" width="700" height="100" fill="#ff6b6b"/>
|
|
<text x="400" y="100" text-anchor="middle" fill="white" font-size="24" font-weight="bold">ERROR: {test_name}</text>
|
|
<rect x="50" y="170" width="700" height="380" fill="white" stroke="#ddd"/>
|
|
<text x="70" y="200" fill="#333" font-size="14" font-family="monospace">{error_message[:80]}</text>
|
|
<rect x="50" y="560" width="700" height="30" fill="#e9ecef"/>
|
|
<text x="400" y="580" text-anchor="middle" fill="#666" font-size="12">Screenshot by browser-automation agent</text>
|
|
</svg>"""
|
|
|
|
with open(screenshot_path, 'w') as f:
|
|
f.write(svg_content)
|
|
|
|
return screenshot_path
|
|
|
|
|
|
def run_login_test():
|
|
"""Test login flow with error screenshot"""
|
|
test_name = "login_flow"
|
|
issue_number = 12
|
|
|
|
print(f"Running test: {test_name}")
|
|
|
|
try:
|
|
# Simulate test
|
|
# browser_navigate("https://example.com/login")
|
|
# browser_type("input[name=email]", "test@example.com")
|
|
# browser_click("button[type=submit]")
|
|
|
|
# Simulate error
|
|
raise Exception("Login button not found - element '#login-btn' does not exist")
|
|
|
|
except Exception as e:
|
|
print(f"Test FAILED: {e}")
|
|
|
|
# Create and upload screenshot
|
|
screenshot_path = create_test_screenshot(str(e), test_name)
|
|
print(f"Screenshot created: {screenshot_path}")
|
|
|
|
result = upload_screenshot_to_gitea(
|
|
issue_number=issue_number,
|
|
screenshot_path=screenshot_path,
|
|
description=f"Test Failure: {test_name}"
|
|
)
|
|
print(f"Screenshot uploaded to Gitea")
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print("E2E Browser Tests with Screenshot Upload")
|
|
print("=" * 60)
|
|
|
|
os.makedirs(".test/screenshots/current", exist_ok=True)
|
|
|
|
run_login_test()
|
|
|
|
print("\n✅ Test complete - check Gitea Issue #12 for screenshot")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |