0

我正在使用“watin”学习软件测试。目前我想记录一个关于如何搜索单词的测试:Google 上的单元测试。我在我的 IE 上安装了开发者插件并
使用它来获取谷歌的搜索文本框和按钮名称。当我运行测试并
输入搜索时术语我收到此错误消息:First_test 失败引发异常:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using WatiN.Core;

namespace Web_project_test
{
[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void First_test()
    {
        IE ie = new IE("http://www.google.com");  
        ie.TextField(Find.ByName("q")).TypeText("Unit testing");
        ie.Button(Find.ByValue("btnk")).Click();  
        bool Expected_Result = ie.Text.Contains("Unit testing");  
        Assert.IsTrue(Expected_Result);
    }  
}  

}

4

1 回答 1

1

这是在http://watin.org/上的 Watin.org 上显示的示例

using (var browser = new IE("http://www.google.co.uk"))
  {
    browser.TextField(Find.ByName("q")).TypeText("WatiN");
    browser.Button(Find.ByName("btnK")).Click();

    Assert.IsTrue(browser.ContainsText("WatiN"));
  }

更新 :

这行代码ie.Button(Find.ByValue("btnk")).Click(); 看起来不正确,因为 google.com 上的搜索按钮的 id 是btnk,值是“Google 搜索”

这可能是您测试失败的问题,请将该行更正为:ie.Button(Find.ByName("btnk")).Click();

于 2012-07-04T13:00:46.050 回答