-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive_check.py
More file actions
114 lines (95 loc) · 4.47 KB
/
live_check.py
File metadata and controls
114 lines (95 loc) · 4.47 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
import time
from playwright.sync_api import sync_playwright
import urllib.request
import json
import ssl
def check_live():
# Wait for github pages to build by checking if the sitemap is live
print("Waiting for GitHub Pages to deploy...")
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
max_retries = 30
for i in range(max_retries):
try:
req = urllib.request.Request("https://techstackglobal.github.io/sitemap.xml", headers={'User-Agent': 'Mozilla/5.0'})
res = urllib.request.urlopen(req, context=ctx)
content = res.read().decode()
if "<loc>https://techstackglobal.github.io/</loc>" in content:
print("Deployment detected! Proceeding to UI and Console checks.")
break
except Exception as e:
pass
print(f"Waiting for deployment... ({i+1}/{max_retries})")
time.sleep(10)
else:
print("FAIL: Deployment check timed out.")
return
results = {}
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
# 1. Desktop Check
desktop_page = browser.new_page(viewport={'width': 1280, 'height': 800})
console_errors = []
desktop_page.on("console", lambda msg: console_errors.append(msg.text) if msg.type == "error" else None)
try:
r = desktop_page.goto("https://techstackglobal.github.io/", wait_until="networkidle")
results["Homepage desktop"] = "OK" if r.ok else "FAIL"
# Check H1 visibility and header overlap
h1 = desktop_page.locator("h1")
header = desktop_page.locator("header")
h1_box = h1.bounding_box()
header_box = header.bounding_box()
if h1_box and header_box and h1_box["y"] > header_box["y"] + header_box["height"]:
results["H1 visible"] = "OK"
else:
results["H1 visible"] = "FAIL (Obscured or not found)"
# Meta & OG tags
has_meta = desktop_page.evaluate("""() => {
return !!document.querySelector('meta[name="description"]') &&
!!document.querySelector('meta[property="og:title"]') &&
!!document.querySelector('meta[property="og:image"]');
}""")
results["Meta & OG present"] = "OK" if has_meta else "FAIL"
# CTA check
cta = desktop_page.locator(".cta-box")
results["CTA check"] = "OK" if cta.is_visible() and desktop_page.locator(".cta-box form button").is_visible() else "FAIL"
# Console errors
results["Console errors"] = "OK" if len(console_errors) == 0 else f"FAIL ({console_errors})"
except Exception as e:
results["Homepage desktop"] = f"FAIL ({e})"
# 2. Mobile Emulated Check
mobile_page = browser.new_page(viewport={'width': 375, 'height': 667})
try:
mobile_page.goto("https://techstackglobal.github.io/", wait_until="networkidle")
results["Homepage mobile"] = "OK"
# Check horizontal overflow
overflow = mobile_page.evaluate("""() => {
return document.documentElement.scrollWidth > window.innerWidth;
}""")
results["No horizontal overflow"] = "FAIL (Overflow detected)" if overflow else "OK"
except Exception as e:
results["Homepage mobile"] = f"FAIL ({e})"
browser.close()
# Check robots.txt
try:
req = urllib.request.Request("https://techstackglobal.github.io/robots.txt", headers={'User-Agent': 'Mozilla/5.0'})
res = urllib.request.urlopen(req, context=ctx)
rb = res.read().decode()
if "Allow: /" in rb and "sitemap.xml" in rb:
results["robots.txt"] = "OK"
else:
results["robots.txt"] = "FAIL"
except Exception:
results["robots.txt"] = "FAIL"
# Check OG Image loads
try:
req = urllib.request.Request("https://techstackglobal.github.io/assets/og-image.jpg", headers={'User-Agent': 'Mozilla/5.0'})
res = urllib.request.urlopen(req, context=ctx)
results["OG image loads"] = "OK" if res.status == 200 else "FAIL"
except Exception:
results["OG image loads"] = "FAIL"
results["sitemap.xml"] = "OK"
for k, v in results.items():
print(f"{k}: {v}")
check_live()