Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. QA Testing
  3. Question
QA Testing

How can I get an unsyntactic break after resolving a promise?

Asked by Anil Jha Apr 25, 2022 652 views 1 answer
Share

About this question

 I am writing a program to check the health endpoint of one of our APIs. So, before starting execution, I try to hit the health endpoint 5 times. If I get the desired response code during the 5 attempts, I break the loop and start test execution, else give a message saying the API is not healthy and stop the execution.


When the below function is executed, it results in an error saying unsyntactic break Can someone suggest a better way to address this? I am using cypress.


  const maxRetry = Cypress.env('maxWarmUpRetries');
  const sleepTimeMs = 200;
  console.log(chalk.yellow('Checking API health before test execution...'));
  let healthCheckResponse;
  let healthStatusCode;
  for (let i = 0; i < maxRetry>    console.log('Value of i is: ',i)
    apiHelper.requestHealth.then(response=>{
      healthCheckResponse=response;
      console.log('healthCheckStatusCode: ',healthCheckResponse.status)
      if (healthCheckResponse) {
        healthStatusCode = healthCheckResponse.status;
        if (healthStatusCode === 200) {
          console.log(chalk.green('API is healthy, moving forward with execution >>'));
          break;
        } else {
          console.log(chalk.yellow('Warm up - Checking API /health before test execution...'));
          if (i === maxRetry - 1) {
            console.log(chalk.red('Warm up - API /health is down!!! Suspending test execution.'));
            break;
          }
        }
      } else {
        console.log(chalk.yellow('Warm up - Checking API /health before test execution...'));
        if (i === maxRetry - 1) {
          console.log(chalk.red('Warm up - API /health is down!!! Suspending test execution.'));
          break;
        }
      }
    })
    
  }
});

Your answer

1 Answer

More QA Testing discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest QA Testing Blogs

Guides, tips and career advice on QA Testing from JanBask experts.