dareid / chakram

REST API test framework. BDD and exploits promises
http://dareid.github.io/chakram/
MIT License
908 stars 99 forks source link

Not able to retain cookies within multiple API calls #109

Open ngarg0511 opened 7 years ago

ngarg0511 commented 7 years ago

Hi @dareid, I am working on chakram framework for API automation. It's a great framework. I want to retain cookies (or JsessionID) while making multiple calls within APIs. Here is my piece of code where I am making a post call first and then want to make get call next but I am not able to retain session. Can you please help in identifying what is it that I am doing wrong.

var call = require('chakram'); expect = call.expect; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

testConfig = require('../config1.json'); login1 = require('../login1.json'); expected = require('./../response.json'); var request = require('request');

describe("User login", function () { before(function () { var jar = request.jar(); call.setRequestDefaults({jar: true});

  });
it('checking First Name for Login API', function () {       
    return call.post(testConfig.APP_URL + testConfig.LOGIN_API, undefined, login1).then(function (response, body) {

        console.log(response.response.body);
        expect(response.response.body.result.firstName).to.equal(expected.result.firstName);         
         });

}); it('GETUSERAPI', function () { return call.get(testConfig.APP_URL+"/rest/user/view").then(function(response, body){ console.log("****"); console.log(response.response.body);
}); }); });

Thanks, Nidhi

tyoc213 commented 6 years ago

Probably doing chakram.setRequestDefaults({jar: true}); as of this test https://github.com/dareid/chakram/blob/0864ebfda57d503b5aaf1d270cd011e736218e3a/test/assertions/cookie.js#L54