2009-03-20 5 views
0

Seleniumテストを実行するようにCCNETサーバを設定しています。私のテストコードでは、実行していない場合、次のようにSelenium RCサーバーを起動します。CCNETビルドサーバでC#から適切に起動していないSerenium Javaプロセス

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から(ユーザーコンテキストで)CCNET.exeを実行すると、java.exeプロセスを実行する代わりに、 "c:\ windows \ java"のエクスプローラウィンドウがポップアップすることがわかります。私のパス設定はうんざりしていると思うけど、どうやってどうやっていいのか分かりません。手伝ってくれますか?

答えて

2

実行しているユーザーコンテキストのコマンドプロンプトでその作業ディレクトリに移動し、コマンドラインを試してみましたか?

パスの設定が台無しにされている場合、あなたは...右マイコンピュータ、プロパティ、高度な、環境変数をクリックして

1

それらを調整することができ、私はこの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); 
    } 

私は、バックグラウンドでサーバを起動するためにこれをやった..しかしないプロキシの下-.-」

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の状況に役立ちますが、今後これを探している人に役立つかもしれませんか?

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 
関連する問題