Select a random wordpress blog entry and then click to open it
What you will learn from this example?
- command: storeXpathCount
- command: echo for debugging
- command: store
- command: storeEval
- command: CaptureEntirePageScreenshot
- javascript functions
- xpath and xpather to select an entry
Pre-requisites:
>> Firefox browser having Selenium IDE
Tips when executing:
- If your script fails on the xpath command, check that you are logged out of wordpress
How to establish the xpath for the blog entry click?
* open up firefox
* goto http://localhost/wordpress/
* right click on the first blog entry link and select "show in xpather" ( install xpather here)
* check that the xpath extracted indeed extracts the text/web clipping for the blog entry you have xpathed
* now copy the xpath into notepad++
/html/body[@class='home blog']/div[@class='hfeed' and position()=1]/div[2]/div[1]/div/div[@class='post-52 post type-post hentry category-uncategorized' and position()=2]/h2[@class='entry-title']/a* modify the xpath to make it generic and retest in xpather and notice the same result as before
/html/body[@class='home blog']/div[@class='hfeed' and position()=1]/div[2]/div[1]/div/div[position()=2]/h2[@class='entry-title']/a* modify again and change [position()=2] to [position()=3] and retest in xpather and notice the next blog entry is selected.
/html/body[@class='home blog']/div[@class='hfeed' and position()=1]/div[2]/div[1]/div/div[position()=3]/h2[@class='entry-title']/a* now finally, to we want to use a variable for the blog entry position ${RandonBlogEntryId}
/html/body[@class='home blog']/div[@class='hfeed' and position()=1]/div[2]/div[1]/div/div[position()=${RandomBlogEntryId}]/h2[@class='entry-title']/a
* put the this xpath in quotes and place into Selenium IDE for the command storeEval"/html/body[@class='home blog']/div[@class='hfeed' and position()=1]/div[2]/div[1]/div/div[position()=${RandomBlogEntryId}]/h2[@class='entry-title']/a"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhost" />
<title>selectRandomBlogEntry</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">selectRandomBlogEntry</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/wordpress/</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//h2</td>
<td>countId</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{"xpath count " + storedVars['countId'];}</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>javascript{ var mycountId = storedVars['countId']; Math.floor(Math.random()*(mycountId)); }</td>
<td>RandomBlogEntryId</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{"randomBlogEntryId=" + storedVars['RandomBlogEntryId'];}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>"/html/body[@class='home blog']/div[@class='hfeed' and position()=1]/div[2]/div[1]/div/div[position()=${RandomBlogEntryId}]/h2[@class='entry-title']/a"</td>
<td>myxpath</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{"myxpath=" + storedVars['myxpath'];}</td>
<td></td>
</tr>
<tr>
<td>clickAtAndWait</td>
<td>xpath=${myxpath}</td>
<td></td>
</tr>
<tr>
<td>captureEntirePageScreenshot</td>
<td>D:\PROFILES\doshiv2\.hudson\jobs\wordpresstest\workspace\wordpressScreenshot_SelectRandomBlogEntry.jpg</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
http://www.digitalcoding.com/tools/convert-htmlentities.html
feedback for vipin:
ReplyDelete1. can you ensure that this example works in teh VM.
2. modify if necessary
3. Also, create a video
ensure to use xpather as per the steps.
Viresh's feedback for vipin:
ReplyDelete1. can you ensure that this example works in teh VM.
2. modify if necessary
3. Also, create a video
ensure to use xpather as per the steps.
Here is the posted solution link for your feedback:
ReplyDeletehttp://time2testcourse.blogspot.com/2011/06/example-select-random-wordpress-entry.html