Need help looping a function to retrieve the value from an API in my Cypress project. The goal is to call the API multiple times until we receive the desired value.
let otpValue = '';
const loopFunc = () => {
cy.request({
method: 'GET',
url: 'http://tesurl/api/otp/getotp',
}).then((res) => {
expect(res.status).to.equal(200);
res.body.OTPCode !== null ? (otpValue = res.body.OTPCode) : loopFunc();
});
};
cy.get('otpinput').type(otpValue)
However, I'm encountering issues with the loop function not functioning as expected. I anticipate that the loop will continue running until we retrieve a non-null value for 'OTPCode'.
Thank you in advance for any assistance.