javascriptunit-testingphantomjsautomated-testsslimerjs

Getting response body for AJAX requests with SlimerJS


I'm writing a test using SlimerJS for a website and need to check the response body coming from the server. I'm using the following piece of code to get the response:

 page.onResourceReceived = function (response) {
            console.log(JSON.stringify(response));
        };

I do receive the response but since by default to prevent too much memory usage SlimerJS keeps the response body empty I too receive an empty body, unless I tell it not to keep the body empty for certain formats using something like this:

webpage.captureContent = [ /css/, /image\/.*/ ]

I understand this works well for files with extensions like css,jpg and avi, but what about an AJAX response coming from the server. The response is in JSON format and the response body is left empty.


Solution

  • By looking at the response header you can tell that the response type is in text/html so by using the following code you can get the body.

    page.captureContent = [/text/, /html/]