#!/usr/bin/env python3 """Read-only game-progress smoke check of the installed Flutter app; no fixtures/reset.""" import argparse,re,subprocess,time,xml.etree.ElementTree as ET from pathlib import Path p=argparse.ArgumentParser();p.add_argument('--serial',required=True);p.add_argument('--package',default='com.lumen.daily');p.add_argument('--expect-fresh',action='store_true');a=p.parse_args() assert re.fullmatch(r'[a-zA-Z0-9_.]+',a.package) base=['/home/ubuntu/Android/Sdk/platform-tools/adb','-s',a.serial];out=Path('artifacts/flutter-check');out.mkdir(parents=True,exist_ok=True) def adb(*args):return subprocess.check_output(base+list(args)) def dump(): adb('shell','uiautomator','dump','/sdcard/lumen-flutter-smoke.xml') return ET.fromstring(adb('exec-out','cat','/sdcard/lumen-flutter-smoke.xml')) def value(n):return n.get('text','')+' '+n.get('content-desc','') def find_any(*texts): root=dump() for text in texts: for n in root.iter('node'): if text.casefold() in value(n).casefold():return n raise AssertionError('Missing '+str(texts)+'; screen: '+str([value(n) for n in root.iter('node') if value(n).strip()])) def find(text):return find_any(text) def tapnode(n): x1,y1,x2,y2=map(int,re.findall(r'\d+',n.get('bounds')));adb('shell','input','tap',str((x1+x2)//2),str((y1+y2)//2)) def tap(text):tapnode(find(text)) def launch():adb('shell','am','start','-n',a.package+'/com.lumen.daily.MainActivity') def shot(name):(out/name).write_bytes(adb('exec-out','screencap','-p')) launch();time.sleep(2) # Leave the player's actual consent decision to them if UMP requires it. root=dump() assert not any('Welcome to Publisher Test Ads' in value(n) for n in root.iter('node')),'Consent form is awaiting the player’s choice.' for attempt in range(8): root=dump() if any('Open Mara’s notebook' in value(n) for n in root.iter('node')):break if any('Close book' in value(n) for n in root.iter('node')):tap('Close book') else:adb('shell','input','keyevent','4') else:raise AssertionError('Could not return to the home screen') if a.expect_fresh:find('0 / 12');find('0\nPATTERNS FOUND') shot('main-home.png');tap('Open Mara’s notebook');tap('Contents');tap('1 · For you, when you are ready') def swipe_text(text,dx): n=find(text);x1,y1,x2,y2=map(int,re.findall(r'\d+',n.get('bounds')));x=(x1+x2)//2;y=(y1+y2)//2 adb('shell','input','swipe',str(x),str(y),str(x+dx),str(y),'350') swipe_text('For you, when you are ready',-360);find('By the cottage window') swipe_text('By the cottage window',360);find('For you, when you are ready') tap('Next leaf');find('By the cottage window') play=find_any('Pause recording','Play this reading') if 'Pause recording' not in value(play):tapnode(play) time.sleep(2) # A clock can advance even when the decoder creates no audio track. Inspect # the real mixer while playback is active (verified on the API 26 tablet). pid=adb('shell','pidof',a.package).decode().strip().split()[0] mixer=adb('shell','dumpsys','media.audio_flinger').decode(errors='replace') (out/'active-audio-track.txt').write_text(mixer) tracks=[line.split() for line in mixer.splitlines()] assert any(len(t)>13 and t[1]=='yes' and t[2]==pid and t[3]=='3' and t[8]=='A' and t[10]=='24000' and all(v!='-inf' for v in t[11:14]) for t in tracks),'The timer is not enough: no active, unmuted 24 kHz media track for this app' shot('main-recording.png');tapnode(play);find('Resume recording') def seconds(): n=find('Paused ·');m=re.search(r'(\d+):(\d+)',value(n));return int(m[1])*60+int(m[2]) first=seconds();assert first>=1 tapnode(play);time.sleep(2);tapnode(play);find('Resume recording');assert seconds()>=first+1 tap('Stop');find('Play this reading') adb('shell','am','force-stop',a.package);launch();find('By the cottage window');find_any('Play this reading','Pause recording');shot('main-restored-page.png') tap('Close book') if a.expect_fresh:find('0 / 12');find('0\nPATTERNS FOUND') print('PASS: optimized app launches, swipes over the writing in both directions, plays through its UI, resumes audio and restores the reading place after process restart.') (out/'release-smoke.txt').write_text('PASS: '+('fresh Flutter progress; ' if a.expect_fresh else '')+'release startup; writing-area swipes both ways; active PCM audio track; UI WAV playback/pause/resume/stop; process restart restores page.\n')