简体   繁体   English

量角器和$ http.post

[英]Protractor and $http.post

I have simple app where i can add conversations(Q/A). 我有一个简单的应用程序,可以在其中添加对话(Q / A)。 I have written test for it - 我已经为此写了测试-

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();
  });
});

after clicking .confirm button this method is called 单击.confirm按钮后,此方法称为

this.saveSurvey = function(conv) {
        return $http.post('/conv', conv);
    };

but protractor does not wait until its done so no conversation is actually sent to server how could i make it to wait until post is done? 但是量角器不会等到完成后才将对话真正发送到服务器,我如何才能等到发布完成后呢?

You can wait for the click() function to execute and your post request to be sent by waiting for its promise to be returned. 您可以等待click()函数执行并通过等待其诺言返回来发送您的帖子请求。 Here's how - 这是如何做 -

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.
    });
});

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM