I am introducing Selenium tests into my build for the first time. I figured that to do this in NAnt, I would have to start the WebDev server first:
<exec program="path/to/WebDev.WebServer.exe"
commandline="/port:51150 /path:path/to/website"
failonerror="true"
resultproperty="selenium.webdev.server.running"
spawn="true">
</exec>
Then start the Selenium server:
<exec program="path/to/java.exe"
commandline="-jar path/to/selenium-server.jar"
failonerror="false"
spawn="true">
</exec>
Then run my tests. This works. What i can't figure out is how do I kill the WebDev and Selenium servers when my tests have finished?
Here is what i do locally, but should work remotely too with a simple http get request:
http://localhost:4444/selenium-server/driver/?cmd=shutDown
or for post 1.0.1 versions of Selenium:
replace "shutDown" with "shutDownSeleniumServer"
James, I managed to solve Selenium starting/stopping problem by applying the test assembly initialization and cleanup mechanism (see the rest of the discussion on my blog):
[AssemblyFixture]
public class SeleniumTestingSetup : IDisposable
{
[FixtureSetUp]
public void Setup()
{
seleniumServerProcess = new Process();
seleniumServerProcess.StartInfo.FileName = "java";
seleniumServerProcess.StartInfo.Arguments =
"-jar ../../../lib/Selenium/selenium-server/selenium-server.jar -port 6371";
seleniumServerProcess.Start();
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes the object.
/// </summary>
/// <param name="disposing">If <code>false</code>, cleans up native resources.
/// If <code>true</code> cleans up both managed and native resources</param>
protected virtual void Dispose(bool disposing)
{
if (false == disposed)
{
if (disposing)
DisposeOfSeleniumServer();
disposed = true;
}
}
private void DisposeOfSeleniumServer()
{
if (seleniumServerProcess != null)
{
try
{
seleniumServerProcess.Kill();
bool result = seleniumServerProcess.WaitForExit(10000);
}
finally
{
seleniumServerProcess.Dispose();
seleniumServerProcess = null;
}
}
}
private bool disposed;
private Process seleniumServerProcess;
}
We usually leave the Selenium server running all the time on our build servers, it's more practical that way.
Failing that, there's always the trusty old pskill. It's a big hammer approach, but it works a treat to kill off webdevwebserver :-)
I know very very little about selenium, so apologies in advance if pskill is no good for stopping it
来源:https://stackoverflow.com/questions/969495/stopping-asp-webdev-and-selenium-servers-from-command-line