I am using Cypress to test this feature: I need to fetch an OTP from another URL in order to complete the deletion of a bucket. The rest of the script runs perfectly, except for the last line, where it should type the OTP into the field - if I leave the line where it is now, cypress does not run/see it, and if I move it down, the variables are deemed "undefined".
ps - URL to Ops platform removed and usernames are defined in another file.
Can someone please help me figure out where I am going wrong?
describe('Delete Bucket', function() {
it('---4. Deletes a bucket', function() {
//Click on trash bin icon
cy.get('[data-testid=bucket-delete-0]').click();
//Click on Continue
cy.get('[data-test="continue-bucket-delete"]').click({timeout:10000}).then(() => {
cy.fixture('users').then((users) => {
let username = users.paid.username;
let password = users.paid.password;
var url = "URL to our internal OPS platform from where OTP is fetched";
new Cypress.Promise((resolve, reject) => {
var data = {
"username": username,
"password": password,
};
var formBody = [];
for (var property in data) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(data[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: formBody
})
.then((resp) => {
resp.json()
.then((data) => {
//THIS IS THE PROBLEMATIC LINE - CURRENTLY NOT PICKED UP BY CYPRESS
**cy.get('[name=otp]').type(otp=["sms"]).tab().tab().click({force:true});**
}); //close fixture
});
});
});
});
}); //close it
}); //close describe ````