If you are using the pure html/javascript capabilities of Selenium like I am then you know that you do not get a results report when testing unless you have a postResults servlet setup somewhere to push the results to.
I found a solution by taking apart the fitRunner plug-in to determine what I would need to get one setup.
This is a java solution btw.
http://jira.openqa.org/browse/SEL-102 you can download a zip file here with everything you would need and a bunch of stuff you don't need.
In your webapp just add the servlet mapping you find in the web.xml to your web app.
make sure the package your reference is created as such below
Then add the following jars you will find in the zip to your web app library if you don't already have them.
jstl.jar
and
standard.jar
create two classes
your.package.path.SeleniumResultServlet
paste the following code in it.
package com.your.package.path;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SeleniumResultsServlet extends HttpServlet {
private static TestResults results;
public static TestResults getResults() {
return results;
}
public static void setResults(TestResults testResults) {
results = testResults;
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
if (request.getParameter("clear") != null) {
results = null;
ServletOutputStream out = response.getOutputStream();
out.println("selenium results cleared!");
} else {
forwardToResultsPage(request, response);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String result = request.getParameter("result");
String totalTime = request.getParameter("totalTime");
String numTestPasses = request.getParameter("numTestPasses");
String numTestFailures = request.getParameter("numTestFailures");
String numCommandPasses = request.getParameter("numCommandPasses");
String numCommandFailures = request.getParameter("numCommandFailures");
String numCommandErrors = request.getParameter("numCommandErrors");
String suite = request.getParameter("suite");
int numTotalTests = Integer.parseInt(numTestPasses) + Integer.parseInt(numTestFailures);
List testTables = createTestTables(request, numTotalTests);
results = new TestResults(result, totalTime,
numTestPasses, numTestFailures, numCommandPasses,
numCommandFailures, numCommandErrors, suite, testTables);
forwardToResultsPage(request, response);
}
private List createTestTables(HttpServletRequest request, int numTotalTests) {
List testTables = new LinkedList();
for (int i = 1; i <= numTotalTests; i++) {
String testTable = request.getParameter("testTable." + i);
System.out.println("table " + i);
System.out.println(testTable);
testTables.add(testTable);
}
return testTables;
}
private void forwardToResultsPage(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute("results", results);
request.getRequestDispatcher("/WEB-INF/jsp/viewResults.jsp").forward(request, response);
}
public static class TestResults {
private final String result;
private final String totalTime;
private final String numTestPasses;
private final String numTestFailures;
private final String numCommandPasses;
private final String numCommandFailures;
private final String numCommandErrors;
private final String suite;
private final List testTables;
public TestResults(String postedResult, String postedTotalTime,
String postedNumTestPasses, String postedNumTestFailures,
String postedNumCommandPasses, String postedNumCommandFailures,
String postedNumCommandErrors, String postedSuite, List postedTestTables) {
result = postedResult;
numCommandFailures = postedNumCommandFailures;
numCommandErrors = postedNumCommandErrors;
suite = postedSuite;
totalTime = postedTotalTime;
numTestPasses = postedNumTestPasses;
numTestFailures = postedNumTestFailures;
numCommandPasses = postedNumCommandPasses;
testTables = postedTestTables;
}
public String getDecodedTestSuite() {
return new UrlDecoder().decode(suite);
}
public List getDecodedTestTables() {
return new UrlDecoder().decodeListOfStrings(testTables);
}
public String getResult() {
return result;
}
public String getNumCommandErrors() {
return numCommandErrors;
}
public String getNumCommandFailures() {
return numCommandFailures;
}
public String getNumCommandPasses() {
return numCommandPasses;
}
public String getNumTestFailures() {
return numTestFailures;
}
public String getNumTestPasses() {
return numTestPasses;
}
public String getSuite() {
return suite;
}
public Collection getTestTables() {
return testTables;
}
public String getTotalTime() {
return totalTime;
}
public int getNumTotalTests() {
return Integer.parseInt(numTestPasses) + Integer.parseInt(numTestFailures);
}
}
}
then go ahead and create a UrlDecoder class in the same package
package your.package.path;
import java.io.UnsupportedEncodingException;import java.net.URLDecoder;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* @author Darren Cotterill
* @author Ajit George
* @version $Revision: $
*/
public class UrlDecoder {
public String decode(String string) {
try {
return URLDecoder.decode(string, System.getProperty("file.encoding"));
} catch (UnsupportedEncodingException e) {
return string;
}
}
public List decodeListOfStrings(List list) {
List decodedList = new LinkedList();
for (Iterator i = list.iterator(); i.hasNext();) {
decodedList.add(decode((String) i.next()));
}
return decodedList;
}
}
In your web-inf create a folder called jsp
copy the viewResults.jsp into it that is in the zip file.
copy the c.tld to the /web-inf
restart your server
if you get some goofy errors when trying to load the postResults servlet from selenium try changing the taglib reference int the viewResults.jsp to use the sun url instead due to different version dependencies it may not work. servlet 1.0 vs. 2.0 stuff.
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Then when you run the test runner and choose automatic option in your selenium screen you will have a postResults servlet that you can use and customize at will.
Hope this helps others. Having a way to format test results is a great help when trying to create documentation and the stuff that comes out of the zip with regular selenium doesn't give you this basic functionality and you have to bake it up yourself.