[英]Continue code execution after starting powershell proces
我想在XUnit测试中执行以下操作:
我可以通过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.