我试图谷歌,但有许多不同的方式与Selenium合作 . 我正在使用: - Windows 2003 Server - Visual Studio 2008 - 通过Firefox安装的Selenium IDE - NUnit 2.5被复制到C:\ - Selenium RC被复制到C:\
-
首先,我使用C#创建了一个库项目 .
-
这是我的 class :
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTest
{
[TestFixture]
public class NewTest
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium( "localhost", 4444, "*iexplore", "http://localhost:4444" );
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch( Exception )
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual( "", "" );
}
[Test]
public void TheNewTest()
{
selenium.Open( "/google.com" );
}
}
}
-
接下来添加C:\ Selenium RC \ selenium-dotnet-client-driver-1.0.1中的所有引用
-
编制了图书馆计划,成功了 . 没有错误 .
-
运行NUnit.exe,现在出错:(
SeleniumTest.NewTest.TheNewTest:Selenium.SeleniumException:XHR ERROR:URL = http:// localhost:4444 / google.com Response_Code = 403 Error_Message = Forbidden for Proxy
3 回答
您收到Forbidden错误,因为您将baseURL设置为Selenium RC的baseURL . 您需要将其设置为http://www.google.com然后在您的测试中看起来像
或者您需要将测试更改为
与c#一起设置selenium的ide是使用visual studio express . 你可以将nUnit作为测试框架 . 以下链接为您提供更多详细信息
How to setup C#,nUnit and selenium client drivers on VSExpress for Automated tests
Creating Basic Selenium web driver test case using Nunit and C#
创建单元测试项目
将库项目添加到您的解决方案中 .
右键单击库项目选择NuGet包选项 .
搜索selenium安装前两个选项selenium和selenium支持类 .
如果要执行跨浏览器测试,还可以下载chrome驱动程序,IEDriver,gecko驱动程序 .
在单元测试项目中创建测试类和测试方法 .
[TestClass] // ReSharper禁用一次InconsistentNaming公共类测试类{[TestMethod] public void LoginTest(){// code}}