Protractor 如何知道回调rest调用量角器的响应
我正在运行一个自动化脚本。我们有一个场景,Java对UI进行回调REST调用。下面是我对该URL执行httpGet的代码。我想知道什么时候有回应。如果是这样的话,怎么知道呢。我找了很多东西,但到处都找不到明确的答案。请给我一些提示Protractor 如何知道回调rest调用量角器的响应,protractor,e2e-testing,Protractor,E2e Testing,我正在运行一个自动化脚本。我们有一个场景,Java对UI进行回调REST调用。下面是我对该URL执行httpGet的代码。我想知道什么时候有回应。如果是这样的话,怎么知道呢。我找了很多东西,但到处都找不到明确的答案。请给我一些提示 http.get(siteUrl, function(response) { var bodyString = ''; response.setEncoding('utf8'); response.on("data
http.get(siteUrl, function(response) {
var bodyString = '';
response.setEncoding('utf8');
response.on("data", function(chunk) {
bodyString += chunk;
});
response.on('end', function() {
defer.fulfill({
statusCode: response.statusCode,
bodyString: bodyString
});
});
}).on('error', function(e) {
defer.reject("Got http.get error: " + e.message);
});
//If we are sure that response has come, then extract it
httpGet("http://testurl").then(function(result) {
//alert('inside test automation');
console.log(result);
});
您可以使用“响应代码”的响应详细信息,无论成功与否,有很多方法将接口用作回调,使用通过检查响应代码的方法,有很多可用的网络库-volley、okhttp等 帮助:
希望这会有所帮助
祝您好运。您可以使用从量角器测试进行API调用。
if(response.statusCode == 200) {
// do success work read response etc...
// you can call methods what you want if success happen
} else {
// you can check other status code too..
// call methods if api get fail.
}