Protractor and $http.post

Protractor and $http.post

本文关键字:post http and Protractor      更新时间:2023-09-26

我有一个简单的应用程序,我可以添加对话(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.
    });
});

希望能有所帮助。