Monday, May 6, 2013

Read mail from Gmail with Selenium IDE.

     This post explain how to read the recent mail (top most mail) from Gmail INBOX. If you are busy with some other work and want to know who was the last person to disturb you in mail then you can just run the test suite of LoginToGmail and ReadMail testcases and let Selenium IDE login to your Gmail on your behalf and alert you with the contents of the mail.

To read how to login and other stiff then please follow my older posts here "http://www.seleniumhq.in/2013/04/automatically-login-to-gmail-and-send.html"


How:

We will locate the FROM field of the top most mail and enter into the mail details page where we capture FROM, SUBJECT and the mail content. Finally the mail format is displayed to you in an JavaScript alert.


Here is the Test Case:

    click | link=Inbox * |
    clickAt | //table/tbody/tr/td[5]/div[@class='yW'] |
    storeText | class=hP | subject
    storeText | class=iw | from
    storeText | //div[2]/div/div/div/div/div/div/div[2]/div[6]/div | content
    storeEval | javascript{alert(storedVars['subject']+storedVars['from']+storedVars['content'])} |


Commands explained:

click | link=Inbox * |
Click on the INBOX link

clickAt | //table/tbody/tr/td[5]/div[@class='yW'] |
Click at the FROM field of first/recent/top most mail to go to mail detail page. //tr for first mail, tr[2] for second and so on.



storeText | class=hP | subject
Store SUBJECT in a variable "subject"

storeText | class=iw | from
Store FROM in a variable "from"

storeText | //div[2]/div/div/div/div/div/div/div[2]/div[6]/div | content
Store mail content in a variable "content"

storeEval | javascript{alert(storedVars['subject']+storedVars['from']+storedVars['content'])} |
Show all the above fields in an alert.



Source
----------------------------------------
 <tr>
    <td>click</td>
    <td>link=Inbox *</td>
    <td></td>
</tr>
<tr>
    <td>clickAt</td>
    <td>//table/tbody/tr/td[5]/div[@class='yW']</td>
    <td></td>
</tr>
<tr>
    <td>storeText</td>
    <td>class=hP</td>
    <td>subject</td>
</tr>
<tr>
    <td>storeText</td>
    <td>class=iw</td>
    <td>from</td>
</tr>
<tr>
    <td>storeText</td>
    <td>//div[2]/div/div/div/div/div/div/div[2]/div[6]/div</td>
    <td>content</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>javascript{alert(storedVars['subject']+storedVars['from']+storedVars['content'])}</td>
    <td></td>
</tr>

---------------------------------------

Here is how the alert is shown:




End Of Post.

No comments:

Post a Comment