WatiN - 失败:System.UriFormatException:无效的 URI:无法解析主机名
好的,我一直在尝试单元测试。我正在使用 Nunit 和 WatiN 进行测试,并决定尝试实现 WatiN 测试记录器。我不知道是否有人熟悉它,但我正在使用 2.0 版本(测试版),我直接从测试记录器中提取了以下代码,并且只稍微清理了一下。
[TestFixture, RequiresSTA]
class WatiNTesting
{
[Test]
public void WatiNTest()
{
IE window = new IE("http://www.google.com");
TextField txt_q = window.TextField(Find.ByName("q"));
Element Locate = window.Element(Find.ByText("") && Find.ByValue("") && Find.ById("") && Find.BySrc("") && Find.ByUrl(""));
Link lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510 = window.Link(Find.ByUrl("http://www.vietnamesetestingboard.org/zbxe/?mid=download&category=197510"));
txt_q.TypeText("Watin");
Locate.Click();
lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510.Click();
window.Dispose();
}
}
每当我运行它时,都会打开 goolge 窗口,然后 Nununit 返回此错误:
Failure: System.UriFormatException : Invalid URI: The hostname could not be parsed.
有谁知道如何消除此错误,或者有办法解决它吗?
Ok so I have been experimenting with Unit Testing. I am using Nunit and WatiN to do my testing and decided to try to implement the WatiN Test Recorder. I don't know if anyone is familiar with it, but I am using the 2.0 build (beta) I have the following code pulled direcltly from the test recorder and only slightly cleaned up.
[TestFixture, RequiresSTA]
class WatiNTesting
{
[Test]
public void WatiNTest()
{
IE window = new IE("http://www.google.com");
TextField txt_q = window.TextField(Find.ByName("q"));
Element Locate = window.Element(Find.ByText("") && Find.ByValue("") && Find.ById("") && Find.BySrc("") && Find.ByUrl(""));
Link lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510 = window.Link(Find.ByUrl("http://www.vietnamesetestingboard.org/zbxe/?mid=download&category=197510"));
txt_q.TypeText("Watin");
Locate.Click();
lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510.Click();
window.Dispose();
}
}
Whenever I go to run it, the window opens to goolge then Nununit returns this error:
Failure: System.UriFormatException : Invalid URI: The hostname could not be parsed.
Does anyone know how to get rid of this error, or a way to get around it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过找到这样的东西:
Have you tried locating something like this:
好吧,第一个问题似乎是这一行的 Find.ByUrl 调用...
删除它...
然后它就通过了。不太确定你想在这里完成什么,但希望这会有所帮助。
Ok, the first problem seems to be with the Find.ByUrl call on this line...
Remove it...
And it passes. Not really sure what you're trying to accomplish here, but hope this helps.
这可能是由于 ? 的存在而发生的。 URL 中的字符以及执行查找操作时 WatiN 内部操作的方式
您可能想尝试一下
这使用正则表达式重载来查找 URL 并将转义 ?特点。
This might be occurring due to the presence of the ? character in your URL and the way WatiN internally operates while performing a find operation
You might want to try this
This uses a Regex overload for finding the URL and will escape the ? character.