Forum Discussion

royd's avatar
royd
Regular Contributor
8 years ago
Solved

How do I access security code from email (web mail)?

Patients received two separate email after signing up with the hospital. One contains the link to the page where they can login. The second email contains a security code. Using TestComplete 12 with Jscript and pretty new to scripting.

 

I am using mailinator.com to access the emails. So far, I have successfully managed to click on the link for sign-up. Currently I am trying to figure out how to retrieve the security code from the second email. The security code email message contains the following message:

 

"Your AMG - Facility forms access code is 22RP3DPM. You will receive a link to your forms using your primary email address. You will need this access code to use the forms link. Further instructions will be available after using the access code to access the forms."

 

The text in blue remains constant in every message. The string in red (access code) is assigned dynamically. I'm trying to figure out how to get the access code from this message.

 

I really appreciate any help I can get.

 

Thanks

 

Dave

  • Here you go,

     

    If you call  getSecurityCode() then you will get return value as your security code

     

     

    function test()
    {
     Log.Message(getSecurityCode("<Your Message body text>"))
    }

     

     

     

     

    function getSecurityCode(str_EmailBody)
    {
          
          var staticStringStart = "access code is ";
          var staticStringEnd = ". You will";
          
          var startPos = aqString.Find(str_EmailBody,0,false) + aqString.GetLength(staticStringStart);
          var endPos = aqString.Find(str_EmailBody,staticStringEnd,0,false);
          
          Log.Message(aqString.SubString(str_EmailBody,startPos,endPos - startPos));
          return aqString.SubString(str_EmailBody,startPos,endPos - startPos);
    }

     

8 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Here you go,

     

    If you call  getSecurityCode() then you will get return value as your security code

     

     

    function test()
    {
     Log.Message(getSecurityCode("<Your Message body text>"))
    }

     

     

     

     

    function getSecurityCode(str_EmailBody)
    {
          
          var staticStringStart = "access code is ";
          var staticStringEnd = ". You will";
          
          var startPos = aqString.Find(str_EmailBody,0,false) + aqString.GetLength(staticStringStart);
          var endPos = aqString.Find(str_EmailBody,staticStringEnd,0,false);
          
          Log.Message(aqString.SubString(str_EmailBody,startPos,endPos - startPos));
          return aqString.SubString(str_EmailBody,startPos,endPos - startPos);
    }

     

    • royd's avatar
      royd
      Regular Contributor

      I am getting "cility forms access code is 22RP3DPM", when I am running the following script:

       

      function emailMessage(){
      
        var emailMessage = Aliases.browser.pageMailinator.frameMessage.panelAccessCode
      
        var massageString = emailMessage.GetAttribute("innerText")
      
        {
           Log.Message(massageString)
        }
      
        var staticStringStart = "access code is ";
      	var staticStringEnd = ". You will";
            
        var startPos = aqString.Find(massageString, 0, false) + aqString.GetLength(staticStringStart);
        var endPos = aqString.Find(massageString, staticStringEnd, 0, false);
            
        Log.Message(aqString.SubString(massageString, startPos, endPos - startPos));
        return aqString.SubString(massageString, startPos, endPos - startPos);
      }

      I tried var staticStringStart = "\"Your AMG - Facility forms access code is "; 

      Got same result. Can not figure out how to get rid of "cility forms access code is " !

       

      Any idea?

       

      Thanks

       

      Dave

      • shankar_r's avatar
        shankar_r
        Community Hero

        Gotcha... You missed to type the staticStringStart in your startPos code. :)

         

        var startPos = aqString.Find(massageString,staticStringStart, 0, false) + aqString.GetLength(staticStringStart);

         

    • royd's avatar
      royd
      Regular Contributor

      Thanks for such a prompt response Shankar! 

       

      I will try that and report here soon.

       

      Thank you! :)