簡體   English   中英

啟動Powershell過程后繼續執行代碼

[英]Continue code execution after starting powershell proces

我想在XUnit測試中執行以下操作:

  • 運行PS腳本以在IIS上啟動網站
  • 返回測試類並針對該站點執行一組Selenium測試

我可以通過PS足夠容易地啟動站點,但是此過程受阻-如果我關閉PS窗口,則XUnit測試將繼續,但是IIS顯然已停止,因此測試失敗。

如何啟動IIS進程並繼續測試? 我的PS腳本如下。

$iisExpressExe = '"c:\Program Files\IIS Express\iisexpress.exe"'
$path = "..\..\..\.vs\config\applicationhost.config"
$site = "SITE NAME"
$apppool = "Clr4IntegratedAppPool"
$params = "/config:$path /site:$site"
get-process | where { $_.ProcessName -like "IISExpress" } | stop-process
$command = "$iisExpressExe $params"
cmd /c start cmd /k "$command"

和調用C#:

    string script = File.ReadAllText("Boot.ps1");
    PowerShell shell = PowerShell.Create();

    shell.AddScript(script);
    shell.BeginInvoke();

    Thread.Sleep(2000);

    _driver = new ChromeDriver
    {
        Url = "http://localhost:56565/umbraco"
    };

    // do tests here

    _driver.Dispose();
    shell.Stop();

這樣可以運行,但是不會丟棄外殼...

創建新線程並從該線程運行ps腳本。 然后使用主線程中的Thread.Sleep()方法等待幾秒鍾,以使iis開始站點並開始硒測試。

如果您熟悉async方法,則可以使用其他方法來解決問題BeginInvoke()異步方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM