Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Selenium Test Starting Local Project

I have a solution with 2 projects.

  1. The static web page project
  2. The selenium tests project

Here's my Test File:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SeleniuumTestSuite
{
    [TestClass]
    public class HomePageTest
    {
        private string baseURL = "http://localhost:56403/";
        private static IWebDriver driver;

        [AssemblyInitialize]
        public static void SetUp(TestContext context)
        {
            driver = new ChromeDriver();
        }

        [TestMethod]
        public void RemoteSelenium()
        {
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl(this.baseURL);
        }

        [TestCleanup]
        public void Finally()
        {
            driver.Quit();

        }
    }
}

I need to start the localhost project before the test case runs so that navigating to the localhost doesn't result in a 404. I found this post that seems to answer that question but I have no idea what library the solution is using.

I tried using NuGet to download Microsoft.AspNet.WebApi.WebHost but if I try to do private Server _webServer = new Server(Port, VirtualPath, SourcePath.FullName);, VS doesn't recognize Server and has no idea what library to import. So I'm kind of stuck here.

Any idea how to get this to work?

like image 978
Richard Avatar asked Sep 21 '25 13:09

Richard


1 Answers

In order to solve the problem, it is necessary to run the two projects at the same time, as mrfreester pointed out in comments:

  • The main project in order to be able to run the main application.
  • The test project which will access the running main application to test it.

As mrfreester suggested, you might use two visual studio instances and it will work. Yet, to enhance this solution and manage everything in just one visual studio instance, you can run the main project using Debug.StartWithoutDebugging (default keyboard shortcut is ctrl + f5). This will effectively run the server for the application without starting VS debug mode, allowing you (and your test project) to normally use the application. The application will run even if you close your browser.

Be noted: if you start your application debugging normally, when you stop the execution, the server will stop, and you will have to start again without debugging to be able to pass your tests again.

like image 158
Alvaro Rodriguez Scelza Avatar answered Sep 23 '25 03:09

Alvaro Rodriguez Scelza