2017-05-23 69 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

相關問題