【问题标题】:Test execution not running with NUnit, Selenium and C#未使用 NUnit、Selenium 和 C# 运行测试执行
【发布时间】:2018-05-06 17:44:30
【问题描述】:

我正在尝试在 C# 中使用 Selenium 学习和设置 NUnit。

我的框架中包含以下内容

  1. Visual Studio 社区 2017
  2. NUnit 3 测试适配器,版本 3.9.0.0
  3. NUnit v3.9.0
  4. Selenium Webdriver 3.7.0
  5. Selenium Webdriver IEDriver v3.7.0

当我运行我的代码时,什么也没有发生。测试资源管理器没有显示任何执行。我无法解决这个问题。

查看此视频以了解问题:https://screencast-o-matic.com/watch/cbX3rQ2t6Z

下面是代码

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestTut
{

    class Program
    {
        //Declaring Internet Explorer driver
        IWebDriver driver = new InternetExplorerDriver();

        static void Main(string[] args)
        {
        }

        [SetUp]
        public void Initialize()
        {
            // Navigate to test URL
            driver.Navigate().GoToUrl("http://www.google.com/");
        }

        [Test]
        public void ExecuteTest()
        {
            // Enter in Google search
            IWebElement element = driver.FindElement(By.Name("q"));

            // Perform action
            element.SendKeys("This is a test");
            Console.WriteLine("Type the text in search box");
        }

        [TearDown]
        public void CloseDriver()
        {
            // Close the browser
            driver.Close();
        }
    }
}

【问题讨论】:

    标签: c# selenium automation nunit nunit-3.0


    【解决方案1】:

    嗯...也许我在这方面错了,但您不应该从测试资源管理器或其他任何名称开始将其作为单元测试运行吗?

    问题可能是您将它作为控制台应用程序运行,并且由于您的 Main 方法是空的,它当然不会做任何事情。

    【讨论】:

    • 我正在关注网络上的教程。 executeautomation.com/blog/using-nunit-with-selenium-c这家伙在视频中展示了控制台应用程序。
    • @Aruba:是的,但是在您刚刚链接的视频中,您可以看到那个人从测试资源管理器窗口中使用“运行选定的测试”命令运行测试用例。在您的视频中,您没有这样做。再看一遍教程视频,而不是看你的视频,看看他开始执行单元测试的方式(从测试资源管理器中使用“运行选定的测试”)和你的执行方式有什么不同。
    • 感谢您指出我的错误。我以错误的方式运行测试。
    猜你喜欢
    • 1970-01-01
    • 2011-12-18
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多