Chap 2, pagination section, pages 55-56.
I am testing the pagination on the forums.
You have to type in a lot of messages to test it.
One way to get around this would be to just set the $display
variable from 25 down to something low, like 4.
Another way to do this is to automatically enter the data.
That's the way I did it. I've posted my scripts here if anyone
wants to try testing it this way. You will have to change the
paths to your own.
I used the Selenium IDE open source web testing tool to automatically
populate the forum with messages. You can download Selenium tool
and use it for free.
I used the data driven capability of Selenium.
I generated an xml file and then the Selenium script loads
that xml file, and loops through the data to automatically write messages.
I have included the Selenium code, the xml data file,
and a small easy Perl program used to generate the xml data file.
I made the message subjects similar and used numbers.
my subject 1
my subject 2
...
my subject 30
This way it's easy to see that you got them in the right sequence.
In the script I also had it reply to each message.
Here is the Selenium code. You can copy it to an .html file and look at it in a browser.
HTML Code:
<?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://www.mydomain.com/myapp/mymain.php" />
<title>forum_pagination_test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">forum_pagination_test</td></tr>
</thead><tbody>
<!--//load the test data-->
<tr>
<td>loadTestData</td>
<td>file:///C:/Documents and Settings/myname/My Documents/selenium/testsken/forum_testdata.xml</td>
<td></td>
</tr>
<!--// Start on main page which has link named forums-->
<tr>
<td>open</td>
<td>/myapp/mymain.php</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=forums</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=exact:Create new forum</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=forum_name</td>
<td>myforum1</td>
</tr>
<tr>
<td>type</td>
<td>forum_desc</td>
<td>My first forum</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//input[@value='Create']</td>
<td></td>
</tr>
<!--// done creating forum-->
<!--//Now click on first forum-->
<tr>
<td>clickAndWait</td>
<td>link=exact:myforum1: My first forum</td>
<td></td>
</tr>
<!--each iteration through loop creates new message and reply-->
<!--the data for the message comes from 1 line in the data file-->
<tr>
<td>while</td>
<td>!testdata.EOF()</td>
<td></td>
</tr>
<tr>
<td>nextTestData</td>
<td></td>
<td></td>
</tr>
<!--//post a message-->
<tr>
<td>clickAndWait</td>
<td>link=Post new message.</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>msg_subject</td>
<td>${msg_subject}</td>
</tr>
<tr>
<td>type</td>
<td>msg_text</td>
<td>${msg_text}</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//input[@value='Create']</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=10/19/2009: ${msg_subject}</td>
<td></td>
</tr>
<!--//post a reply-->
<tr>
<td>clickAndWait</td>
<td>link=Reply</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>msg_subject</td>
<td>${msg_reply_subject}</td>
</tr>
<tr>
<td>type</td>
<td>msg_text</td>
<td>${msg_reply_text}</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//input[@value='Create']</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Here is the xml data file that it loads.
HTML Code:
<testdata>
<test
msg_subject="my subject 1"
msg_text="This is my text for subject 1"
msg_reply_subject="Reply to subject 1"
msg_reply_text="This is the text of my reply for subject 1"
/>
<test
msg_subject="my subject 2"
msg_text="This is my text for subject 2"
msg_reply_subject="Reply to subject 2"
msg_reply_text="This is the text of my reply for subject 2"
/>
<test
msg_subject="my subject 3"
msg_text="This is my text for subject 3"
msg_reply_subject="Reply to subject 3"
msg_reply_text="This is the text of my reply for subject 3"
/>
<test
msg_subject="my subject 4"
msg_text="This is my text for subject 4"
msg_reply_subject="Reply to subject 4"
msg_reply_text="This is the text of my reply for subject 4"
/>
<test
msg_subject="my subject 5"
msg_text="This is my text for subject 5"
msg_reply_subject="Reply to subject 5"
msg_reply_text="This is the text of my reply for subject 5"
/>
<test
msg_subject="my subject 6"
msg_text="This is my text for subject 6"
msg_reply_subject="Reply to subject 6"
msg_reply_text="This is the text of my reply for subject 6"
/>
<test
msg_subject="my subject 7"
msg_text="This is my text for subject 7"
msg_reply_subject="Reply to subject 7"
msg_reply_text="This is the text of my reply for subject 7"
/>
<test
msg_subject="my subject 8"
msg_text="This is my text for subject 8"
msg_reply_subject="Reply to subject 8"
msg_reply_text="This is the text of my reply for subject 8"
/>
<test
msg_subject="my subject 9"
msg_text="This is my text for subject 9"
msg_reply_subject="Reply to subject 9"
msg_reply_text="This is the text of my reply for subject 9"
/>
<test
msg_subject="my subject 10"
msg_text="This is my text for subject 10"
msg_reply_subject="Reply to subject 10"
msg_reply_text="This is the text of my reply for subject 10"
/>
<test
msg_subject="my subject 11"
msg_text="This is my text for subject 11"
msg_reply_subject="Reply to subject 11"
msg_reply_text="This is the text of my reply for subject 11"
/>
<test
msg_subject="my subject 12"
msg_text="This is my text for subject 12"
msg_reply_subject="Reply to subject 12"
msg_reply_text="This is the text of my reply for subject 12"
/>
<test
msg_subject="my subject 13"
msg_text="This is my text for subject 13"
msg_reply_subject="Reply to subject 13"
msg_reply_text="This is the text of my reply for subject 13"
/>
<test
msg_subject="my subject 14"
msg_text="This is my text for subject 14"
msg_reply_subject="Reply to subject 14"
msg_reply_text="This is the text of my reply for subject 14"
/>
<test
msg_subject="my subject 15"
msg_text="This is my text for subject 15"
msg_reply_subject="Reply to subject 15"
msg_reply_text="This is the text of my reply for subject 15"
/>
<test
msg_subject="my subject 16"
msg_text="This is my text for subject 16"
msg_reply_subject="Reply to subject 16"
msg_reply_text="This is the text of my reply for subject 16"
/>
<test
msg_subject="my subject 17"
msg_text="This is my text for subject 17"
msg_reply_subject="Reply to subject 17"
msg_reply_text="This is the text of my reply for subject 17"
/>
<test
msg_subject="my subject 18"
msg_text="This is my text for subject 18"
msg_reply_subject="Reply to subject 18"
msg_reply_text="This is the text of my reply for subject 18"
/>
<test
msg_subject="my subject 19"
msg_text="This is my text for subject 19"
msg_reply_subject="Reply to subject 19"
msg_reply_text="This is the text of my reply for subject 19"
/>
<test
msg_subject="my subject 20"
msg_text="This is my text for subject 20"
msg_reply_subject="Reply to subject 20"
msg_reply_text="This is the text of my reply for subject 20"
/>
<test
msg_subject="my subject 21"
msg_text="This is my text for subject 21"
msg_reply_subject="Reply to subject 21"
msg_reply_text="This is the text of my reply for subject 21"
/>
<test
msg_subject="my subject 22"
msg_text="This is my text for subject 22"
msg_reply_subject="Reply to subject 22"
msg_reply_text="This is the text of my reply for subject 22"
/>
<test
msg_subject="my subject 23"
msg_text="This is my text for subject 23"
msg_reply_subject="Reply to subject 23"
msg_reply_text="This is the text of my reply for subject 23"
/>
<test
msg_subject="my subject 24"
msg_text="This is my text for subject 24"
msg_reply_subject="Reply to subject 24"
msg_reply_text="This is the text of my reply for subject 24"
/>
<test
msg_subject="my subject 25"
msg_text="This is my text for subject 25"
msg_reply_subject="Reply to subject 25"
msg_reply_text="This is the text of my reply for subject 25"
/>
<test
msg_subject="my subject 26"
msg_text="This is my text for subject 26"
msg_reply_subject="Reply to subject 26"
msg_reply_text="This is the text of my reply for subject 26"
/>
<test
msg_subject="my subject 27"
msg_text="This is my text for subject 27"
msg_reply_subject="Reply to subject 27"
msg_reply_text="This is the text of my reply for subject 27"
/>
<test
msg_subject="my subject 28"
msg_text="This is my text for subject 28"
msg_reply_subject="Reply to subject 28"
msg_reply_text="This is the text of my reply for subject 28"
/>
<test
msg_subject="my subject 29"
msg_text="This is my text for subject 29"
msg_reply_subject="Reply to subject 29"
msg_reply_text="This is the text of my reply for subject 29"
/>
<test
msg_subject="my subject 30"
msg_text="This is my text for subject 30"
msg_reply_subject="Reply to subject 30"
msg_reply_text="This is the text of my reply for subject 30"
/>
</testdata>
Here is the Perl code used to generate the xml file.
Code:
#!/usr/bin/perl -w
#
# This program writes an xml test data file for
# Selenium script. It will be used in testing
# the forum section of the website.
#
# edit this line to put in the number of message you want
$total_number_of_messages = 30;
open(OUTFILE, ">$ARGV[0]") || die "open output file failed\n";
$counter=0;
# start writing file
print OUTFILE "<testdata>\n";
while ($counter++ < $total_number_of_messages) {
print OUTFILE "<test\n";
print OUTFILE "msg_subject=\"my subject $counter\"\n";
print OUTFILE "msg_text=\"This is my text for subject $counter\"\n";
print OUTFILE "msg_reply_subject=\"Reply to subject $counter\"\n";
print OUTFILE "msg_reply_text=\"This is the text of my reply for subject $counter\"\n";
print OUTFILE "/>\n";
}
print OUTFILE "</testdata>\n";