How can I make a POST request from a Protractor test?

后端 未结 4 1342
情深已故
情深已故 2020-12-15 07:57

I would like to make a POST request (with JSON payload) to a database server prior to running a Protractor test, in order to inject test data. How can I do this, if at all p

4条回答
  •  心在旅途
    2020-12-15 08:36

    It is possible to run some async setup code in your onPrepare function of your protractor config. You need to explicitly tell protractor to wait for your request to finish. This can be done with flow.await() which plays nice with promises.

    onPrepare: function() {
    
      flow = protractor.promise.controlFlow()
    
      flow.await(setup_data({data: 'test'})).then( function(result) {
        console.log(result);
      })
    
    }
    

    ** As of protractor 1.1.0 on prepare can return a promise, so the use of flow to explictly wait for the promise to resolve is unnecessary.

    See: https://github.com/angular/protractor/blob/master/CHANGELOG.md

提交回复
热议问题