从命令行停止 ASP WebDev 和 Selenium 服务器

发布于 2024-07-24 07:56:22 字数 571 浏览 6 评论 0原文

我第一次将 Selenium 测试引入我的构建中。 我认为要在 NAnt 中执行此操作,我必须首先启动 WebDev 服务器:

<exec program="path/to/WebDev.WebServer.exe"
   commandline="/port:51150 /path:path/to/website"
   failonerror="true"
   resultproperty="selenium.webdev.server.running"
   spawn="true">
</exec>

然后启动 Selenium 服务器:

<exec program="path/to/java.exe"
   commandline="-jar path/to/selenium-server.jar"
   failonerror="false"
   spawn="true">
</exec>

然后运行我的测试。 这有效。 我不明白的是,当我的测试完成后,如何杀死 WebDev 和 Selenium 服务器?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你丑哭了我 2024-07-31 07:56:22

这是我在本地执行的操作,但也应该通过简单的 http get 请求远程工作:

http://localhost:4444/selenium-server/driver/?cmd=shutDown

或对于 Selenium 1.0.1 后版本:

将“shutDown”替换为“shutDownSeleniumServer”

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"

失与倦" 2024-07-31 07:56:22

James,我通过应用测试程序集初始化和清理机制成功解决了 Selenium 启动/停止问题(请参阅我的

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

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;
}
这样的小城市 2024-07-31 07:56:22

我们通常让 Selenium 服务器在我们的构建服务器上一直运行,这样更实用。

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

忆梦 2024-07-31 07:56:22

如果做不到这一点,总是有值得信赖的旧pskill。 这是一个大锤子的方法,但它可以有效地杀死 webdevwebserver :-)

我对 selenium 知之甚少,所以如果 pskill 无法阻止它,请提前道歉

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文