Thursday, May 9, 2013

Find unread count of all folders / Mail box in GMail using Selelnium IDE

See my previous posts related to Gmail below:
http://www.seleniumhq.in/2013/05/read-mail-from-gmail-with-selenium-ide.html
http://www.seleniumhq.in/2013/05/read-first-n-mails-form-gmail-with.html
http://www.seleniumhq.in/2013/05/read-first-few-un-read-mails-using.html

This post explain how to read and display the number of unread mail from all GMail default folders such
as Inbox, Sent mail, Drafts, Trash, Spam and Starred etc.

Below test case iterates through all the folders (Inbox, Sent etc) available at left of the mailbox account and pickup the text of the <a> tag (ex: Inbox(3214), Sent(23), Spam(56) etc). All these counts along with the folder name are read to a variable and printed to an alert.



Here is the Test Case:

store | //div[@class='LrBjie']/div/div[ | target1
store | ]/div/div/div/span/a | target2
store | 1 | i
store | true | present
store |  | countsAll
while | ${present}==true |
storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
echo | ${target} |
storeText | javascript{storedVars['target']} | counts
storeEval | storedVars['countsAll']+'&nbsp;&nbsp;$&nbsp;&nbsp;'+storedVars['counts'] | countsAll
echo | ${countsAll} |
storeEval | parseInt(storedVars['i'])+1 | i
storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
storeElementPresent | javascript{storedVars['target']} | present
echo | ${present} |
endWhile |  |
storeEval | javascript{alert(storedVars['countsAll'])} | countsAll


Commands explained

store | //div[@class='LrBjie']/div/div[ | target1
store | ]/div/div/div/span/a | target2
store | 1 | i
store | true | present
store |  | countsAll

Store the actual target of Inbox link "//div[@class='LrBjie']/div/div[i]/div/div/div/span/a" in 3 parts so that the value of 'i' can be incremented later in a loop. Initialize a variable 'present' to allow first iteration at while loop. And, Initialize a variable 'countsAll' to empty.


while | ${present}==true |
Loop until there are folders available.

storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
For every iteration we are storing the target of each folder (Xpath) in a variable named "target" to read the text from it (from <a> tag).

storeText | javascript{storedVars['target']} | counts
Store the text at the <a> tag //ex: Inbox(3214)

storeEval | storedVars['countsAll']+' $ '+storedVars['counts'] | countsAll
Store the texts of all folders in a single variable separetd by a "$" symbol //can be any separator

storeEval | parseInt(storedVars['i'])+1 | i
Increment "i'"

storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
We are forming the XPath of next folder's <a> tag.

storeElementPresent | javascript{storedVars['target']} | present
Srore TRUE/FALSE if the folder is actually present there

endWhile |  |
Stop and  restart While

storeEval | javascript{alert(storedVars['countsAll'])} | countsAll
Display alert with all the folder counts.


Source:
-------------------------
<tr>
    <td>store</td>
    <td>//div[@class='LrBjie']/div/div[</td>
    <td>target1</td>
</tr>
<tr>
    <td>store</td>
    <td>]/div/div/div/span/a</td>
    <td>target2</td>
</tr>
<tr>
    <td>store</td>
    <td>1</td>
    <td>i</td>
</tr>
<tr>
    <td>store</td>
    <td>true</td>
    <td>present</td>
</tr>
<tr>
    <td>store</td>
    <td></td>
    <td>countsAll</td>
</tr>
<tr>
    <td>while</td>
    <td>${present}==true</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>storedVars['target1']+storedVars['i']+storedVars['target2']</td>
    <td>target</td>
</tr>
<tr>
    <td>echo</td>
    <td>${target}</td>
    <td></td>
</tr>
<tr>
    <td>storeText</td>
    <td>javascript{storedVars['target']}</td>
    <td>counts</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>storedVars['countsAll']+'&nbsp;&nbsp;$&nbsp;&nbsp;'+storedVars['counts']</td>
    <td>countsAll</td>
</tr>
<tr>
    <td>echo</td>
    <td>${countsAll}</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>parseInt(storedVars['i'])+1</td>
    <td>i</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>storedVars['target1']+storedVars['i']+storedVars['target2']</td>
    <td>target</td>
</tr>
<tr>
    <td>storeElementPresent</td>
    <td>javascript{storedVars['target']}</td>
    <td>present</td>
</tr>
<tr>
    <td>echo</td>
    <td>${present}</td>
    <td></td>
</tr>
<tr>
    <td>endWhile</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>javascript{alert(storedVars['countsAll'])}</td>
    <td>countsAll</td>
</tr>
-------------------------

The alert is shown like this.




End Of Post

No comments:

Post a Comment