WatiN - 失败:System.UriFormatException:无效的 URI:无法解析主机名

发布于 2024-12-20 23:29:24 字数 1079 浏览 1 评论 0原文

好的,我一直在尝试单元测试。我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柏拉图鍀咏恒 2024-12-27 23:29:24

您是否尝试过找到这样的东西:

Link link = window.Link(Find.By("rawurl", "http://www.vietnamesetestingboard.org/zbxe/?mid=download&category=197510"));

Have you tried locating something like this:

Link link = window.Link(Find.By("rawurl", "http://www.vietnamesetestingboard.org/zbxe/?mid=download&category=197510"));
笑,眼淚并存 2024-12-27 23:29:24

好吧,第一个问题似乎是这一行的 Find.ByUrl 调用...

Element Locate = window.Element(Find.ByText("") && Find.ByValue("") && 
    Find.ById("") && Find.BySrc("") && Find.ByUrl(""));

删除它...

Element Locate = window.Element(Find.ByText("") && Find.ByValue("") &&
    Find.ById("") && Find.BySrc(""));

然后它就通过了。不太确定你想在这里完成什么,但希望这会有所帮助。

Ok, the first problem seems to be with the Find.ByUrl call on this line...

Element Locate = window.Element(Find.ByText("") && Find.ByValue("") && 
    Find.ById("") && Find.BySrc("") && Find.ByUrl(""));

Remove it...

Element Locate = window.Element(Find.ByText("") && Find.ByValue("") &&
    Find.ById("") && Find.BySrc(""));

And it passes. Not really sure what you're trying to accomplish here, but hope this helps.

绝情姑娘 2024-12-27 23:29:24

这可能是由于 ? 的存在而发生的。 URL 中的字符以及执行查找操作时 WatiN 内部操作的方式

您可能想尝试一下

Link lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510 = window.Link(Find.ByUrl(new Regex(@"^http://www.vietnamesetestingboard.org/zbxe/\?mid=download&category=197510$")));

这使用正则表达式重载来查找 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

Link lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510 = window.Link(Find.ByUrl(new Regex(@"^http://www.vietnamesetestingboard.org/zbxe/\?mid=download&category=197510$")));

This uses a Regex overload for finding the URL and will escape the ? character.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文