因此,我试图通过量角器使用POST命中端点。我已经写了很多不同的代码来尝试使它工作。如何使用量角器发送POST
因此,我使用'请求'作为我的http客户端似乎最流行,并发现其他http客户端,并考虑尝试这些,如果我不能让这个工作。
我也使用黄瓜和柴作为承诺。所以运行这个结果是没有用的。所以当我运行这个黄瓜测试,并通过这个函数时,它不会执行request.post。它只是进入下一步。没有错误显示在控制台中。我用一个REST客户端来做一个GET来检查POST是否工作,并且发现它不起作用。 我需要一些帮助来解决它为什么这样做。
它会有所作为如果我把发布请求放到其他地方的类的函数中。我打电话给它发送适当的变量?
下面是代码:
this.When(/^I test this$/, function (next) {
var request = require('request');
var options = {
headers: {
'id': 'AQ8WHWC',
'sessionid': 'XnINW5KDQg=',
'Accept': 'application/json',
'Accept-Language': 'en-us',
'random': 'BS3P5Q'
},
form: { "pay_load": [] }
};
request.post('http://myurl.com/endpoint/test/', options, callback);
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(info);
}
}
browser.sleep(1).then(next)
});
运行黄瓜测试的控制台输出:
Scenario: this is a cool test
# endpoint/test/testing.feature:7
Given I run this endpoint test
# endpoint/test/testing.feature:8
When I test this
# endpoint/test/testing.feature:9
Then I see this
# endpoint/test/testing.feature:10
1 scenario (1 passed)
3 steps (3 passed)
[launcher] chrome passed
Done, without errors.
你什么错误? – Saifur 2014-11-03 23:25:02
控制台没有任何错误。它在测试中显示全部绿色。但是当我从其他客户端运行GET时。我看到POST不起作用。 – adbarads 2014-11-03 23:26:09
我加了控制台输出 – adbarads 2014-11-03 23:43:27