Wednesday, October 30, 2013

How to book IRCTC tatkal tickets using Selenium IDE ? - Part 1.5

        Please refer to first part at How to book IRCTC tatkal tickets using Selenium IDE? before reading this article to understand the context.

This part is specially added in response to an user request. This part discusses about choosing a train and class before we fill the passenger information. This is usually done after we find the trains by providing From and To information. The below code finds the train number we gave as input in the list of trains shown and select a class (i.e, clicks on the checkbox) corresponding to the train number.

We should be having a train number and travel class with us and then we can make our selenese commands select them.


 Here is how it is drafted.



 Source

 ------------------------------------------------
<tr>
<td>store</td>
<td>//td/table/tbody/tr//td/div/table/tbody/tr[</td>
<td>part1</td>
</tr>
<tr>
<td>store</td>
<td>]/td[@class='border-btm']</td>
<td>part2</td>
</tr>
<tr>
<td>store</td>
<td>]/td[11]/input[@value='SL']</td>
<td>part3</td>
</tr>
<tr>
<td>store</td>
<td>123</td>
<td>value</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>i</td>
</tr>
<tr>
<td>while</td>
<td>${value}!=12728</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['part1']+storedVars['i']+storedVars['part2']</td>
<td>path</td>
</tr>
<tr>
<td>storeText</td>
<td>javascript{storedVars['path']}</td>
<td>value</td>
</tr>
<tr>
<td>echo</td>
<td>${value}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>parseInt(storedVars['i'])+1</td>
<td>i</td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>javascript{storedVars['part1']+(storedVars['i']-1)+storedVars['part3']}</td>
<td></td>
</tr>
 ------------------------------------------------

 Explanation:

-> Take the xpath of the train number and split into part1 and part2.

-> Take the xpath of the class and split into two parts. here first part equals to part1 of train number xpath and second one is named as part3.

-> In while loop, combine part1 and part2 to check ll train numbers in order and quit the loop if it finds the train number we are searching for.

-> Select the class after we quit the while which means we found the train number and we go to corresponding class with help of the value of "i".

-> Remember that the class is sleeper here (You can change it to any thing else)

  

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.

Wednesday, May 8, 2013

Read first few UN-Read mails from GMail using Selenium IDE

        To make yourself familiar with reading mails from GMail please read my previous post "http://www.seleniumhq.in/2013/05/read-mail-from-gmail-with-selenium-ide.html"

To know reading first few mail with help of control structures (flow control using while loop, Goto etc), please read the Previous post "http://www.seleniumhq.in/2013/05/read-first-n-mails-form-gmail-with.html".

This post explain how to read top/recent n UN-read mails from Gmail INBOX. Selenium IDE logs in to your Gmail on your behalf and give continuous n alerts with the contents of the UN-Read mails.


Below code picks up each mail by its FROM field and verifies it it is already read. If it is an Un-read mail then its contents are alerted to user by JavaScript alert, if not the next mail is considered for checking. Remember that the test case execution is paused until you click on OK of the alert. This code is very dynamic that no matter where the Un-Read mails present in the page, that gets picked up and alerted. 


Here is the Test Case:

store | //table/tbody/tr[ | target1
store | ]/td[5]/div[@class='yW'] | target2
store | //table/tbody/tr[ | targetBold1
store | ]/td[5]/div[@class='yW']//span | targetBold2
store | 1 | i
store | 1 | boldCount
click | link=Inbox * | 
while | ${boldCount}<=3 | 
storeEval | storedVars['targetBold1']+storedVars['i']+storedVars['targetBold2']+'@class' | targetBold
storeAttribute | javascript{storedVars['targetBold']} | targetBoldClass
echo | ${targetBoldClass} | 
gotoIf | storedVars['targetBoldClass']!='zF' | jump
storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
clickAt | javascript{storedVars['target']} | 
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['from']+'  '+<br/>+storedVars['subject']+'  '+<br/>+storedVars['content'])} | 
storeEval | parseInt(storedVars['boldCount'])+1 | boldCount
echo | ${boldCount} | 
goBack |  | 
label | jump | 
storeEval | parseInt(storedVars['i'])+1 | i
endWhile |  | 



Commands explained

store | //table/tbody/tr[ | target1
store | ]/td[5]/div[@class='yW'] | target2
store | //table/tbody/tr[ | targetBold1
store | ]/td[5]/div[@class='yW']//span | targetBold2
store | 1 | i
store | 1 | boldCount

Tuesday, May 7, 2013

Read first n mails form GMail with Selenium IDE

        To make yourself familiar with reading mails from GMail please read my previous post "http://www.seleniumhq.in/2013/05/read-mail-from-gmail-with-selenium-ide.html"

This post explain how to read top/recent n mails from Gmail INBOX. You just need to run the test suite of LoginToGmail and ReadFirstNMails testcases and let Selenium IDE login to your Gmail on your behalf and give continuous n alerts with the contents of the mail.



Here is the Test Case:

store | //table/tbody/tr[ | target1
store | ]/td[5]/div[@class='yW'] | target2
store | 1 | i
click | link=Inbox * |
while | ${i}<=5 |
storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
clickAt | javascript{storedVars['target']} |
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['from']+'   '+<br/>+storedVars['subject']+'   '+<br/>+storedVars['content'])} |
goBack |  |
storeEval | parseInt(storedVars['i'])+1 | i
endWhile |  |



Commands explained

store | //table/tbody/tr[ | target1
store | ]/td[5]/div[@class='yW'] | target2
store | 1 | i
Store the actual target "//table/tbody/tr[ i ]/td[5]/div[@class='yW']" in 3 parts so that the value of 'i' can be incremented later in a loop.