如何使用 Watin 测试 Web 服务
我正在尝试编写一个调用 Web 服务并测试其结果的测试。
[Test]
public void should_display_correct_customer_when_DoCustomerSearch_is_invoked()
{
using (var browser = new IE("http://localhost:61245/WebServices/CustomerSearch.asmx?op=DoCustomerSearch"))
{
browser.WaitForComplete();
browser.TextField(Find.ByName("txtSearch")).TypeText("microsoft");
browser.Button(Find.ByValue("Invoke")).Click();
browser.Close();
IE poppedUpBrowser = IE.AttachTo<IE>(Find.ByUrl("http://localhost:61245/WebServices/CustomerSearch.asmx/DoCustomerSearch"));
poppedUpBrowser.WaitForComplete();
Assert.IsTrue(poppedUpBrowser.ContainsText("Microsoft Corporation"));
}
}
当我通过浏览器调用该服务时,会显示结果,但是当 watin 运行相同的测试时,结果页面出现 500 服务器错误。
请提供任何帮助。
I'm trying to write a test that invokes a web service and tests it's results.
[Test]
public void should_display_correct_customer_when_DoCustomerSearch_is_invoked()
{
using (var browser = new IE("http://localhost:61245/WebServices/CustomerSearch.asmx?op=DoCustomerSearch"))
{
browser.WaitForComplete();
browser.TextField(Find.ByName("txtSearch")).TypeText("microsoft");
browser.Button(Find.ByValue("Invoke")).Click();
browser.Close();
IE poppedUpBrowser = IE.AttachTo<IE>(Find.ByUrl("http://localhost:61245/WebServices/CustomerSearch.asmx/DoCustomerSearch"));
poppedUpBrowser.WaitForComplete();
Assert.IsTrue(poppedUpBrowser.ContainsText("Microsoft Corporation"));
}
}
When I invoke the service through the browser, the results are displayed but when watin runs through the same test, the results page has a 500 server error.
Any help appreciated please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试通过 WatiN 测试 Web 服务?
有更好的方法可以做到这一点:您应该在单元/集成测试中测试您的逻辑。这些测试的执行速度比 WatiN 快得多。
HTTP 500 由您的 Web 服务返回 - 您的代码可能抛出异常 - 检查您的日志或附加调试器。
Are you trying to test Web Service through WatiN?
There are better ways to do that: you should rather test your logic in unit / integration tests. Those tests will execute much faster than WatiN.
The HTTP 500 is returned by your web service - there is probably an exception being thrown from your code - check your logs or attach a debugger.
我同意 Jakub 的观点,使用 WatiN 来测试 Web 服务似乎不是一个好主意。您应该使用 Visual Studio 使用 Web 服务,它将为您创建一个类。您可以通过生成的类调用Web服务并检查结果。
I agree with Jakub, using WatiN to test web services doesn't seem like a good idea. You should consume the web service using Visual Studio, which will create a class for you. You can call the web service via the generated class and check the result.