Multi-scroll support: build.py and fetch.py take any open-data scroll (per-scroll voxel size, X-ray scan, renumbering by radius, optional ink, a second 1 um ink layer), make_manifest.py, the scroll picker's prize eligible badge and eligible-only toggle (window.unrollScrolls), and a 'Why N ink layers?' box written from each manifest's ink layers
cf20894 Download tests/e2e_scrolls.py from SharpMeow/unroll: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/SharpMeow/unroll/resolve/main/tests/e2e_scrolls.py
- Command line
-
hf download hf://spaces/SharpMeow/unroll/tests/e2e_scrolls.py
-
curl -L -o e2e_scrolls.py https://huggingface.co/spaces/SharpMeow/unroll/resolve/main/tests/e2e_scrolls.py
2.13 kB
| """Load registry scrolls in headless Chromium and screenshot each one. | |
| usage: python3 tests/e2e_scrolls.py <base url> <screenshot dir> [id ...]""" | |
| import json, os, sys | |
| from playwright.sync_api import sync_playwright | |
| base, shots, ids = sys.argv[1].rstrip('/') + '/', sys.argv[2], sys.argv[3:] | |
| os.makedirs(shots, exist_ok=True) | |
| fails = [] | |
| with sync_playwright() as pw: | |
| br = pw.chromium.launch(args=['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader']) | |
| for sid in ids: | |
| p = br.new_page(viewport={'width': 1440, 'height': 900}) | |
| errs = [] | |
| p.on('pageerror', lambda e: errs.append(str(e))) | |
| p.goto(f'{base}#s={sid}', wait_until='load') | |
| try: | |
| p.wait_for_selector('#loader', state='detached', timeout=180000) | |
| p.wait_for_timeout(2500) | |
| info = p.evaluate('() => ({ s: window.__unroll.scroll(), why: document.querySelector("#layerWhy").hidden ? null : document.querySelector("#layerWhy summary").textContent, badge: !document.querySelector("#prizeBadge").hidden, opts: window.unrollScrolls.visible().length })') | |
| p.evaluate('() => window.unrollScrolls.setPrizeEligibleOnly(true)') | |
| only = p.evaluate('() => window.unrollScrolls.visible()') | |
| p.evaluate('() => window.unrollScrolls.setPrizeEligibleOnly(false)') | |
| ok = info['s']['id'] == sid and not errs | |
| print(('ok ' if ok else 'FAIL ') + sid, json.dumps({**info, 's': {k: info['s'][k] for k in ('id', 'layers', 'inkLayers', 'prizeEligible')}, 'nWindings': len(info['s']['windings']), 'eligibleOnly': only}), errs[:2]) | |
| if not ok: fails.append(sid) | |
| except Exception as e: | |
| print('FAIL', sid, str(e)[:200], errs[:2]); fails.append(sid) | |
| # CDP capture: the page's render loop keeps Playwright's own screenshot waiting under software GL | |
| import base64 | |
| cdp = p.context.new_cdp_session(p) | |
| open(f'{shots}/scroll_{sid}.png', 'wb').write(base64.b64decode(cdp.send('Page.captureScreenshot', {'format': 'png'})['data'])) | |
| p.close() | |
| br.close() | |
| sys.exit(1 if fails else 0) | |