@@ -60,6 +60,38 @@ const clickAllSortableHeaders = function(driver, counter=0) {
6060 )
6161}
6262
63+ const waitForDataTableReady = async function ( driver , maxWaitMs ) {
64+ for ( let attempt = 0 ; attempt < maxWaitMs / 100 ; attempt ++ ) {
65+ try {
66+ // eslint-disable-next-line no-await-in-loop
67+ await driver . executeScript ( "return window.dt && window.dt.initialized" )
68+ return
69+ } catch {
70+ // eslint-disable-next-line no-await-in-loop
71+ await driver . sleep ( 100 )
72+ }
73+ }
74+ }
75+
76+ const waitForTestCompletion = async function ( driver , maxWaitMs ) {
77+ for ( let attempt = 0 ; attempt < maxWaitMs / 100 ; attempt ++ ) {
78+ try {
79+ // eslint-disable-next-line no-await-in-loop
80+ const resultsElement = await driver . findElement ( webdriver . By . id ( "results" ) )
81+ // eslint-disable-next-line no-await-in-loop
82+ const resultsText = await resultsElement . getText ( )
83+
84+ if ( resultsText . includes ( "All tests passed!" ) || resultsText . includes ( "Some tests failed!" ) ) {
85+ return
86+ }
87+ } catch {
88+ // Element not found yet, continue waiting
89+ }
90+ // eslint-disable-next-line no-await-in-loop
91+ await driver . sleep ( 100 )
92+ }
93+ }
94+
6395
6496describe ( "Demos work" , function ( ) {
6597 this . timeout ( 5000 )
@@ -143,17 +175,7 @@ describe("Integration tests pass", function() {
143175
144176 it ( "preserves cell attributes (JS)" , async ( ) => {
145177 await driver . get ( `${ baseUrl } tests/cell-attributes-js.html` )
146-
147- // Wait for the DataTable to be available with intelligent retry
148- for ( let attempt = 0 ; attempt < testWait / 100 ; attempt ++ ) {
149- try {
150- await driver . executeScript ( "return window.dt && window.dt.initialized" )
151- break
152- } catch ( error ) {
153- await driver . sleep ( 100 )
154- }
155- }
156-
178+ await waitForDataTableReady ( driver , testWait )
157179 await assertCellAttrs ( "cell-attributes-js-table" )
158180 } )
159181
@@ -189,37 +211,13 @@ describe("Integration tests pass", function() {
189211 ]
190212
191213 await driver . get ( `${ baseUrl } tests/multiple-classes.html` )
192-
193- // Wait for the DataTable to be available with intelligent retry
194- for ( let attempt = 0 ; attempt < testWait / 100 ; attempt ++ ) {
195- try {
196- await driver . executeScript ( "return window.dt && window.dt.initialized" )
197- break
198- } catch ( error ) {
199- await driver . sleep ( 100 )
200- }
201- }
202-
214+ await waitForDataTableReady ( driver , testWait )
203215 await Promise . all ( classes . map ( className => driver . findElement ( webdriver . By . css ( className ) ) ) )
204216 } )
205217
206218 it ( "handles colspan functionality comprehensively" , async ( ) => {
207219 await driver . get ( `${ baseUrl } tests/colspan.html` )
208-
209- // Wait for the DataTable to initialize and tests to run
210- for ( let attempt = 0 ; attempt < testWait / 100 ; attempt ++ ) {
211- try {
212- const resultsElement = await driver . findElement ( webdriver . By . id ( "results" ) )
213- const resultsText = await resultsElement . getText ( )
214-
215- if ( resultsText . includes ( "All tests passed!" ) || resultsText . includes ( "Some tests failed!" ) ) {
216- break
217- }
218- } catch ( error ) {
219- // Element not found yet, continue waiting
220- }
221- await driver . sleep ( 100 )
222- }
220+ await waitForTestCompletion ( driver , testWait )
223221
224222 // Check that all tests passed by looking for the success summary
225223 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -236,21 +234,7 @@ describe("Integration tests pass", function() {
236234
237235 it ( "handles colspan with JSON/JavaScript data" , async ( ) => {
238236 await driver . get ( `${ baseUrl } tests/colspan-json.html` )
239-
240- // Wait for the DataTable to initialize and tests to run
241- for ( let attempt = 0 ; attempt < testWait / 100 ; attempt ++ ) {
242- try {
243- const resultsElement = await driver . findElement ( webdriver . By . id ( "results" ) )
244- const resultsText = await resultsElement . getText ( )
245-
246- if ( resultsText . includes ( "All tests passed!" ) || resultsText . includes ( "Some tests failed!" ) ) {
247- break
248- }
249- } catch ( error ) {
250- // Element not found yet, continue waiting
251- }
252- await driver . sleep ( 100 )
253- }
237+ await waitForTestCompletion ( driver , testWait )
254238
255239 // Check that all tests passed by looking for the success summary
256240 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -267,21 +251,7 @@ describe("Integration tests pass", function() {
267251
268252 it ( "handles rowspan functionality comprehensively" , async ( ) => {
269253 await driver . get ( `${ baseUrl } tests/rowspan.html` )
270-
271- // Wait for the DataTable to initialize and tests to run
272- for ( let attempt = 0 ; attempt < testWait / 100 ; attempt ++ ) {
273- try {
274- const resultsElement = await driver . findElement ( webdriver . By . id ( "results" ) )
275- const resultsText = await resultsElement . getText ( )
276-
277- if ( resultsText . includes ( "All tests passed!" ) || resultsText . includes ( "Some tests failed!" ) ) {
278- break
279- }
280- } catch ( error ) {
281- // Element not found yet, continue waiting
282- }
283- await driver . sleep ( 100 )
284- }
254+ await waitForTestCompletion ( driver , testWait )
285255
286256 // Check that all tests passed by looking for the success summary
287257 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -302,20 +272,7 @@ describe("Integration tests pass", function() {
302272 // Wait for the DataTable to initialize and tests to run
303273 // Extra wait needed for Test 8 which uses setTimeout(100ms)
304274 const totalWait = testWait + 500
305-
306- for ( let attempt = 0 ; attempt < totalWait / 100 ; attempt ++ ) {
307- try {
308- const resultsElement = await driver . findElement ( webdriver . By . id ( "results" ) )
309- const resultsText = await resultsElement . getText ( )
310-
311- if ( resultsText . includes ( "All tests passed!" ) || resultsText . includes ( "Some tests failed!" ) ) {
312- break
313- }
314- } catch ( error ) {
315- // Element not found yet, continue waiting
316- }
317- await driver . sleep ( 100 )
318- }
275+ await waitForTestCompletion ( driver , totalWait )
319276
320277 // Check that all tests passed by looking for the success summary
321278 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -335,21 +292,7 @@ describe("Integration tests pass", function() {
335292
336293 it ( "handles combined colspan and rowspan" , async ( ) => {
337294 await driver . get ( `${ baseUrl } tests/colspan-rowspan.html` )
338-
339- // Wait for the DataTable to initialize and tests to run
340- for ( let attempt = 0 ; attempt < testWait / 100 ; attempt ++ ) {
341- try {
342- const resultsElement = await driver . findElement ( webdriver . By . id ( "results" ) )
343- const resultsText = await resultsElement . getText ( )
344-
345- if ( resultsText . includes ( "All tests passed!" ) || resultsText . includes ( "Some tests failed!" ) ) {
346- break
347- }
348- } catch ( error ) {
349- // Element not found yet, continue waiting
350- }
351- await driver . sleep ( 100 )
352- }
295+ await waitForTestCompletion ( driver , testWait )
353296
354297 // Check that all tests passed by looking for the success summary
355298 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
0 commit comments