【问题标题】:The type or namespace name 'IWebDriver' could not be found error while executing Nunit test through Selenium on Visual Studio 2017在 Visual Studio 2017 上通过 Selenium 执行 Nunit 测试时找不到类型或命名空间名称“IWebDriver”错误
【发布时间】:2018-07-27 08:01:42
【问题描述】:

我正在尝试在带有 C# 的 mac 上使用 selenium 创建一些测试用例。我使用的 IDE 是 Visual Studio 2017。我安装了以下软件包,selenium web 驱动程序,selenium 支持,selenium firefox web 驱动程序。我的问题是如何成功使用 selenium 为使用 C# 的网站创建测试用例。每当我尝试运行测试用例时,都会弹出以下错误;

/Users/andrew/Projects/test/test/Test.cs(23,23): Error CS0234: The type or namespace name 'Firefox' does not exist in the namespace 'OpenQA.Selenium' (are you missing an assembly reference?) (CS0234) (test)      

/Users/andrew/Projects/test/test/Test.cs(9,9): Error CS0246: The type or namespace name 'IWebDriver' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (test)

代码试用:

using NUnit.Framework;
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace test
{
    [TestFixture()]
    public class Test
    {

        IWebDriver driverOne = new FirefoxDriver();

        [Test()]
        public void TestCase()
        {
            driverOne.Navigate().GoToUrl("http://google.com/");
        }
    }
}

【问题讨论】:

    标签: c# visual-studio unit-testing selenium selenium-webdriver


    【解决方案1】:

    如果您通过 Visual Studio 2017 等框架使用 Selenium-WebDriver,请参阅之前的几篇文章strong>、nunittestadapterNUnit.FrameworkVS 2017 使用 NuGet 管理器 有时安装/配置可能会出现问题。

    示例:SelectElement 类

    根据文档,SelectElement 类在 OpenQA.Selenium.Support.UI Namespace 中几乎可用,它提供了一种方便的方法来操作 HTML 选择元素中的选项选择。


    继承层次结构

    System.Object
        OpenQA.Selenium.Support.UI.SelectElement
    

    命名空间:OpenQA.Selenium.Support.UI


    程序集:WebDriver.Support(在 WebDriver.Support.dll 中)版本:3.1.0


    语法:公共类 SelectElement : IWrapsElement


    快照:

    解决方案

    卸载并重新安装 Selenium.Webdriver 和 Selenium.Support 包,肯定会解决问题。

    参考

    您可以在

    中找到相关讨论

    【讨论】:

    • 构建成功。但现在我得到了这个错误。 TestFixtureSetUp 在测试中失败
    • 如何使用 selenium 打开浏览器?
    • 卸载 nuget 包后我还必须重新启动 VS 并重新安装它们
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多