jQuery replaced by CheerioJS in Postman Sandbox

As many Postman users know, with the release of v4.5.0+ of the Postman Mac app and Newman v3, jQuery was discontinued as a built-in library in the scripting sandbox. Essentially, we moved to NodeJS-based script execution, which meant saying “bye-bye” to DOM and its allied functionalities. (I can see some of you about to suggest JSDOM – but we wanted something stable, fast and cross-platform.) jQuery is a brilliant library when you need to work with servers that return HTML or XML as responses. We do have xml2js just for that, but … we & our users still love jQuery.

So, we included a new library called CheerioJS. Cheerio emulates the core API and functionalities of jQuery, without the need of browser or DOM. This approach appears rather neat when used inside Postman. Take a look at the following code sample inside a test script:

A live sample of a similar code in action inside Newman: https://tonicdev.com/shamasis/newman-cheerio

The above piece of code extracts the title from an HTML response, and tests whether it has some text or not. The code would have had worked with jQuery by simply replacing cheerio with jQuery. In short, if you know your way around jQuery, you know CheerioJS too!

All cool – but, many folks love those nifty utility functions of jQuery such as $.each and $.param. Fear not fellow developers, we have lodash to the rescue; with _.forEach as one replacement. Lodash is insanely fast and in many ways, the jQuery of the NodeJS world (metaphorically speaking!)

With all these additions, Postman users now have consistent, blazing fast, scripting sandbox inside Postman that works cross-platform and is unaffected by browser quirks or versioning differences.

3 thoughts on “jQuery replaced by CheerioJS in Postman Sandbox”

  1. Is cheerio pre-installed with Postman? or needs to be manually installed to make it work
    I added the following lines in a pre-request script and got “cheerio is not defined” ?

    var html;
    html = cheerio(‘h2 class = “title”>Hello world’);

  2. Excellent post. I was checking continuously this blog and
    I’m impressed! Extremely helpful information particularly the remaining section 🙂
    I take care of such info much. I was looking for this
    certain info for a long time. Thanks and best of luck.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.