0

我正在设置 CCNET 服务器来运行 Selenium 测试。在我的测试代码中,如果 Selenium RC 服务器未运行,我将使用以下代码启动它:

var proc = new Process();
proc.StartInfo.WorkingDirectory = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, @"..\..\..\..\..\lib\SeleniumRC\selenium-server-1.0-beta-2");
proc.StartInfo.FileName = "java"; //have also tried with "java.exe"
proc.StartInfo.Arguments = @"-jar selenium-server.jar -multiWindow -trustAllSSLCertificates -firefoxProfileTemplate ""..\Firefox Profiles\Relaxed Security""";
proc.StartInfo.UseShellExecute = true;
proc.Start();

这在我的开发机器上效果很好。但是,当我从 CCNET.exe(在用户上下文中)运行它时,我可以看到不是执行 java.exe 进程,而是为“c:\windows\java”弹出一个资源管理器窗口。我认为我的路径设置搞砸了,但我不确定如何。你能帮我吗?

4

4 回答 4

2

您是否尝试过在运行它的用户上下文下的命令提示符下进入该工作目录并尝试命令行?

如果路径设置混乱,您可以通过右键单击我的电脑、属性、高级、环境变量...来调整它们。

于 2009-03-20T16:19:29.577 回答
2

我这样做是为了在后台启动服务器:

// Start the java server
Process seleniumServer;
String javaFileLocation = @"C:\Program Files\Java\jre6\bin\java.exe";
String jarFileLocation = @"C:\SeleniumRC\selenium-remote-control-1.0.1\selenium-server-1.0.1\selenium-server.jar";
seleniumServer = new Process();
seleniumServer.StartInfo.FileName = javaFileLocation;
seleniumServer.StartInfo.Arguments = "-jar " + jarFileLocation;
seleniumServer.StartInfo.WorkingDirectory = jarFileLocation.Substring(0, jarFileLocation.LastIndexOf("\\"));
seleniumServer.StartInfo.UseShellExecute = true;
seleniumServer.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
seleniumServer.Start();

然后就做了

seleniumServer.Kill()

一切顺利后停止它。

不确定这将有助于 CCNET 的情况,但可能会帮助人们在未来寻找这个?

于 2010-02-16T13:49:26.640 回答
1

我用这个

公共类 Navegador : DefaultSelenium { 私有静态 int contadorPorta = 4444;

    private int porta;

    private delegate string OperacaoSelenium();

    // Variável para a URL Base
    private string urlBase;
    public string UrlBase
    {
        get { return urlBase; }
    }

    public Navegador(string urlBase)
        : base("localhost", contadorPorta, "*firefox", urlBase) // ou *firefox ou *chrome *safari, *opera , *iexplore etc.
    {
        this.urlBase = urlBase;

        porta = Navegador.contadorPorta;
        // Deve sempre abrir o Selenium RC-Server antes (instância única - Singleton)
        this.IniciarSeleniumRCServer();
        Navegador.contadorPorta++;

        this.Start();
        this.Open("/");
    }

    /// <summary>
    /// Inicia o Selenium RC-Server, que é o arquivo JAR que vem no pacote do Selenium RC
    /// </summary>
    private void IniciarSeleniumRCServer()
    {
        string seleniumParameters = "..\\..\\..\\ExternalLibraries\\selenium-remote-control-1.0-beta-1\\selenium-server-1.0-beta-1\\selenium-server.jar -Dhttp.proxyHost=10.100.100.24 -port " + porta + "";
        procSeleniumServer = System.Diagnostics.Process.Start("java.exe", " -jar " + seleniumParameters);
        System.Threading.Thread.Sleep(1000);
    }

效果很好..但不在代理下-.-'

于 2009-06-02T13:36:17.613 回答
1

SeleniumProcess 类

public class SeleniumProcess
    {
        private static Process _seleniumServer;

        public static void Start()
        {
            _seleniumServer = new Process
                                  {
                                      StartInfo =
                                          {
                                              FileName = "java",
                                              Arguments =
                                                  "-jar ../../../References/" +
                                                  "selenium-remote-control-1.0.3/" +
                                                  "selenium-server-1.0.3/" + "selenium-server.jar -port 4444"
                                          }
                                  };
            _seleniumServer.Start();
        }

        public static void Stop()
        {
            _seleniumServer.Kill();
        }
    }

区域设置/拆卸

    [SetUp]
    public void SetupTest()
    {
        SeleniumProcess.Start();
    }

    [TearDown]
    public void TeardownTest()
    {
        try
        {
            _selenium.Stop();
        }
        catch (Exception)
        {
            // Ignore errors if unable to close the browser
        }
        SeleniumProcess.Stop();
        Assert.AreEqual("", _verificationErrors.ToString());
    }

    #endregion
于 2010-03-05T13:19:54.810 回答