2017-05-23 74 views
4

我目前正在尝试在Core Web应用程序上设置一些UI测试,但是我无法启动Web应用程序。使用命令行直接从Web应用程序目录中运行“dotnet run”。当我在执行我的测试之前尝试使用Process来运行它时,问题就出现了。以编程方式启动用于Selenium测试的.NET Core Web应用程序

var process = new Process 
    { 
     StartInfo = 
     { 
      FileName = "dotnet", 
      Arguments = "run", 
      WorkingDirectory = applicationPath 
     } 
    }; 
    process.Start(); 

有没有人遇到类似的问题之前和/或设法解决它?我可能会滥用Process

回答

3

打开,添加UseShellExecute我的StartInfo并将其设置为false使工作:

var process = new Process 
{ 
    StartInfo = 
    { 
     FileName = "dotnet", 
     Arguments = "run", 
     UseShellExecute = false, 
     WorkingDirectory = applicationPath 
    } 
}; 
process.Start(); 

UseShellExecute默认值是真实的,但它是类似于运行cmd dotnet run而不是dotnet run这是我所需要的。

+0

启动后,您是否能够阻止它? – Zack

+0

nm。如果(_webprocess!= null && _webprocess.HasExited == false)使用了以下关闭函数: {_lbprocess.CloseMainWindow(); _webprocess.Close(); } 调用Kill()不起作用。 – Zack

+0

在我的情况下,程序结束时它会停止 – IamNguele

0

试试这个

ProcessStartInfo Startinfo = new ProcessStartInfo(); 
Startinfo.FileName = "D:\\TFS\\QA\\SH_LoadTest\\SH_LoadTest\\bin\\Debug\\SH_LoadTest.exe"; 
StartInfo.Arguments="Your Arguements"; 
       Process pro = Process.Start(Startinfo); 
+0

您实际上可以使用Autoit启动.net核心应用程序 – Neha

+0

它给了我和以前相同的结果:/ – IamNguele

相关问题