Outlook how to check if the email sent is received in the folder

Hi im testing an outlook plug in right now and am able to send an email. However i cant seem to automate the process of checking the folder to see if the email sent is there.

I am currently trying to achieve this by using these identifiers to check for the email in the folder:

if (Windows.verifyElementPresent(findWindowsObject(Object Repository/Folder Test Storage/Text[@id=’ + folderId + ‘][contains(@subject,’ + expectedSubjectPrefix + ‘) and contains(@subject,’ + currentTimestamp + ')]), verificationTimeWindow, FailureHandling.OPTIONAL)) {
println(Sent email found in the specified folder within the time window.)
} else {
println(ERROR: Sent email not found in the specified folder within the time window.)
}

Is my method wrong and is there some other way to get Katalon to recognise the contents in a folder?

Hi,

Katalon has not had an official way to do this but you can try JavaMail Library

hi @jadon3011

scraping the outlook message list through winappdriver is fragile, the list is virtualised so items that are scrolled out of view are not in the ui tree at all, which is why a subject that exists is still “not found”. since outlook is already running on that machine, ask outlook itself through its com object. a few lines of powershell from the test case:

def ps = '''
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNamespace("MAPI")
$folder = $ns.GetDefaultFolder(6).Folders.Item("Test Storage")
$items = $folder.Items.Restrict("[Subject] like '%''' + expectedSubjectPrefix + '''%'")
$items.Count
'''
def proc = ['powershell', '-NoProfile', '-Command', ps].execute()
proc.waitFor()
int count = proc.text.trim().toInteger()
assert count > 0 : 'sent email not found in folder'

GetDefaultFolder(6) is the inbox, use .Folders.Item(“name”) to walk into subfolders, or ns.Folders for a different account. Restrict takes the same filter syntax as outlook rules, so you can match ReceivedTime too. it returns in milliseconds and does not care whether the folder is on screen.

if the mailbox is office 365 you could also hit the graph api with a bearer token, but the com route needs no setup since the plugin test already has outlook open.