vondie
9 years agoContributor
Wildcard Not Recognized in URL within an Email
Currently using TC 11.20 and writing scripts using Python. I am working on a script that checks the body content of my last email in my inbox (Outlook). My end goal is to click a URL within an email to reset a password. My code can identify the URL when I do not put a wildcard at the end, but then the URL is incorrect (should have 'password-reset/b632ffa303463b9445a5685697b0e352' on the end for this example). The URL will change each time the "Forgot Password" link is clicked within the application. Any ideas how I can get this to work? Thanks in advance for your help!
def check_email(): msOutlook = Sys.OleObject["Outlook.Application"] mapi = msOutlook.GetNamespace("MAPI") inbox = mapi.Folders("test@test.com").Folders("Inbox") messages = inbox.Items message = messages.getLast() body_content = message.body url = "http://qaregapps.testurl.com:123456/test/admin/password-reset/*" Log.Message(body_content) if url in str(body_content): Browsers.Item(btFirefox).Navigate(url) Log.Message(url) else: Log.Message("Email not received.")
Thank you both for your input! I decided to follow a little of both pieces of advice and developed the solution below.
def check_email(): msOutlook = Sys.OleObject["Outlook.Application"] mapi = msOutlook.GetNamespace("MAPI") inbox = mapi.Folders("test@test.com").Folders("Inbox") messages = inbox.Items message = messages.getLast() body_content = str(message.body) s = 'http://qaapps.test.com:12345/test/admin/password-reset/' time.sleep(10) if s in body_content: url = body_content[237:347] Browsers.Item[btFirefox].Run(url) Log.Message("Test passed!") else: Log.Message("Email not received. Please open bug in JIRA.")