我正在尝试在此处的文档中运行示例。
我正在使用带有 MSTest 的 Visual Studio,所以我稍微修改了代码,现在看起来像这样:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAutomation;
using FluentAutomation.Interfaces;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace UnitTestProject1
{
public class BingSearchPage : PageObject
{
public BingSearchPage(FluentTest test)
: base(test)
{
Url = "http://bing.com/";
At = () => I.Expect.Exists(SearchInput); //Documentation says "At = () =>; I.Expect.Exists(SearchInput);" but I think that's a typo
}
public BingSearchResultsPage Search(string searchText)
{
I.Enter(searchText).In(SearchInput);
I.Press("{ENTER}");
return this.Switch();
}
private const string SearchInput = "input[title='Enter your search term']";
}
public class BingSearchResultsPage : PageObject
{
public BingSearchResultsPage(FluentTest test)
: base(test)
{
At = () => I.Expect.Exists(SearchResultsContainer);
}
public BingSearchResultsPage FindResultUrl(string url)
{
I.Expect.Exists(string.Format(ResultUrlLink, url));
return this;
}
private const string SearchResultsContainer = "#b_results";
private const string ResultUrlLink = "a[href='{0}']";
}
[TestClass]
public class UnitTest1 : FluentTest
{
public UnitTest1()
{
SeleniumWebDriver.Bootstrap(SeleniumWebDriver.Browser.Chrome);
}
[TestMethod]
public void SearchForFluentAutomation()
{
new BingSearchPage(this)
.Go()
.Search("FluentAutomation")
.FindResultUrl("http://fluent.stirno.com/blog/FluentAutomation-scriptcs/");
}
}
}
我收到如下错误:
错误 1 'FluentAutomation.PageObject' 不包含带有 1 个参数的构造函数 C:\Users\Shitij\Documents\Visual Studio 2013\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs 13 15 UnitTestProject1
错误 2 当前上下文中不存在名称“I” C:\Users\Shitij\Documents\Visual Studio 2013\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs 16 20 UnitTestProject1
错误 3“UnitTestProject1.BingSearchPage”不包含“Switch”的定义,并且找不到接受“UnitTestProject1.BingSearchPage”类型的第一个参数的扩展方法“Switch”(您是否缺少 using 指令或程序集引用?) C:\Users\Shitij\Documents\Visual Studio 2013\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs 23 25 UnitTestProject1
感觉像一个愚蠢的问题,但我坚持下去。知道我做错了什么吗?属性“I”似乎在 FluentTest 类中,那么文档如何在派生自 PageObject 的类中使用它?