Running tests with NUnit and Selenium 2.11.0 exception

让人想犯罪 __ 提交于 2019-12-25 02:21:00

问题


I'm trying to run some tests in C# with NUnit and Selenium 2. Steps I followed:

  • I installed NUnit. I figure I can't have any errors here.
  • I downloaded Selenium 2: I got the client from this link and the C# server from this one.
  • Started the selenium server executing the following command: (i´m now doubting whether this step is necessary or not)

    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
    

When -using NUnit- I run a simple google test which uses an instance of FirefoxDriver, this error comes up:

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

This is driving me crazy!! Any help out there?


回答1:


First things first, to run test with selenium using C#.NET you don't have to use the RC(remote control) server. All you need to do is

public IWebDriver driver = new FireFoxDriver();

public void test()
{
  driver.Navigate().GoToUrl("google.com");
}

as to your error. I had a similar problem and I want to say that it had something to do with the port that RC Server runs on on your local computer.

------- Edit -------

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
        }
    }
}


来源:https://stackoverflow.com/questions/7947773/running-tests-with-nunit-and-selenium-2-11-0-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!