Skip to content

Testing Response Data

Restfox supports writing automation test scripts in JavaScript for your API requests to assert its behaviour.

Here's an example test plugin :

javascript
function handleResponse() {
    const response =  JSON.parse(context.response.getBodyText())
    test('check if response has property form and has a key with value 1', () => {
        expect(response).to.have.property('form')
        expect(response.form).to.eql({
            "key": "1"
        })
    })
    test('check if response has property args', () => {
        expect(response).to.have.property('args')
    })
}

if('response' in context) {
    handleResponse()
}

Here are the steps :

  1. Right click on a request to access Plugins

Image

  1. Click on add plugin to create a new plugin

Image

  1. Write a test script and save it

Image

Image

  1. Send the request & test results will be available in the Tests tab of the response panel

Image

Image