以编程方式启动.NET Core Web应用进行硒测试 [英] Programmatically start a .NET Core web app for Selenium testing

查看:73
本文介绍了以编程方式启动.NET Core Web应用进行硒测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在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();

有人曾经遇到过类似的问题和/或设法解决过吗?我可能会误用进程

Has anyone been confronted to a similar issue before and/or managed to solve it? I may be misusing Process.

推荐答案

转为添加 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运行,而不是运行 dotnet运行,这正是我所需要的。

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应用进行硒测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆