Author: ajaquith
Date: Wed Mar 19 19:11:10 2008
New Revision: 639114
URL: http://svn.apache.org/viewvc?rev=639114&view=rev
Log:
Fixed failing Selenium web unit tests so that they run correctly, with two
exceptions. See tests/etc/selenium/readme.txt; this file includes a few notes
on how to write Selenium tests so that they will run automatically via the Ant
"webtests" target.
Added:
incubator/jspwiki/trunk/tests/etc/selenium/tests/JSPWikiTestNoDeletePage.html
Modified:
incubator/jspwiki/trunk/tests/etc/selenium/readme.txt
incubator/jspwiki/trunk/tests/etc/webtests.xml
Modified: incubator/jspwiki/trunk/tests/etc/selenium/readme.txt
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/etc/selenium/readme.txt?rev=639114&r1=639113&r2=639114&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/etc/selenium/readme.txt (original)
+++ incubator/jspwiki/trunk/tests/etc/selenium/readme.txt Wed Mar 19 19:11:10
2008
@@ -43,19 +43,49 @@
Add the new test file (in this case, JSPWikiTestAnonymousView.html) to the test
directory (tests/etc/selenium/tests).
-However, simply adding the file to the suited is NOT enough. To make it run
-for all of the five sample webapp contexts we test, you MUST add a short
-preamble to each test file so that the Selenium-RC test runner starts at
-the correct URL. Here is that preamble:
+However, simply adding the file to the suite is NOT enough. To make it run
+for all of the five sample webapp contexts we test (test-custom,
test-container, etc),
+you MUST add a short preamble to each test file so that the Selenium-RC
+test runner starts at the correct URL. Here is that preamble:
- <tr><td>store</td><td>/@selenium.context@/</td> <td>baseUrl</td></tr>
+ <tr><td>store</td> <td>/@selenium.context@</td> <td>baseUrl</td></tr>
<tr><td>open</td> <td>$${baseUrl}/Wiki.jsp?page=Main</td>
<td> </td></tr>
The first line is important: at build time (that is, when the Ant webtests
target executes), the @selenium.context@ variable will be replaced with the
-correct test context. You MUST ensure that the first Selenese 'open' command
-(such as the one shown in the second line, above) opens to the correct context.
-Setting, then using, the ${baseUrl} property is the recommended way.
+correct test context (e.g., test-custom). You MUST ensure that the first
+Selenese 'open' command (such as the one shown in the second line, above)
+opens to the correct context. Setting, then using, the ${baseUrl} property
+is the recommended way.
+
+To put it simply: just make sure you add somethign similar to the two lines
shown above
+to the top of your test, and you should be good to go.
+
+You need to keep in mind two other issues:
+1) Creating unique resources for each test
+2) Restoring the correct session state at the end of your test
+
+Web unit tests should NOT make any assumptions about what wiki pages, users
and groups
+are present in the test context, other than these:
+Users: janne, admin, user
+Groups: Admin
+Pages: Main
+
+If you need to run tests that create, delete or rename users, groups or pages,
+you should always write tests that use unique names for those resources.
+The best way to do this is to store a unique value in a variable, then
+use the value of that variable in your script. Generating unique values is
easy:
+
+ <tr><td>store</td> <td>javascript{'Test-group-'+new
Date().getTime()}</td> <td>group</td></tr>
+
+(from JSPWikiTestCreateGroupWikiName.html)
+
+Second, you should make sure that a particular unit test doesn't hose the next
one, and
+restore the user session to an anonymous state. Make sure your unit test
includes
+the following Selenese at the end of the test script:
+
+ <!-- Log out -->
+ <tr><td>clickAndWait</td> <td>link=Log out</td> <td> </td></tr>
BUILD NOTES
Added:
incubator/jspwiki/trunk/tests/etc/selenium/tests/JSPWikiTestNoDeletePage.html
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/etc/selenium/tests/JSPWikiTestNoDeletePage.html?rev=639114&view=auto
==============================================================================
---
incubator/jspwiki/trunk/tests/etc/selenium/tests/JSPWikiTestNoDeletePage.html
(added)
+++
incubator/jspwiki/trunk/tests/etc/selenium/tests/JSPWikiTestNoDeletePage.html
Wed Mar 19 19:11:10 2008
@@ -0,0 +1,54 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
+ <title>JSPWiki Test Delete Page</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+ <tbody>
+ <tr><td rowspan="1" colspan="3">JSPWiki Test Delete Page<br></td></tr>
+
+ <tr><td>store</td> <td>/@selenium.context@</td>
<td>baseUrl</td></tr>
+ <tr><td>store</td> <td>javascript{'Delete-page '+new
Date().getTime()}</td> <td>page</td></tr>
+ <tr><td>store</td> <td>janne</td>
<td>TestUsername</td></tr>
+ <tr><td>store</td> <td>[EMAIL PROTECTED]</td>
<td>TestPassword</td></tr>
+
+ <tr><td>store</td> <td>${baseUrl}/Wiki.jsp?page=${page}</td>
<td>url</td></tr>
+ <tr><td>store</td> <td>${baseUrl}/Edit.jsp?page=${page}</td>
<td>editurl</td></tr>
+ <tr><td>store</td>
<td>${baseUrl}/PageInfo.jsp?page=${page}</td><td>infourl</td></tr>
+ <tr><td>store</td> <td>${baseUrl}/Login.jsp</td>
<td>loginurl</td></tr>
+ <tr><td>store</td> <td>This page was created by the web unit tests.</td>
<td>PageContent</td></tr>
+
+ <!-- Login --!>
+ <tr><td>open</td> <td>${loginurl}</td> <td> </td></tr>
+ <tr><td>type</td> <td>j_username</td> <td>${TestUsername}</td></tr>
+ <tr><td>type</td> <td>j_password</td> <td>${TestPassword}</td></tr>
+ <tr><td>clickAndWait</td> <td>submitlogin</td> <td> </td></tr>
+
+ <!-- Create page --!>
+ <tr><td>open</td> <td>${editurl}</td>
<td> </td></tr>
+ <tr><td>verifyTitle</td> <td>JSPWiki: Edit: ${page}</td>
<td> </td></tr>
+ <tr><td>verifyElementPresent</td> <td>ok</td> <td></td></tr>
+ <tr><td>verifyElementPresent</td> <td>id=editorarea</td> <td></td></tr>
+
+ <tr><td>type</td> <td>id=editorarea</td>
<td>${PageContent}</td></tr>
+ <tr><td>clickAndWait</td> <td>ok</td> <td> </td></tr>
+
+ <tr><td>open</td> <td>${url}</td>
<td> </td></tr>
+ <tr><td>verifyTitle</td> <td>JSPWiki: ${page}</td>
<td> </td></tr>
+ <tr><td>verifyTextPresent</td> <td>${PageContent}</td>
<td> </td></tr>
+
+ <!-- Delete Page --!>
+ <tr><td>open</td> <td>${infourl}</td>
<td> </td></tr>
+ <tr><td>verifyTitle</td> <td>JSPWiki: ${page}</td>
<td> </td></tr>
+ <tr><td>assertElementNotPresent</td> <td>id=delete-all</td>
<td> </td></tr>
+
+ <!-- Log out --!>
+ <tr><td>clickAndWait</td> <td>link=Log out</td> <td> </td></tr>
+
+ </tbody>
+</table>
+
+</body>
+</html>
Modified: incubator/jspwiki/trunk/tests/etc/webtests.xml
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/etc/webtests.xml?rev=639114&r1=639113&r2=639114&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/etc/webtests.xml (original)
+++ incubator/jspwiki/trunk/tests/etc/webtests.xml Wed Mar 19 19:11:10 2008
@@ -196,9 +196,11 @@
value="${basedir}/${tests.build}/@{context}/jspwiki.log" />
</propertyfile>
- <!-- Copy our sample user database -->
+ <!-- Copy our sample user and group databases -->
<copy file="tests/etc/userdatabase.xml"
toFile="${tests.build}/@{context}/userdatabase.xml" />
+ <copy file="tests/etc/groupdatabase.xml"
+ toFile="${tests.build}/@{context}/groupdatabase.xml" />
<!-- Build the war -->
<war warfile="${tests.build}/@{context}/@{context}.war"
@@ -213,10 +215,9 @@
<include name="jspwiki.jaas" />
<include name="jspwiki.policy" />
<include name="*.tld" />
- <include name="groupdatabase.xml" />
</webinf>
<webinf dir="${tests.build}/@{context}"
- includes="jspwiki.properties userdatabase.xml" />
+ includes="jspwiki.properties userdatabase.xml groupdatabase.xml" />
<classes dir="etc" includes="oscache.properties" />
<metainf dir="${tests.build}/@{context}" includes="context.xml" />
</war>