mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-12-12 20:11:09 +01:00
tests/emulator, .github/workflows/emulator: add
This commit is contained in:
parent
a81256666e
commit
7882ff6d35
9 changed files with 374 additions and 0 deletions
36
tests/emulator/common.py
Normal file
36
tests/emulator/common.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
SERVER = 'https://nix-on-droid.unboiled.info'
|
||||
# Just use F-Droid through fdroidctl later when F-Droid has x86_64 builds
|
||||
APK = f'{SERVER}/com.termux.nix_188035-x86_64.apk'
|
||||
BOOTSTRAP_URL = 'file:///data/local/tmp/n-o-d'
|
||||
|
||||
|
||||
def screenshot(d, suffix=''):
|
||||
os.makedirs('screenshots', exist_ok=True)
|
||||
fname_base = f'screenshots/{time.time()}-{suffix}'
|
||||
d.ui.screenshot(f'{fname_base}.png')
|
||||
with open(f'{fname_base}.xml', 'w') as f:
|
||||
f.write(d.ui.dump_hierarchy())
|
||||
print(f'screenshotted: {fname_base}.{{png,xml}}')
|
||||
|
||||
|
||||
def wait_for(d, on_screen_text, timeout=90, critical=True):
|
||||
start = time.time()
|
||||
last_displayed_time = None
|
||||
while (elapsed := time.time() - start) < timeout:
|
||||
display_time = int(timeout - elapsed)
|
||||
if display_time != last_displayed_time:
|
||||
print(f'waiting for `{on_screen_text}`: {display_time}s...')
|
||||
sys.stdout.flush()
|
||||
last_displayed_time = display_time
|
||||
if on_screen_text in d.ui.dump_hierarchy():
|
||||
print(f'found: {on_screen_text} after {elapsed:.1f}s')
|
||||
return
|
||||
time.sleep(.75)
|
||||
print(f'NOT FOUND: {on_screen_text} after {timeout}s')
|
||||
screenshot(d, suffix='error')
|
||||
if critical:
|
||||
sys.exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue