简体   繁体   中英

Continue code execution after starting powershell proces

I want to do the following within an XUnit test:

  • run a PS script to start a site on IIS
  • return to the test class and execute a set of Selenium tests against the site

I can start the site easily enough via PS, but the process is blocking - if I close the PS window, the XUnit test continues, but IIS has obviously stopped so the test fails.

How do I start the IIS process and have the test continue? My PS script is below.

$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"

And the calling 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();

This runs, but doesn't dispose the shell...

Create new thread and run ps script from that thread. Then wait several seconds with Thread.Sleep() method in main thread to let iis start site and start selenium tests.

Alternative way to solve problem BeginInvoke() async method, if you are familiar with async methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM