Visual Studio Selenium Test启动本地项目 [英] Visual Studio Selenium Test Starting Local Project

查看:132
本文介绍了Visual Studio Selenium Test启动本地项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个项目的解决方案.

I have a solution with 2 projects.

  1. 静态网页项目
  2. 硒测试项目

这是我的测试文件:

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

        }
    }
}

我需要在测试用例运行之前启动localhost项目,以便导航到localhost不会导致404.我发现

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.

我尝试使用NuGet下载Microsoft.AspNet.WebApi.WebHost,但是如果尝试执行private Server _webServer = new Server(Port, VirtualPath, SourcePath.FullName);,则VS无法识别Server,并且不知道要导入哪个库.所以我有点卡在这里.

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?

推荐答案

为解决该问题,有必要同时运行两个项目,正如mrfreester在评论中指出的那样:

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

  • 主项目,以便能够运行主应用程序.
  • 将访问正在运行的主应用程序以对其进行测试的测试项目.

按照mrfreester的建议,您可以使用两个Visual Studio实例,它将起作用.但是,要增强此解决方案并仅在一个Visual Studio实例中管理所有内容,您可以使用Debug.StartWithoutDebugging(默认键盘快捷键为ctrl + f5)运行主项目.这将为应用程序有效地运行服务器,而无需启动VS调试模式,从而允许您(和您的测试项目)正常使用该应用程序.即使关闭浏览器,该应用程序也将运行.

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.

这篇关于Visual Studio Selenium Test启动本地项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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