Forum Discussion

bhagya_prabashw's avatar
bhagya_prabashw
New Contributor
10 years ago

How to open an email on Gmail and click a link on it

Hi All,



I'm a new user of TestComplete. I need to know the scripts for how to open an email on Gmail and click on a link on the particular email body. 



Thanks,

Bhagya.

11 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Bhagya,

     


    As far as I understand, you need to identify the email by its subject on the list of all emails and click it, right? You can call the Find method for this. Here is an example:


     




    //JScript


    var page = Sys.Browser("chrome").Page("https://mail.google.com/mail/u/0/#inbox");


    var email = page.Find("contentText", "<SUBJECT>", 100);


    if (email.Exists)


     email.Click();




     

    • hhagay's avatar
      hhagay
      Contributor

      This does not work with Chrom and / or Firefox.

       

      Thank you

       

    • Ravik's avatar
      Ravik
      Super Contributor

      Thing is that, If multiple mails are available with same Subject or suppose I wanted to test Unread emails only with the given "Subject" line in this case this solution may get fail.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Ok... curiosity question... what exactly are you testing? It seems you are spending a lot of time getting TestComplete to interact with GMAIL when you are actually testing some other sort of process that is generating the email. Specifically, it sounds like you are checking to make sure a link is generated with the proper values, etc.

    So, there are two pieces to this... the process that generates the link, and the link itself which navigayes to a particular page. It seems the actual generation of the email is ancillary.

    I'm assuming there is some predictability to the link generation. So, it seems to me you don't really need to check the email, you simply need to a) check in a database or some other storage to see if an email conraining the appropriate link was generated... an SQL query might solve that and check the link against expected values then b) Simply open a browser using the predicted link value and verify that the page to which you navigated is correct. Seems that mucking around with gmail, an application outside of your scope of control, seems a futile effort as all it will take is for Google to change a bit of code and, therefore, invalidate your tests.

    Another suggestion : get with your programmers to create a simple email client for he sole purpose to receive the emails. Set up a local exchang server in your test environment and run your emails through that. This way, you control all the pieces and you no longer have to mess with Google.
    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      The only $0.02 that I can add to the otherwise absolutely exaustive Robert's reply is that if for some reason you *really need* to check with some external mail server, you may consider some other (free) mail service with much simpler UI. Mailinator.com might be one of the possible alternatives.

      • hhagay's avatar
        hhagay
        Contributor

        I agree with your comments however there are scenarios where one has to follow "user" flow in order to accomplish a case, for example; a confirmation process requires certain flow that entails an email invitation to an enrollment page which requires the user to create credentials and as a result, login.

        I understand that we can manipulate the url in most cases, but by doing so we stir away from testing the true user flow and confirm the dynamic process the server uses to deliver dynamic pages....

         

        my $0.04 :)

         

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Completely understandable on wanting to follow the user flow from end to end. Perhaps, then, it might be better to build an internal mini-email client as a test stub or use some other means rather than use Gmail.

    However, sometimes the ROI I'd prohibitive for a full end user simulation... again the amount of effort to get Gmail to work versus the actual benefit of doing an actual user experience... since the technical pieces are independent of the mail client, it may be better ROI to find an alternative to gmail.
  • Hi Tanya,



    Thanks for the Reply. But Record and Playback option or the script cannot identify the email as there will be always a new email. (In my test case first, I generate an email and then try to click it and open it from Gmail. The email title will be same). Please advise



    Thanks,

    Bhagya.
  • exispam's avatar
    exispam
    New Contributor


    Hi all,



    Not sure the reply fixes the initial problem. I'm encountering the same issue as Bhagya described it first: "how to click a link stored inside a Gmail email (or do any action with a Gmail email content)?".



    Tanya's answer allows us to open the Gmail email in a perfect way. Then, how to get the email content (in order to click a link, copy a string and any other testing purpose action)?

     



    Gmail interface seems to associate random ID to UI items. Message panel may be named "g" or "f" or any other dynamic value. No way then to use ID for message retreiving.A



    Any idea?

    Thanks in advance