views:

744

answers:

4

Hi, I'm setting up CCNET server to run Selenium tests. In my test code I use the following to start the Selenium RC server if its not running:

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();

This works great on my development machine. However, when I run it from CCNET.exe (under a user context), I can see that instead of executing the java.exe process, an explorer window pops up for "c:\windows\java". I think my path settings are messed up but I'm not sure how. Can you help?

+1  A: 

Have you tried going to that working directory in a Command prompt under the user context you are running it under and trying the command line?

If the path settings are messed up, you can adjust them by right clicking the My computer, properties, Advanced, Environment Variables...

Jeff Martin
+1  A: 

i use this one

public class Navegador : DefaultSelenium { private static 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);
    }

works good.. but not under a proxy -.-'

A: 

I did this to start the server in the background:

// 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();

then just did

seleniumServer.Kill()

to stop it after all went well.

Not sure this will help the CCNET situation but may help people looking for this in future?

Matt Clarkson
A: 

SeleniumProcess Class

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

region Setup/Teardown

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

    [TearDown]
    public void TeardownTest()
    {
        try
        {
            _selenium.Stop();
        }

// ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { // Ignore errors if unable to close the browser } SeleniumProcess.Stop(); Assert.AreEqual("", _verificationErrors.ToString()); }

    #endregion
smnbss