@@ -128,26 +128,24 @@ test.describe("StagehandContext - Multi-page Support", () => {
128
128
* Test popup handling
129
129
*/
130
130
test ( "should handle popups with enhanced capabilities" , async ( ) => {
131
- const mainPage = stagehand . page ;
132
- let popupPage : Page | null = null ;
131
+ await stagehand . page . goto ( `http://localhost: ${ serverPort } /page1` ) ;
132
+ await stagehand . page . click ( "#popupBtn" ) ;
133
133
134
- mainPage . on ( "popup" , ( page : Page ) => {
135
- popupPage = page ;
136
- } ) ;
134
+ await expect . poll ( ( ) => stagehand . context . pages ( ) . length ) . toBe ( 2 ) ;
137
135
138
- await mainPage . goto ( `http://localhost: ${ serverPort } /page1` ) ;
139
- await mainPage . click ( "#popupBtn" ) ;
136
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
137
+ const [ _original , popupPage ] = stagehand . context . pages ( ) ;
140
138
141
- // Verify popup has enhanced capabilities
142
- expect ( popupPage ) . not . toBeNull ( ) ;
143
- expect ( typeof popupPage . act ) . toBe ( "function" ) ;
144
- expect ( typeof popupPage . extract ) . toBe ( "function" ) ;
145
- expect ( typeof popupPage . observe ) . toBe ( "function" ) ;
139
+ await popupPage . waitForLoadState ( ) ;
146
140
147
- if ( popupPage ) {
148
- await popupPage . waitForLoadState ( ) ;
149
- expect ( await popupPage . title ( ) ) . toBe ( "Page 2" ) ;
150
- }
141
+ const get = ( k : string ) =>
142
+ ( popupPage as unknown as Record < string , unknown > ) [ k ] ;
143
+
144
+ expect ( typeof get ( "act" ) ) . toBe ( "function" ) ;
145
+ expect ( typeof get ( "extract" ) ) . toBe ( "function" ) ;
146
+ expect ( typeof get ( "observe" ) ) . toBe ( "function" ) ;
147
+
148
+ expect ( await popupPage . title ( ) ) . toBe ( "Page 2" ) ;
151
149
} ) ;
152
150
153
151
/**
0 commit comments