0
votes

Where can I find examples of end to end testing with Backend Rest Api testing included using protractor and jasmine?

2
It's not clear what you mean by "Backend Rest Api testing" here; end to end testing would include the site touching any API endpoints, or do you mean testing the REST API more directly? Either way SO isn't here to find things for you - jonrsharpe
directly to test REST API with basic Authentication using protractor - Mohana Madheswaran
Why? That's really not what it's designed for; it's a browser driver. - jonrsharpe

2 Answers

1
votes

You can use "http" module available in nodeJs to make http request and then process the response recieved from the api call. Look at the below example

var http = require('http');

var options = {
   host: 'example.com',
   port: 80,
   path: '/foo.html'
};

http.get(options, function(resp){
   resp.on('data', function(chunk){
   //do something with chunk
  });
}).on("error", function(e){
   console.log("Got error: " + e.message);
}); 
0
votes

You can use the "http" or "request" module to make the calls to the server. I recommend that the api calls return a promise so in the tests you can use the browser.wait() function and wait for the call to be fulfilled

let apiCall = function () {
    return new Promise((resolve, reject) => {
        request.get(url, function (error, response, json) {
            if (!error && response.statusCode == 200) {
               return resolve(JSON.parse(json));
            } else {
                return reject(error);
            }
        });
    });
}

And in your tests

it("validates something",()=>{
 //...
  browser.wait(apiCall(),timeout).then(json => {
              //do stuff with json
            });
 // Continue with your test
}