
org.openqa.selenium.server.htmlrunner.SingleTestSuiteResourceHandler Maven / Gradle / Ivy
Go to download
Selenium automates browsers. That's it! What you do with that power is entirely up to you.
/*
* Created on Feb 26, 2006
*
*/
package org.openqa.selenium.server.htmlrunner;
import org.openqa.jetty.http.HttpException;
import org.openqa.jetty.http.HttpRequest;
import org.openqa.jetty.http.HttpResponse;
import org.openqa.jetty.http.handler.ResourceHandler;
import org.openqa.jetty.util.StringUtil;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.MessageFormat;
/**
* Generates a test suite table designed to run a single Selenium test; to use it, point
* TestRunner.html to /singleTest/http://my.com/single/test.html
*
* @author dfabulich
*
*/
public class SingleTestSuiteResourceHandler extends ResourceHandler {
private static final String HTML =
"\n\n{0} Suite \n\n\n\n\n{0} Suite \n{0} \n\n
\n\n";
/** Handles the HTTP request and generates the suite table */
@Override
public void handle(String pathInContext, String pathParams,
HttpRequest request, HttpResponse response) throws HttpException,
IOException {
if (!pathInContext.startsWith("/singleTest/")) return;
request.setHandled(true);
String url = pathInContext.substring("/singleTest/".length());
OutputStream outStream = response.getOutputStream();
if (url == null) {
outStream.write("No singleTest was specified!".getBytes());
outStream.flush();
return;
}
response.setContentType("text/html");
String suiteName = getSuiteName(url);
Writer writer = new OutputStreamWriter(response.getOutputStream(), StringUtil.__ISO_8859_1);
writer.write(MessageFormat.format(HTML, new Object[] {suiteName, url}));
writer.flush();
}
private String getSuiteName(String path) {
int lastSlash = path.lastIndexOf('/');
String fileName = path.substring(lastSlash + 1);
return fileName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy