FRISBY.JS COMMANDS

Hi all, from a previous post we talked about how to install Frisby.js and other dependencies and how to successfully execute a API test. From this post let’s see what are the available commands for testing.

  • Every code should start with the following line, which will direct to the Frisby libraries.

var frisby = require(‘path/to/frisby/installation’);

  • Next line should be the title for the test.

frisby.create(‘anything_you_like’)

  • Next we can give the specific URL or the IP of the checking API.

.get(‘URL/IP_of_the_API’)

  • Then we can give any method to check a specific condition.
  • Finally we should end the code with the following line.

.toss()

Now let’s see what the possible Expectations are,

  • As we did in the previous example, one is ‘expectStatus()‘, which will check the actual status with the expected status. We should give the expected status as the parameter. Then it will execute the code and send a request to the given URL. In this case it’s a GET request. Then it will check for the actual status. If actual status is equal to the expected status, then case is passed and otherwise it is fail.

Success scenario

1

2

Failure scenario

3

4

  • Next one is the ‘expectHeader()‘, which will check for the http header. Header should be given as a ‘key‘,’value‘ pair.

24

25

  • expectHeaderContains()‘ is similar to the previous one, but this is a less strict one which will check for a best match not for the exact match.

27

28

  • expectJSON()‘ check the JSON values of the response body.

29

30

  • expectJSONType()‘ which will check for the JSON in the response as well, but this time it will check the type of the JSON values, not the values.

32

33

  • Next method, ‘expectBodyContains()‘ will test for a given String content whether is it there or not.

35

36

37.png

  • Then the ‘expectJSONLength()‘ method will check for the length of the JSON respnse body.

41

40

Those are the Expectations in Frisby.js. Next we can see the Helpers of Frisby.js.

  • after()‘ will be used to run another test case after a one test is finished.

42

43

  • afterJSON()‘ is another call back function which will convert the response body to JSON.

45

46

Those are the two Helpers involved in Frisby. Next there are Headers.

  • addHeader()‘ will be used to add a http header.

47

48

  • addHeaders()‘ will add more than one header to the http request.

49

50

  • Next ‘removeHeader()‘ is used to remove the header from the http request.

51

52

Finally we can see the Inspectprs of Frisby. Inspector helpers are useful for viewing details about the HTTP response when the test does not pass, or has trouble for some reason. They are also useful for debugging the API itself as a more user-friendly alternative to curl.

  • inspectJSON()‘ dumps parsed JSON body in console using the node.js pretty printing utility method util.inspect.

53

54

  • inspectBody()‘ will get the raw response and will display to you.

56

57

Those are the two Inspectors used in the Frisby. So far we saw how to send GET requests using Frisby. Now let’s see how to send a POST request. If we send a POST request without mentioning the {json : true} it will send as a form data.

58

59

With the {json : true} parameter, data will be send as JSON data.

60

61

This is a complete tutorial for Frisby.js. Hope now you have a clear idea about Frisby and API testing. Thank You!

Advertisements

4 thoughts on “FRISBY.JS COMMANDS

    1. API (application program interface) is a set of routines, protocols, and tools for building software applications.

      server is a computer program or a device that provides functionality for other programs or devices, called “clients”.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s