Wait or .then in an API Test

Is there anyway to call a wait command or something similar to .then in the scripted browsers tests in a synthetics API test? I want to finished all my function calls first then assert the results. Something like this:

healthCheck(“SERVICE NAME”, “SERVICE URL”);

wait or .then

SOME ASSRT

Hi, @BigNStrauss: The $http object used by Synthetics API tests is the node.js request module. It doesn’t support promises (.then) or wait, but it does support pipe. From the docs:

request
  .get('http://google.com/img.png')
  .on('response', function(response) {
    console.log(response.statusCode) // 200 
    console.log(response.headers['content-type']) // 'image/png' 
  })
  .pipe(request.put('http://mysite.com/img.png'));

You may also implement .then yourself, using the native JavaScript Promise class, as shown here: https://www.tomas-dvorak.cz/posts/nodejs-request-without-dependencies/,

1 Like

Hi @BigNStrauss - I created a sample api script for maintenance window workarounds which is a promise based script.

1 Like