File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -120,13 +120,21 @@ async function runTest() {
120120 // Click download button
121121 await driver .findElement (By .id (' download-button' )).click ();
122122
123- // Wait for download to complete (you might need a custom wait)
124- await driver .sleep (2000 );
123+ // Wait for download to complete by polling localStorage
124+ let downloadsStr;
125+ let downloads;
126+ const timeout = Date .now () + 15000 ; // 15 seconds timeout
127+ do {
128+ downloadsStr = await driver .executeScript (
129+ ' return localStorage.getItem("_DOWNLOADS_");'
130+ );
131+ downloads = downloadsStr ? JSON .parse (downloadsStr) : [];
132+ if (downloads .length > 0 && downloads[0 ].state === ' complete' ) break ;
133+ await driver .sleep (500 );
134+ } while (Date .now () < timeout);
125135
126136 // Get download information
127- const downloadsStr = await driver .executeScript (
128- ' return localStorage.getItem("_DOWNLOADS_");'
129- );
137+ // downloadsStr already fetched above
130138
131139 const downloads = JSON .parse (downloadsStr);
132140 console .log (' Downloads:' , downloads);
You can’t perform that action at this time.
0 commit comments