1- import { expect , type Page , test } from "@playwright/test" ;
1+ import { type BrowserContext , expect , type Page , test } from "@playwright/test" ;
22import {
33 assertReadyChecks ,
44 installDefaultAppRoutes ,
@@ -52,10 +52,21 @@ const RED_ERROR_TEXT =
5252const BENIGN_SHIM_ISSUES = [
5353 / " K e y b o a r d " p l u g i n i s n o t i m p l e m e n t e d o n w e b / i,
5454 / \[ E l i z a \] N e t w o r k p l u g i n n o t a v a i l a b l e : C a n n o t r e a d p r o p e r t i e s o f u n d e f i n e d \( r e a d i n g ' a d d L i s t e n e r ' \) / i,
55+ / F a i l e d t o r e a d t h e ' s e s s i o n S t o r a g e ' p r o p e r t y f r o m ' W i n d o w ' : A c c e s s i s d e n i e d f o r t h i s d o c u m e n t \. / i,
5556] ;
5657
5758test . use ( { userAgent : ANDROID_ELIZA_UA } ) ;
5859
60+ function getAndroidSystemRoute ( name : string ) : AndroidSystemRouteCase {
61+ const route = ANDROID_SYSTEM_APP_CASES . find (
62+ ( candidate ) => candidate . name === name ,
63+ ) ;
64+ if ( ! route ) {
65+ throw new Error ( `Missing Android system app route: ${ name } ` ) ;
66+ }
67+ return route ;
68+ }
69+
5970function installAndroidPlatformShim ( page : Page ) : Promise < void > {
6071 return page . addInitScript ( ( ) => {
6172 let capacitorValue : unknown = Reflect . get ( window , "Capacitor" ) ;
@@ -120,6 +131,22 @@ async function openAppWindow(
120131 ) ;
121132}
122133
134+ async function openFreshAppWindow (
135+ context : BrowserContext ,
136+ routeCase : AndroidSystemRouteCase ,
137+ ) : Promise < { issues : string [ ] ; page : Page } > {
138+ const page = await context . newPage ( ) ;
139+ await installAndroidPlatformShim ( page ) ;
140+ await seedAppStorage ( page , {
141+ "eliza:ui-theme" : "dark" ,
142+ "elizaos:ui-theme" : "dark" ,
143+ } ) ;
144+ await installDefaultAppRoutes ( page ) ;
145+ const issues = installIssueGuards ( page ) ;
146+ await openAppWindow ( page , routeCase ) ;
147+ return { issues, page } ;
148+ }
149+
123150async function expectNoIssues (
124151 page : Page ,
125152 issues : readonly string [ ] ,
@@ -151,26 +178,25 @@ test.beforeEach(async ({ page }) => {
151178 await installDefaultAppRoutes ( page ) ;
152179} ) ;
153180
154- test ( "AOSP system apps render and expose safe controls" , async ( { page } ) => {
155- const issues = installIssueGuards ( page ) ;
156-
181+ test ( "AOSP system apps render and expose safe controls" , async ( {
182+ context ,
183+ } ) => {
157184 for ( const routeCase of ANDROID_SYSTEM_APP_CASES ) {
158185 await test . step ( routeCase . name , async ( ) => {
159- await openAppWindow ( page , routeCase ) ;
186+ const { issues , page } = await openFreshAppWindow ( context , routeCase ) ;
160187 await expectNoIssues ( page , issues . splice ( 0 ) , routeCase . name ) ;
188+ await page . close ( ) ;
161189 } ) ;
162190 }
163191} ) ;
164192
165193test ( "Phone, Contacts, WiFi, Messages, and Device Settings handle core interactions" , async ( {
166- page ,
194+ context ,
167195} ) => {
168- const issues = installIssueGuards ( page ) ;
169- const byName = new Map (
170- ANDROID_SYSTEM_APP_CASES . map ( ( route ) => [ route . name , route ] ) ,
196+ let { issues, page } = await openFreshAppWindow (
197+ context ,
198+ getAndroidSystemRoute ( "phone" ) ,
171199 ) ;
172-
173- await openAppWindow ( page , byName . get ( "phone" ) ! ) ;
174200 await page . getByTestId ( "phone-dial-key-1" ) . click ( ) ;
175201 await page . getByTestId ( "phone-dial-key-2" ) . click ( ) ;
176202 await page . getByTestId ( "phone-dial-key-3" ) . click ( ) ;
@@ -179,7 +205,9 @@ test("Phone, Contacts, WiFi, Messages, and Device Settings handle core interacti
179205 page . getByRole ( "status" , { name : "Number being dialed" } ) ,
180206 ) . toContainText ( "12" ) ;
181207 await page . getByRole ( "tab" , { name : "Recent" } ) . click ( ) ;
182- await expect ( page . getByText ( "No recent calls." , { exact : true } ) ) . toBeVisible ( ) ;
208+ await expect (
209+ page . getByText ( "No recent calls." , { exact : true } ) ,
210+ ) . toBeVisible ( ) ;
183211 const phoneContactsTab = page . getByRole ( "tab" , { name : "Contacts" } ) ;
184212 if ( await phoneContactsTab . isEnabled ( ) ) {
185213 await phoneContactsTab . click ( ) ;
@@ -190,36 +218,53 @@ test("Phone, Contacts, WiFi, Messages, and Device Settings handle core interacti
190218 await expect ( phoneContactsTab ) . toBeDisabled ( ) ;
191219 }
192220 await expectNoIssues ( page , issues . splice ( 0 ) , "phone interactions" ) ;
221+ await page . close ( ) ;
193222
194- await openAppWindow ( page , byName . get ( "contacts" ) ! ) ;
223+ ( { issues, page } = await openFreshAppWindow (
224+ context ,
225+ getAndroidSystemRoute ( "contacts" ) ,
226+ ) ) ;
195227 await page . getByTestId ( "contacts-search" ) . fill ( "ada" ) ;
196228 await page . getByTestId ( "contacts-new" ) . click ( ) ;
197229 await page . getByPlaceholder ( "Full name" ) . fill ( "Ada Lovelace" ) ;
198230 await page . getByPlaceholder ( "+1 555 123 4567" ) . fill ( "+1 555 0100" ) ;
199231 await page . getByRole ( "button" , { name : "Cancel" } ) . click ( ) ;
200232 await expect ( page . getByTestId ( "contacts-shell" ) ) . toBeVisible ( ) ;
201233 await expectNoIssues ( page , issues . splice ( 0 ) , "contacts interactions" ) ;
234+ await page . close ( ) ;
202235
203- await openAppWindow ( page , byName . get ( "wifi" ) ! ) ;
236+ ( { issues, page } = await openFreshAppWindow (
237+ context ,
238+ getAndroidSystemRoute ( "wifi" ) ,
239+ ) ) ;
204240 await page . getByTestId ( "wifi-scan" ) . click ( ) ;
205241 await expect ( page . getByText ( "Wi-Fi is off" ) ) . toBeVisible ( ) ;
206242 await expect ( page . getByText ( "No networks found" ) ) . toBeVisible ( ) ;
207243 await expectNoIssues ( page , issues . splice ( 0 ) , "wifi interactions" ) ;
244+ await page . close ( ) ;
208245
209- await openAppWindow ( page , byName . get ( "messages" ) ! ) ;
246+ ( { issues, page } = await openFreshAppWindow (
247+ context ,
248+ getAndroidSystemRoute ( "messages" ) ,
249+ ) ) ;
210250 await page . getByTestId ( "messages-new" ) . click ( ) ;
211251 await page . getByTestId ( "messages-compose-address" ) . fill ( "+1 555 0101" ) ;
212252 await page . getByTestId ( "messages-compose-body" ) . fill ( "QA SMS draft" ) ;
213253 await expect ( page . getByTestId ( "messages-send" ) ) . toBeEnabled ( ) ;
214254 await page . getByTestId ( "messages-refresh" ) . click ( ) ;
215255 await expectNoIssues ( page , issues . splice ( 0 ) , "messages interactions" ) ;
256+ await page . close ( ) ;
216257
217- await openAppWindow ( page , byName . get ( "device settings" ) ! ) ;
258+ ( { issues, page } = await openFreshAppWindow (
259+ context ,
260+ getAndroidSystemRoute ( "device settings" ) ,
261+ ) ) ;
218262 await page . getByTestId ( "device-settings-brightness" ) . fill ( "67" ) ;
219263 const mediaVolume = page . getByTestId ( "device-settings-volume-music" ) ;
220264 if ( await mediaVolume . isVisible ( ) . catch ( ( ) => false ) ) {
221265 await mediaVolume . fill ( "8" ) ;
222266 }
223267 await page . getByTestId ( "device-settings-refresh" ) . click ( ) ;
224268 await expectNoIssues ( page , issues . splice ( 0 ) , "device settings interactions" ) ;
269+ await page . close ( ) ;
225270} ) ;
0 commit comments