Making an API call while running protractor tests

我们两清 提交于 2019-12-04 15:10:45

Protractor runs on top of nodejs, and under the hood is calling Selenium API. You can use all of the node libraries, including request.

Choose between import/require:

import * as request from 'request'; 
var request = require('request');

And perform your GET request:

it('Should reach google.com', done => {
    request('http://www.google.com', function (error, response, body) {
        console.log('error:', error); // Print the error if one occurred
        console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
        console.log('body:', body); // Print the HTML for the Google homepage.
        done(); //informs runner that the asynchronous code has finished
    });
});

Check out this links:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!