Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically start a .NET Core web app for Selenium testing

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.

like image 586
CodingNagger Avatar asked May 23 '17 12:05

CodingNagger


People also ask

Does Selenium work with .NET core?

Using . NET Core you can write cross-platform UI tests using C# and Selenium. You can swap out the ChromeDriver with any other supported browser to verify cross-browser compatibility. You can use this GitHub repository as a reference in case you run into any roadblocks.

How do I run a .NET core application?

You can run it, from the console, by calling dotnet run from the folder that contains the project. json file. On your local machine, you can prepare the application for deployment by running "dotnet publish". This builds the application artifacts, does any minification and so forth.

Can we use Selenium for .NET application?

We can use Selenium for . NET applications. We should have Visual Studio 2019 installed in the system along with Selenium webdriver and any browser like Firefox, Chrome, and so on. Then we must utilize the NUnit framework.


1 Answers

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();

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.

like image 82
CodingNagger Avatar answered Dec 09 '22 05:12

CodingNagger