问题描述
我正在尝试使用 NUnit 和 Selenium 2 在 C# 中运行一些测试.我遵循的步骤:
I'm trying to run some tests in C# with NUnit and Selenium 2. Steps I followed:
- 我安装了 NUnit.我想我不能在这里有任何错误.
- 我下载了 Selenium 2:我从 this 链接和来自 this 的 C# 服务器.
启动 selenium 服务器,执行以下命令:(我现在怀疑这一步是否必要)
- 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
当 -using NUnit- 我运行一个使用 FirefoxDriver 实例的简单谷歌测试时,出现此错误:
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?
推荐答案
首先,要使用 C#.NET 使用 selenium 运行测试,您不必使用 RC(远程控制)服务器.你需要做的就是
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");
}
关于你的错误.我遇到了类似的问题,我想说这与 RC Server 在本地计算机上运行的端口有关.
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
}
}
}
这篇关于使用 NUnit 和 Selenium 2.11.0 异常运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!