Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have merely just had a kick off meeting for a new project that I am required to automate ASAP. The project is essentially a "mailbox project", if you will, and I have no idea as to where to start my test automation on this type of project as I am fairly new to selenium automation. Emails will however be sent/received via Gmail. I would really appreciate any help or advice on how/where to start my automation with regards to this project... if at all possible :).

The framework I am using is Eclipse, TestNG and of course selenium:). Language - Java

share|improve this question
What does it mean for emails to be sent via Gmail? Do you mean you will use Google's SMTP servers, or do you intend to send emails via the browser? – user246 Jan 19 '12 at 14:47

10 Answers 10

If I remember correctly, automating the use of GMail is a technical violation of their terms of service. It's not something that their likely to take action against you for, as many other people/companies do do this as well.

From Google Terms of Service

5.3 You agree not to access (or attempt to access) any of the Services by any means other than through the interface that is provided by Google, unless you have been specifically allowed to do so in a separate agreement with Google. You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers) and shall ensure that you comply with the instructions set out in any robots.txt file present on the Services.

Do you actually need to login to the google site in order to do this?

If you wanted to, you could definitely use a third party client, and, it will probably run faster than to access it through the UI.

I'm sure that you could do something similar with Java and a third party client, so, I'll give you how I normally handle email using outlook. I typically setup a folder for each application that I need to validate the emails that were sent. From there, I have my code access the client and then the specific folder. When in the folder, I attempt to Match the From, To, CC, Subject, and body with my expected values. If I don't need to verify much, I'll just pass these in as parameters. If I'm having to validate all of the information, I would typically create some strings that I could set to the values of what I need to check and then attempt the match. This is easier to do than through the UI as well.

share|improve this answer
Where the technical violation of automating GMail is concerned,i was not aware of that AT ALL and appreciate you actually making me aware of that,thanx. I have however gave it some thought and the way i was intending on going about this was to actually have a "tester GMail account",whereby i login using the "tester account" credentials and do a simple UI automation technique where i would use the search feature of GMail to assert the unread email(subject) and verify whether all text is present after opening the mail. I really am clueless as to how i can go about this:(. – Faheem Jan 19 '12 at 12:54
Updated answer with reference and a possible workaround. – Lyndon Vrooman Jan 19 '12 at 14:19
+1 For reading the Terms of Service! ;-) – Alberto Jan 19 '12 at 19:13

Look into the Javamail API and Dumbster (Fake SMTP Server).

share|improve this answer

I think you really don’t need to automate Gmail UI unless you are working for Google.

  1. I bet your application requires an SMTP server configuration. So, it uses SMTP protocol to send email to Gmail. In this case you can search Google for “SMTP for developers”. And choose some SMTP server that fits your needs. In this program turns your workstation into the real SMTP server and it will store the emails your application sent into some specific folder as a text file. So, you could check that your application had sent the email and look its content.

  2. But, if the first case is not appropriate for you, then you could use the POP3 client in your Java code. Your Application will send the email using the real smtp server, that email will be stored on the Gmail server and then you could receive it using your test code. You could change/allow the POP3 protocol in the Gmail settings.

Anyway, automated checking of the text formatting through the Gmail interface will be really painful for automation. But if you want to check that the application had sent the email, and the email is in the server and it has correct content – use a POP3 client/Development SMTP Server.

share|improve this answer
Hey Dmitry. I've had a look at POP3 client and as i have mentioned before,in my question,i am fairly new to all of this and i merely know the fundamentals in Java. I have however done some research on POP3 client and it seems really simple to implement. So i will definitely give it a shot. Thank you so much :). (I'm really digging this SQA community/website..its awesome :D). – Faheem Jan 20 '12 at 8:16

Here's what I'll suggest:

Setup a library, have it accept the mails and send to Gmail when your app is running in production mode. But when the app is running in development/testing mode, have your emails stored in database. Now create a simple script to show all mails from the database (keep this script under same URL as app). While testing, access this script from browser to read the emails. We've been doing this from quite a while now.

This way you also speed up your app's testing because you don't have to retrieve data from remote server.

share|improve this answer
I will not be the one who will be sending the mails,all i am required to do is to verify that the mail has been sent to the correct user and verify that the content of the mail is correct. The starting point for the mail to be sent however is the website...this is merely a reply to an ad that goes via a message center and i would have to make sure that the process actually works. (The company I work for is a classifieds company,which mainly deals with ads..thus reply via mail to an ad) – Faheem Jan 19 '12 at 13:04
Yes, you can keep a simple 'test_mails' table in your database with fields like to, from, body, headers etc. etc. and implement a custom assert function then. Of course, this is limited till your application is in test mode. If you're planning to verify this function in production mode, you'll need some other type of setup. – Abhimanyu Jan 28 '12 at 10:19
+1 this helped me – Pieter Willaert Jan 25 '13 at 13:28

Keeping in mind your excerpt : " I have however gave it some thought and the way i was intending on going about this was to actually have a "tester GMail account",whereby i login using the "tester account" credentials and do a simple UI automation technique where i would use the search feature of GMail to assert the unread email(subject) and verify whether all text is present after opening the mail. I really am clueless as to how i can go about this:( "
And Assuming that you are well aware and comfortable /got permission with Google terms of service as mentioned in one of the answers and would like to try from the UI , you could try this bit below:

Login to your "tester gmail acount" in basic HTML view.
Input your search term in the "search box" and search.
If there are no mails in the search results : exit.
While there are unread mail/s (there would be an css identifier to differentiate from read mails): Do Open the mail and verify whether all text is present .

You could quickly bootstrap this code using selenium ide, export the same to eclipse java and add the loops.

OR If you would not prefer to interact with the gmail UI and use a client i.e IMAP , there is some useful stuff here ,which is a superset and can be easily tweaked to cover the issue in concern here.

share|improve this answer
The link you provided in your response is a really seems to be exactly what i have been looking for and i will most certainly give it a shot :).!* Thanks a mill for your advice/suggestions,its highly appreciated. – Faheem Jan 20 '12 at 7:11

Though the question is not so specific on what part of that web mail is to be automated, the best solution for whatever your question is Selenium IDE.

If your tests involved repeated logins, and sending mails to many then you can instal this addon to firefox and start recording your tests like login to gmail and compose and send mails.

You can find related code and steps for this at stackoverflow and many other blogs such as seleniumhq dot in.

share|improve this answer

Try out It gives you unlimited test email addresses and allow for automated and manual testing of emails.

We have Java, .NET, Ruby, Python and Node.js bindings to make it easy to integrate this in your Selenium test scripts.

Disclosure: I am a co-founder.

share|improve this answer
very nice api altough it would be nice to have option to wait for specific email to arrive without a need to fetch api in intervals... – Marko Jun 7 at 18:55

I just replaced our Gmail-based tests with a tool called Inbucket ( and just query its REST API to check the email contents. It works pretty well so far. If you use c#, it's pretty simple to create a small class to query the API using RestSharp.

share|improve this answer

GMail has official JAVA API. Here is your bag:

share|improve this answer

Here is what we did at my company: write a webapp that talks to Gmail over IMAP. The webapp displays your inbox, or individual messages, in a form that is easy for Webdriver to process. It can also display individual messages.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.