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
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