【问题标题】:Running tests with NUnit and Selenium 2.11.0 exception使用 NUnit 和 Selenium 2.11.0 异常运行测试
【发布时间】:2011-12-18 08:47:30
【问题描述】:

我正在尝试使用 NUnit 和 Selenium 2 在 C# 中运行一些测试。我遵循的步骤:

  • 我安装了 NUnit。我想我在这里不能有任何错误。
  • 我下载了 Selenium 2:我从 this 链接获得了客户端,从 this 获得了 C# 服务器。
  • 执行以下命令启动 selenium 服务器:(我现在怀疑这一步是否必要)

    java -jar C:\selenium-remote-control-2.11.0\selenium-server-2.11.0\selenium-2.11.0\selenium-server-standalone-2.11.0.jar
    

当 - 使用 NUnit- 我运行一个使用 FirefoxDriver 实例的简单谷歌测试时,出现此错误:

SeleniumTests.Test (TestFixtureSetUp):
SetUp : System.ComponentModel.Win32Exception : The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at OpenQA.Selenium.Firefox.Internal.Executable.LocateFirefoxBinaryFromPlatform() in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Firefox\Internal\Executable.cs:line 197
at OpenQA.Selenium.Firefox.Internal.Executable..ctor(String userSpecifiedBinaryPath) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Firefox\Internal\Executable.cs:line 36
at OpenQA.Selenium.Firefox.FirefoxBinary..ctor(String pathToFirefoxBinary) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Firefox\FirefoxBinary.cs:line 66
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor() in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Firefox\FirefoxDriver.cs:line 114
at SeleniumTests.Test.FixtureSetup() in c:\users\julio\documents\visual studio 2010\Projects\UnitTestingElSuperDT\UnitTestingElSuperDT\Test.cs:line 18

这快把我逼疯了!!有什么帮助吗?

【问题讨论】:

    标签: unit-testing selenium nunit


    【解决方案1】:

    首先,要使用 C#.NET 使用 selenium 运行测试,您不必使用 RC(远程控制)服务器。你需要做的就是

    public IWebDriver driver = new FireFoxDriver();
    
    public void test()
    {
      driver.Navigate().GoToUrl("google.com");
    }
    

    关于你的错误。我遇到了类似的问题,我想说它与 RC Server 在您的本地计算机上运行的端口有关。

    ------- 编辑 -------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Firefox; //needed to open the firefox driver
    
    namespace SeleniumBenchmark
    {
        public class Program
        {
            public static IWebDriver browserDriver = new FirefoxDriver();  //instantiates the webdriver (opens the browser)
    
            static void Main(string[] args)
            {
                browserDriver.Navigate().GoToUrl("http://yahoo.com"); //navigates to the page
            }
        }
    }
    

    【讨论】:

    • 事实上我不记得我做了什么,因为我停止使用 RC。因为你只需要 RC 来运行 JavaScript,我找到了一种不用 JavaScript 就可以做我想做的事情的方法。
    • 你介意我问一下你找到了什么方法吗?因为我真的没办法了!
    • @Soph 我正在使用 VS2010 IDE。如果您有 VS,请转到包管理器控制台并输入 Install-Package Selenium.Support,这将安装您需要的所有内容。如果没有,那么您所要做的就是使用您的 IDE 安装您的引用。您需要 Selenium、Selenium Support、Castle.Core、Newtonsoft.Json 才能充分利用 Webdriver。但是,只需下载 Webdriver.dll 并在您的 IDE 中引用它,然后实例化您的 IWebDriver 就足以打开浏览器。请参阅上面的编辑。
    猜你喜欢
    • 1970-01-01
    • 2018-05-06
    • 2018-08-30
    • 2014-08-14
    • 2011-07-31
    • 2021-06-25
    • 2011-09-14
    • 2015-08-09
    • 1970-01-01
    相关资源
    最近更新 更多