Hey there,
I want to make a driver for selenium, so I can use tomcat to test my webapplication and I can write my tests with JUnit. I didnt find a lot of information about how doing this, and I cant make it work.
I have installed tomcat 5.5 (configured on port 8080), running on java 1.5 and I have installed the struts-blank application in the tomcat/webapps directory (unzipped). I also have unzipped selenium in this directory (tomcat/webapps/struts-blank/selenium-driver
).
I have chosen for this configuration because most people are familiar with it, and it is easy to set up. I wanted to write a stupid basic test to learn how it works. I have written a JUnit testcase that you can find below.
When I run the test, the following exception is thrown:
com.thoughtworks.selenium.SeleniumException: Moved Temporarily
at com.thoughtworks.selenium.outbedded.CommandBridgeClient.getCommandResponse(CommandBridgeClient.java:92)
at com.thoughtworks.selenium.outbedded.CommandBridgeClient.executeCommandOnServlet(CommandBridgeClient.java:58)
at com.thoughtworks.selenium.outbedded.CommandBridgeClient.doCommand(CommandBridgeClient.java:46)
at com.thoughtworks.selenium.DefaultSelenium.testComplete(DefaultSelenium.java:90)
at be.opensystems.marvin.SeleniumTestCase.tearDown(SeleniumTestCase.java:39)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
It opens up my browser (firefox) but this shows an error he cant connect to my server on port 8080.
Can someone tell me what Im doing wrong, of what else I have to do to make it work? Has someone done this before? It would be great to get some help.
Regards,
Dimitri
import java.io.File;
import junit.framework.TestCase;
import com.thoughtworks.selenium.CommandProcessor;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.launchers.SystemDefaultBrowserLauncher;
import com.thoughtworks.selenium.outbedded.Deployer;
import com.thoughtworks.selenium.outbedded.OutbeddedTomcat;
import com.thoughtworks.selenium.outbedded.ServletContainer;
public class SeleniumTestCase extends TestCase {
Selenium selenium;
ServletContainer container;
protected void setUp() throws Exception {
super.setUp();
Deployer deployer = new IntegrationTestDeployer();
if (container == null) {
container = new OutbeddedTomcat("D:\\tomcat");
container.deployAppAndSelenium(deployer);
CommandProcessor processor = container.start();
selenium = new DefaultSelenium(processor,
new SystemDefaultBrowserLauncher());
}
selenium.start();
}
protected void tearDown() throws Exception {
super.tearDown();
selenium.testComplete();
Thread.sleep(2 * 10000);
selenium.stop();
container.stop();
}
public void testLogin() throws InterruptedException {
selenium.setContext("Test the welcome page");
selenium.open("/Welcome.do");
selenium.verifyTextPresent("Welcome");
selenium.testComplete();
}
public class IntegrationTestDeployer implements Deployer {
public void deploySelenium(ServletContainer container,
String seleniumContext, String driverPath) {
container.installWebApp(new File(calculateCodeRoot(), "struts-blank"), seleniumContext+"/"+driverPath);
}
public void deployAppUnderTest(ServletContainer container,
String appContext) {
container.installWebApp(new File(calculateCodeRoot(), "struts-blank"), appContext);
}
private File calculateCodeRoot() {
File codeRoot = null;
String codeRootProperty = System.getProperty("code_root");
if (codeRootProperty == null) {
codeRootProperty = "D:\\tomcat\\webapps";
}
if (codeRootProperty == null) {
} else if (codeRootProperty == null) {
throw new RuntimeException("'code_root' not specified");
} else {
codeRoot = new File(codeRootProperty);
if (!codeRoot.exists()) {
throw new RuntimeException("'code_root' not a dir");
}
}
return codeRoot;
}
}
}
_______________________________________________ Selenium-devel mailing list Selenium-devel@lists.public.thoughtworks.org http://lists.public.thoughtworks.org/mailman/listinfo/selenium-devel