WatiN 无法与 MSpec 一起使用 - UnauthorizedAccessException

发布于 2024-10-21 15:14:19 字数 1607 浏览 4 评论 0原文

我正在尝试使用 TestDriven.Net 让 WatiN 在 VS2010 中与 MSpec 一起工作。我的代码如下:

[Subject("Whatever")]
public class when_on_home_page {

    private static IE browser;

    Establish context = () =>
        browser = new IE();

    Because of = () => {
        browser.GoTo("http://localhost:1234/");
        browser.WaitForComplete();
    };

    It should_show_add_details_link = () =>
        browser.Link(Find.ByValue("Add Details")).Exists.ShouldBeTrue();
}

当我运行此代码时,浏览器加载页面,但是当它检查链接时,我得到:

无论如何,在主页上时
» 应显示添加详细信息链接(失败)

测试“应显示添加详细信息链接”失败: System.UnauthorizedAccessException:访问被拒绝。 (HRESULT 异常:0x80070005 (E_ACCESSDENIED)) 在 mshtml.IHTMLElementCollection.tags(对象 tagName) 在 WatiN.Core.Native.InternetExplorer.IEElementCollection.GetElementsByTag(字符串 tagName) 在 WatiN.Core.NativeElementFinder.FindElementsByTag(String tagName) 在 WatiN.Core.NativeElementFinder.d__2.MoveNext() 在 WatiN.Core.ElementFinder.FindFirst() 在 WatiN.Core.Element.FindNativeElementInternal() 在 WatiN.Core.Element.get_Exists() NavigationSpecs.cs(20,0):位于 RoboWeb.Specs.when_on_home_page.<.ctor>b__2() 在 Machine.Specifications.Model.Specification.InvokeSpecificationField() 在 Machine.Specifications.Model.Specification.Verify()

环顾四周后,我检查了以下内容:

  • VS 正在以管理员身份运行
  • TestDriven.Net 在 STA 模式下运行所有​​内容,显然
  • IE 已关闭“保护模式”
  • 我无法添加站点到受信任的站点,大概是因为它在本地运行,
  • 我调用了 WaitForComplete(),并且还尝试了 Thread.Sleep()

我也用 FireFox 尝试过,但这只是崩溃。

知道我在这里做错了什么吗?

I'm trying to get WatiN working with MSpec in VS2010, using TestDriven.Net. My code is as follows:

[Subject("Whatever")]
public class when_on_home_page {

    private static IE browser;

    Establish context = () =>
        browser = new IE();

    Because of = () => {
        browser.GoTo("http://localhost:1234/");
        browser.WaitForComplete();
    };

    It should_show_add_details_link = () =>
        browser.Link(Find.ByValue("Add Details")).Exists.ShouldBeTrue();
}

When I run this, the browser loads the page, but when it checks for the link, I get:

Whatever, when on home page
» should show add details link (FAIL)

Test 'should show add details link' failed:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at mshtml.IHTMLElementCollection.tags(Object tagName)
at WatiN.Core.Native.InternetExplorer.IEElementCollection.GetElementsByTag(String tagName)
at WatiN.Core.NativeElementFinder.FindElementsByTag(String tagName)
at WatiN.Core.NativeElementFinder.d__2.MoveNext()
at WatiN.Core.ElementFinder.FindFirst()
at WatiN.Core.Element.FindNativeElementInternal()
at WatiN.Core.Element.get_Exists()
NavigationSpecs.cs(20,0): at RoboWeb.Specs.when_on_home_page.<.ctor>b__2()
at Machine.Specifications.Model.Specification.InvokeSpecificationField()
at Machine.Specifications.Model.Specification.Verify()

Having looked around, I checked the following:

  • VS is running as administrator
  • TestDriven.Net runs everything in STA mode, apparently
  • IE has 'protected mode' turned off
  • I can't add the site to trusted sites, presumably because it's running locally
  • I call WaitForComplete(), and have also tried Thread.Sleep()

I also tried it with FireFox, but that just crashes.

Any idea what I'm doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

青衫负雪 2024-10-28 15:14:19

这些规范对我有用。事实上,这是我的第一个 WatiN 规范;我在尝试重现您收到的错误时写道。 :-)

我必须做的唯一特别的事情是关闭 IE 的保护模式。 在命令行上运行规范

  • (请参阅存储库中的 WebSpecs-Watin.cmd,请编译规范项目并在运行 cmd 之前从 VS 运行 Web 应用程序)
  • TD.Net 运行程序
  • 我使用 ReSharper

他们在这三种情况下都取得了成功。我没有以管理员身份运行。

您能否尝试使用上面链接的项目重现该错误?如果您没有安装 Git,顶部有一个下载按钮。

These specifications work for me. Actually, I this is my first WatiN spec; I wrote while trying to reproduce the error you received. :-)

The only special thing I had to do was to turn off IE's Protected Mode. I ran the specs

  • on the command line (see WebSpecs-Watin.cmd in the repo, please compile the specs project and run the web application from VS before running the cmd)
  • with the TD.Net runner
  • with ReSharper

They succeed in all three cases. I'm not running as Administrator.

Can you please try to reproduce the error with the project linked above? If you don't have Git installed, there's a download button in the top section.

祁梦 2024-10-28 15:14:19

System.UnauthorizedAccessException 可能在多种情况下发生。如果页面尚未完全加载并且您尝试访问对象,并且您根本不是正确的用户。我首先手动调试脚本,然后以管理员身份运行测试运行程序。

如果有效,请尝试 admin 和 的组合。全速、非管理和全速以及管理和调试。那么您应该清楚真正的问题是什么。在一些罕见的情况下(使用 WatiN 的早期版本),我必须将调用包装在 try - catch 中,然后处理此异常,然后在短暂等待后重试。

System.UnauthorizedAccessException can happen in a number of circumstances. If the page has not loaded fully and you try to access an object, as well as simply not being the right user. I would start by debugging through the script manually, and running the test runner as an administrator.

If that works, then try the combinations of admin & full speed, non-admin and full full speed as well as admin and debugging. Then you should have a good idea as to what the real problem. In some rare circumstances (with early early versions of WatiN,) I had to wrap calls in a try - catch then handle this exception, and then re-try after a short wait.

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