量角器和 $http.post
Protractor and $http.post
我有一个简单的应用程序,我可以在其中添加对话(Q/A)。我已经为它写了测试 -
describe('New Survey:', function() {
it('should be added', function() {
browser.get('http://127.0.0.1:8090/#/newConversation');
//picking a user
element.all(by.css('.form-control')).get(5).click();
element(by.model('vm.user')).sendKeys('test');
element(by.repeater('user in vm.users').row(6)).click();
//push some answers
var inputs = element.all(by.css('.form-control.validated')).each(function(element,index){
element.sendKeys('test answer');
});
//and send it
element(by.id('submit')).click();
element(by.css('.confirm')).click()
browser.waitForAngular();
});
});
点击 .confirm
按钮后
这个方法叫做
this.saveSurvey = function(conv) {
return $http.post('/conv', conv);
};
但是量角器不会等到它完成所以实际上没有对话发送到服务器我怎么让它等到 post 完成?
您可以等待 click()
函数执行,您的 post 请求通过等待其承诺返回来发送。方法如下 -
element(by.id('submit')).click().then(function(){
element(by.css('.confirm')).click().then(function(){
browser.sleep(2000);
//If your server returns a response in some way that the conversation is saved, you can verify it here.
});
});
希望对您有所帮助。
我有一个简单的应用程序,我可以在其中添加对话(Q/A)。我已经为它写了测试 -
describe('New Survey:', function() {
it('should be added', function() {
browser.get('http://127.0.0.1:8090/#/newConversation');
//picking a user
element.all(by.css('.form-control')).get(5).click();
element(by.model('vm.user')).sendKeys('test');
element(by.repeater('user in vm.users').row(6)).click();
//push some answers
var inputs = element.all(by.css('.form-control.validated')).each(function(element,index){
element.sendKeys('test answer');
});
//and send it
element(by.id('submit')).click();
element(by.css('.confirm')).click()
browser.waitForAngular();
});
});
点击 .confirm
按钮后
这个方法叫做
this.saveSurvey = function(conv) {
return $http.post('/conv', conv);
};
但是量角器不会等到它完成所以实际上没有对话发送到服务器我怎么让它等到 post 完成?
您可以等待 click()
函数执行,您的 post 请求通过等待其承诺返回来发送。方法如下 -
element(by.id('submit')).click().then(function(){
element(by.css('.confirm')).click().then(function(){
browser.sleep(2000);
//If your server returns a response in some way that the conversation is saved, you can verify it here.
});
});
希望对您有所帮助。