@@ -17,8 +17,8 @@ let testWait = 2000
1717const options = new chrome . Options ( )
1818if ( process . env . CI ) { // eslint-disable-line no-process-env
1919 // We are running on CI
20- wait = 300
21- testWait = 5000
20+ wait = 500
21+ testWait = 10000
2222 options . addArguments ( "--headless=new" )
2323}
2424const driver = new webdriver . Builder ( ) . withCapabilities ( webdriver . Capabilities . chrome ( ) ) . setChromeOptions ( options ) . build ( )
@@ -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 )
@@ -79,7 +111,7 @@ describe("Demos work", function() {
79111} )
80112
81113describe ( "Integration tests pass" , function ( ) {
82- this . timeout ( 5000 )
114+ this . timeout ( 30000 )
83115
84116 it ( "initializes the datatable" , async ( ) => {
85117 await driver . get ( `${ baseUrl } 1-simple/` )
@@ -143,7 +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- await driver . sleep ( testWait )
178+ await waitForDataTableReady ( driver , testWait )
147179 await assertCellAttrs ( "cell-attributes-js-table" )
148180 } )
149181
@@ -179,15 +211,13 @@ describe("Integration tests pass", function() {
179211 ]
180212
181213 await driver . get ( `${ baseUrl } tests/multiple-classes.html` )
182- await driver . sleep ( testWait )
214+ await waitForDataTableReady ( driver , testWait )
183215 await Promise . all ( classes . map ( className => driver . findElement ( webdriver . By . css ( className ) ) ) )
184216 } )
185217
186218 it ( "handles colspan functionality comprehensively" , async ( ) => {
187219 await driver . get ( `${ baseUrl } tests/colspan.html` )
188-
189- // Wait for the DataTable to initialize and tests to run
190- await driver . sleep ( testWait )
220+ await waitForTestCompletion ( driver , testWait )
191221
192222 // Check that all tests passed by looking for the success summary
193223 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -204,9 +234,7 @@ describe("Integration tests pass", function() {
204234
205235 it ( "handles colspan with JSON/JavaScript data" , async ( ) => {
206236 await driver . get ( `${ baseUrl } tests/colspan-json.html` )
207-
208- // Wait for the DataTable to initialize and tests to run
209- await driver . sleep ( testWait )
237+ await waitForTestCompletion ( driver , testWait )
210238
211239 // Check that all tests passed by looking for the success summary
212240 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -223,9 +251,7 @@ describe("Integration tests pass", function() {
223251
224252 it ( "handles rowspan functionality comprehensively" , async ( ) => {
225253 await driver . get ( `${ baseUrl } tests/rowspan.html` )
226-
227- // Wait for the DataTable to initialize and tests to run
228- await driver . sleep ( testWait )
254+ await waitForTestCompletion ( driver , testWait )
229255
230256 // Check that all tests passed by looking for the success summary
231257 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -245,7 +271,8 @@ describe("Integration tests pass", function() {
245271
246272 // Wait for the DataTable to initialize and tests to run
247273 // Extra wait needed for Test 8 which uses setTimeout(100ms)
248- await driver . sleep ( testWait + 500 )
274+ const totalWait = testWait + 500
275+ await waitForTestCompletion ( driver , totalWait )
249276
250277 // Check that all tests passed by looking for the success summary
251278 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
@@ -265,9 +292,7 @@ describe("Integration tests pass", function() {
265292
266293 it ( "handles combined colspan and rowspan" , async ( ) => {
267294 await driver . get ( `${ baseUrl } tests/colspan-rowspan.html` )
268-
269- // Wait for the DataTable to initialize and tests to run
270- await driver . sleep ( testWait )
295+ await waitForTestCompletion ( driver , testWait )
271296
272297 // Check that all tests passed by looking for the success summary
273298 const results = await driver . findElement ( webdriver . By . id ( "results" ) )
0 commit comments