File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,6 +38,14 @@ const normalizeWaitMs = (value: unknown): number => {
3838 return parsed >= 0 ? parsed : 1000 ;
3939} ;
4040
41+ const normalizeWaitUntil = ( value : unknown ) : "domcontentloaded" | "load" | "networkidle" => {
42+ const parsed = asNonEmptyTrimmedString ( value ) ;
43+ if ( parsed === "load" || parsed === "networkidle" ) {
44+ return parsed ;
45+ }
46+ return "domcontentloaded" ;
47+ } ;
48+
4149export function createScriptFromActionCache (
4250 params : CreateScriptFromActionCacheParams
4351) : string {
@@ -111,8 +119,7 @@ ${indent}await page.waitForTimeout(${waitMs});`;
111119 const actionParams = isRecord ( step . actionParams )
112120 ? step . actionParams
113121 : undefined ;
114- const waitUntil =
115- asNonEmptyTrimmedString ( step . arguments ?. [ 0 ] ) ?? "domcontentloaded" ;
122+ const waitUntil = normalizeWaitUntil ( step . arguments ?. [ 0 ] ) ;
116123 const timeoutMs = asNumber ( step . arguments ?. [ 1 ] ?? actionParams ?. timeout ) ;
117124 if ( typeof timeoutMs === "number" && Number . isFinite ( timeoutMs ) ) {
118125 return `${ indent } // Step ${ step . stepIndex }
Original file line number Diff line number Diff line change @@ -213,6 +213,28 @@ describe("action cache helpers", () => {
213213 expect ( script ) . toContain ( 'await page.waitForLoadState("domcontentloaded");' ) ;
214214 } ) ;
215215
216+ it ( "normalizes unsupported waitForLoadState targets to domcontentloaded" , ( ) => {
217+ const waitEntry : ActionCacheEntry = {
218+ stepIndex : 14 ,
219+ instruction : "wait unsupported" ,
220+ elementId : null ,
221+ method : null ,
222+ arguments : [ "interactive" ] ,
223+ actionType : "waitForLoadState" ,
224+ success : true ,
225+ message : "ok" ,
226+ frameIndex : null ,
227+ xpath : null ,
228+ } ;
229+
230+ const script = createScriptFromActionCache ( {
231+ steps : [ waitEntry ] ,
232+ } ) ;
233+
234+ expect ( script ) . toContain ( 'await page.waitForLoadState("domcontentloaded");' ) ;
235+ expect ( script ) . not . toContain ( 'await page.waitForLoadState("interactive");' ) ;
236+ } ) ;
237+
216238 it ( "skips helper generation when xpath is missing" , ( ) => {
217239 const actElementEntry : ActionCacheEntry = {
218240 stepIndex : 3 ,
You can’t perform that action at this time.
0 commit comments