基于
this article
我已经在测试设置和文本fixture的构造函数中进行了尝试,但这两种方法似乎都不会导致使用我的自定义类。测试仍在运行和工作,但我必须使用完整的asp.net身份证。
我正在使用nunit2.5.2.9222的VS2008中的watin2.0.15.928。我以管理员的身份运行visualstudio,只要不依赖自定义查找逻辑,测试就会成功运行。
下面是文本fixture的开始部分,在这里我设置FindByDefaultFactory
namespace Fundsmith.Web.Main.BrowserTests
{
[TestFixture]
class WatinHomepageTests
{
private IE _ie;
[SetUp]
public void Setup()
{
Settings.FindByDefaultFactory = new FindByAspIdFactory();
_ie = new IE("http://localhost/somepage.aspx");
}
//etc etc...
using System.Text.RegularExpressions;
using WatiN.Core;
using WatiN.Core.Constraints;
using WatiN.Core.Interfaces;
namespace Fundsmith.Web.Main.BrowserTests
{
public class FindByAspIdFactory : IFindByDefaultFactory
{
public Constraint ByDefault(string value)
{
// This code is never called :(
// My custom find by id code to cope with asp.net webforms ids...
return Find.ById(value);
}
public Constraint ByDefault(Regex value)
{
return Find.ById(value);
}
}
}
编辑:事后补充信息。
基于我的推测(见下面的答案),我用Watin来寻找元素的方法是错误的。我在打电话查找.ById,而不是让默认操作发生。所以我重新分配了默认值,但是没有使用它!
[Test]
public void StepOneFromHomepageShouldRedirectToStepTwo()
{
_ie.TextField(Find.ById("textBoxId")).TypeText("100");
//Other test stuff...
}