启动PowerShell进程

时间:2018-05-04 04:20:21

标签: c# powershell selenium-webdriver xunit

我想在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();

这样运行,但是没有配置shell ...

1 个答案:

答案 0 :(得分:1)

创建新线程并从该线程运行ps脚本。然后在主线程中使用Thread.Sleep()方法等待几秒钟,让iis启动站点并启动selenium测试。

解决问题BeginInvoke() async方法的其他方法,如果您熟悉异步方法。

相关问题