我正在尝试使用NUnit和Selenium 2在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实例的简单google测试,出现了这个错误:
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
这让我发疯!有任何帮助吗?
答案 0 :(得分: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
}
}
}