Search code examples
c#seleniumselenium-grid

C# selenium target machine actively refused it only when I try to start it programmatically


I need to have my selenium standalone sever start from my code but I keep getting the "No connection could be made because the target machine actively refused" error. The server is started from a bat file and when I try to run the bat file programmatically I get the error. If I just click an the bat file manually it work no problem its only when I try to do it through my code that I get this error.

The sever version is 4.4.0

[BeforeTestRun]
public static void setUp()
{
   StreamWriter sw =new StreamWriter("file.bat");
   sw.WriteLine("java -jar selenium-server-4.4.0.jar standalone");
   sw.Dispose();
   System.Diagnostics.Process.Start("file.bat");
}

Solution

  • Based of what jdweng said I copied the jar into the net48 and wrote this

     ProcessStartInfo processInfo;
     Process process;
    
     processInfo = new ProcessStartInfo("cmd.exe", "/K java -jar selenium-server-4.4.0.jar standalone");
     processInfo.CreateNoWindow = true;
     processInfo.UseShellExecute = true;
    
     process = Process.Start(processInfo);