以编程方式启动 .NET Core Web 应用程序以进行 Selenium 测试 [英] Programmatically start a .NET Core web app for Selenium testing
问题描述
我目前正在尝试在 Core Web 应用程序上设置一些 UI 测试,但是我无法启动 Web 应用程序.将命令行直接与 Web 应用程序目录中的dotnet run"一起使用是可行的.当我在执行测试之前尝试使用 Process 运行它时,问题就出现了.
I am currently trying to setup some UI tests on a Core web app, however I am not able to get the web app started. Using the command line directly with "dotnet run" from the web app directory works. The problem comes when I try to use Process to run it before executing my tests nothing happens.
var process = new Process
{
StartInfo =
{
FileName = "dotnet",
Arguments = "run",
WorkingDirectory = applicationPath
}
};
process.Start();
有没有人遇到过类似的问题和/或设法解决了它?我可能滥用了 Process
.
Has anyone been confronted to a similar issue before and/or managed to solve it? I may be misusing Process
.
推荐答案
Turns 将 UseShellExecute
添加到我的 StartInfo 并将其设置为 false
使其工作:
Turns that adding UseShellExecute
to my StartInfo and setting it to false
made it work:
var process = new Process
{
StartInfo =
{
FileName = "dotnet",
Arguments = "run",
UseShellExecute = false,
WorkingDirectory = applicationPath
}
};
process.Start();
UseShellExecute
的默认值为 true,但它类似于运行 cmd dotnet run
而不是我需要的 dotnet run
.
The default for UseShellExecute
is true but it would be similar to running cmd dotnet run
instead of dotnet run
which is what I needed.
这篇关于以编程方式启动 .NET Core Web 应用程序以进行 Selenium 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!