我正在使用Protracotr进行e2e测试。
我想在量角器中测试来自HTTP的响应。 基本上是:
我正在使用“http”NODEJS Lib来进行http调用GET + POST。
Finished in 0.019 seconds
1 test, 0 assertions, 0 failures
label: Text1
label: Text2
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
Process finished with exit code 0
我可以看到在console.log中解析的响应消息很好,但是我无法测试任何东西,我的测试结果:
{{1}}
在完成测试后记录控制台日志,并且没有完成断言。
请问,如何在Protractor中从服务器测试这些响应(采用JSON格式)?
答案 0 :(得分:2)
对于异步测试,您需要将完成的回调传递给您的函数。然后在成功时调用done()
或在失败时调用done.fail()
。请参阅Jasmine's Asynchronous support文档。
it('Test case', function(done){
httpGet("http://localhost:3333/path/1/10").then((result) => {
var json_data = JSON.parse(result.bodyString);
for (var i = 0; i < json_data.length; ++i) {
console.log("label: " + json_data[i].label);
}
done();
}).catch(err => {
done.fail();
});
});