When I try to type OTP code (I get it from API), cypress shows an error cypress screenshot
cy.get('input[data-placeholder="OTP"]').type(getOtpCode(phoneNumber))
function getOtpCode(phone) {
var otpCode;
cy.request({
method: 'GET',
url: 'url'
}).then(resp => resp.body)
.then(data => data.find(element => element['body']['Message']['Phone'] == phone))
.then(phone => otpCode = phone['body']['Message']['CustomMessage']);
return otpCode;
}
If i typed a random string instead getOtpCode() it's working. Do you know how to resolve that problem? Thanks for any help :)