Stopping ASP WebDev and Selenium servers from command line

橙三吉。 提交于 2019-12-06 16:13:43

问题


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?


回答1:


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"




回答2:


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;
}



回答3:


We usually leave the Selenium server running all the time on our build servers, it's more practical that way.




回答4:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!