Before delving into my test script, let me provide some context.
Triggering a button on a website will result in an email being sent to a designated test mailbox.
This email typically arrives within a timeframe of 10 to 30 minutes.
To extract the pertinent details, I utilize code from imap-simple ;
'obtain new email information': function(browser) {
imaps.connect(config).then(function (connection) {
return connection.openBox('INBOX').then(function () {
var searchCriteria = ['UNSEEN'];
var fetchOptions = {
bodies: ['HEADER', 'TEXT'],
markSeen: false
};
return connection.search(searchCriteria, fetchOptions).then(function (results) {
var subjects = results.map(function (res) {
return res.parts.filter(function (part) {
return part.which === 'HEADER';
})[0].body.subject[0];
});
console.log(subjects);
Initially, the subjects array is empty since the email hasn't reached the test mailbox yet.
Introducing a 30-minute delay at the beginning of the script does yield fruitful results eventually, once the email arrives (typically within that time frame).
However, this approach is not optimal as the email may arrive sooner, leading to a wastage of time.
Hence, my goal is to implement a loop of sorts to check if the subjects array has been populated.
If the array contains data, proceed with the remaining tests to validate specific text within it.
If the array remains empty, wait for another minute before retrying.
This iterative process continues until the array is filled with relevant content.
I've experimented with various methods like setInterval, For loops, and While loops without success, seeking guidance or references to overcome this challenge.
Your assistance and insights would be highly appreciated, and I'm ready to provide additional information if necessary.