I ran into the problem of sending an HTTP request request to Protractor. In fact, I need to check the data in the database after performing some actions in the user interface.
It will be very useful if I can do it with jQuery, but I canβt find a way to use jQuery inside Protractor.
Help is needed!
In fact, we tried to use the NODEJS library, as shown below, but we encounter problems in it.
var http = require('http'); var json_data; http.get('SiteUrl', function(response) { var bodyString = ''; response.setEncoding('utf8'); response.on("data", function(chunk) { bodyString += chunk; }); response.on('end', function() { json_data = bodyString; console.log("1---->"+json_data); }); }).on('error', function(e) { console.log("There is an error in GET request"); }); console.log("2---->"+json_data);
After debugging, we found that the problem is that Protractor does not wait for the HTTP request to complete and just jumps. We get "2 ---->" first in the console, and then "1 ---->".
source share