Testing DataTables with CasperJS

Testing DataTables with CasperJS

ve7tccve7tcc Posts: 25Questions: 8Answers: 0

Anyone trying testing DataTables with CasperJS ?

I have some tables with server side / ajax, and trying to do some kind of casper.waitFor() to catch when the table has been reloaded. If you have had any luck with that, what were you looking for?

Example: I've been trying to filter the data and count the rows returned to see if something exists or not.

this.fillSelectors('form#RESULT_FILTERS_EXP_CLIENT', {
    'input[type="search"]':    testClient
}, false);

this.waitForText('No data available', function() {
       test.assertTextExists('No data available in table', 'Confirmed that ' + testClient + ' does not exist');
});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    Perhaps you could wait for the init event before checking the DOM? I haven't used CasperJS myself I'm afraid, does waitForText just keep polling the document?

    Allan

  • ve7tccve7tcc Posts: 25Questions: 8Answers: 0

    I am not sure how waitForText() is implemented under the hood in CasperJS.

    I got something to work, I used waitForResource() to wait for the ajax response to come back, and added a half second after that.

                this.fillSelectors('form#RESULT_FILTERS_EXP_CLIENT', {
                    'input[type="search"]':    testClient
                    }, false);
    
                this.waitForResource(/exp_listclientajax.php/, function() {
                    test.comment('after waitForResource processing, before wait');
                    this.wait(500, function() {
                        test.assertTextExists('No data available in table', 'Confirmed that ' + testClient + ' does not exist');
                    });
                });
    
    

    So, this test, enters the name of a test client into the search box, which triggers an ajax/serverside request. The waitForResource() catches the response, and the assertTextExists() checks that there is no match.

  • ve7tccve7tcc Posts: 25Questions: 8Answers: 0
    edited July 2016

    By the way for DataTables server side, when there is no match you get

    "No data available in table"

    and when it is not server side, you get

    "No matching records found"

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin
    Answer ✓

    "No data available in table" is language.emptyTable and is shown when there is no data at all.

    "No matching records found" is language.zeroRecords and is shown when there is data in the table, but the filtering applied to the table has removed it all.

    In the case of server-side processing, emptyTable is used if the recordsTotal property is returned as 0.

    Allan

This discussion has been closed.