SpecFlow +等待NUnit + Windows Server 2008 R2 上的 TeamCity

发布于 2024-11-09 13:33:43 字数 2310 浏览 4 评论 0原文

我最近在设置完全自动化的夜间构建/测试/部署环境时遇到了一些麻烦。简而言之解释一下设置。我们使用 Mercurial 作为源控制系统,使用 TeamCity 作为构建服务器。目前,为了简单起见,它在一台单独的机器上只有一个构建代理。

其想法如下:每天晚上运行一次 TeamCity 构建。从 Mercurial 存储库中提取最新版本,运行构建,运行单元测试,部署到测试服务器,针对新部署的测试服务器运行验收测试(在构建代理上),如果所有这些都通过,则将批次部署到临时服务器。除了验收测试之外,我已经完成了所有工作。这些是通过 SpecFlow 和 WatiN 完成的。 Everything 在开发机器(Windows 7 32 位)上运行良好。但是,当我尝试运行验收测试(TeamCity 中的 NUnit)时,运行器报告由于步骤 [Browser].ContainsText(browserText) 而失败。到目前为止的所有步骤都正确运行,如果我在构建代理上的同一浏览器中复制这些步骤(获得完整的管理员访问权限),我可以看到存在的文本。据我所知,测试应该通过。

我发现这个stackoverflow线程让我觉得我我保持浏览器实例的方式可能出了问题。解释一下:我有一组常见步骤,例如“当我单击 X 按钮时”或“当我在字段 Y 中输入文本 X 时”,以及有问题的步骤“然后我会看到 X”。因为我正在使尽可能多的测试可重用,所以我还概括了 @requires_browser 场景要求,然后定义如下: 然后是

[BeforeScenario("requires_browser")]
public void RequiresBrowserBeforeFeature()
{
    Settings.MakeNewIeInstanceVisible = false;
    ScenarioContext.Current.Set<Browser>(new IE(true));
}

[AfterScenario("requires_browser")]
public void RequiresBrowserAfterFeature()
{
    ScenarioContext.Current.Get<Browser>().Close();
    ScenarioContext.Current.Get<Browser>().Dispose();
}

通用步骤:

[Then("I am shown \"(.*)\"")]
public void ThenIAmShown(string text)
{
    Assert.IsTrue(ScenarioContext.Current.Get<Browser>().ContainsText(text));
}

由此我可以定义在文本框中输入文本的其他通用步骤,单击按钮等。所有这些都在开发环境中完美运行,在 Visual Studio 2010 中运行[以管理员身份]。

我认为应该保留 ScenarioContext 直到测试完成是错误的吗?

到目前为止我已经尝试过:

  1. 配置构建代理服务作为本地系统(SYSTEM)运行。这会导致所描述的问题 - ThenIAmShown(string text) 方法将始终失败。它已启用与本地桌面的交互。

  2. 配置构建代理服务以网络管理员身份运行(完全管理权限)。此设置甚至不会运行测试。我得到的异常:

    TearDown 方法失败。 WatiN.Core.Exceptions.BrowserNotFoundException:找不到 IE 窗口匹配约束:等待附加到新创建的 IE 实例时超时。搜索在“30”秒后过期。 TearDown:System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键。 在 WatiN.Core.IE.CreateIEPartiallyInitializedInNewProcess() 在 WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri,IDialogHandler logonDialogHandler,布尔 createInNewProcess) ...

  3. 已将程序集 Interop.SHDocVw.dll 和 Microsoft.mshtml.dll 添加到 bin 目录(复制到项目引用中的输出)。

  4. 从构建代理运行 NUnit UI。这将按预期运行单元测试。让我相信可能存在安全问题。在 Windows Server 2008 R2 Enterprise 上运行 NUnit 2.0.5。

有人遇到过这个问题吗?

I just recently ran into some trouble setting up a fully automated nightly build / testing / deployment environment. To explain the setup in short. We use Mercurial as source control system and TeamCity as build server. It currently only has one build agent on a separate machine to keep things simple.

The idea is as follows: each night a TeamCity build runs. Pulls latest from Mercurial repository, runs a build, runs unit tests, deploys to test server, runs acceptance tests (on build agent) against freshly deployed test server and if all of that passes deploys the lot to a staging server. I've got everything working except for acceptance tests. These are done with SpecFlow and WatiN. Everyhting runs nicely on development machines (Windows 7 32 bit). However when I try to run the acceptance tests (NUnit in TeamCity) the runner reports fail beacuse of step [Browser].ContainsText(browserText). All steps up to that ran correctly and if I replicate the steps in the same browser on build agent (got full admin access) I can see the text being present. So to my best knowledge the test should pass.

I found this stackoverflow thread that got me thinking I may be doing somwthing wrong with how I keep the browser instance around. To explain: I have a set of common steps such as "when I click X button" or "when I enter text X into field Y" and the one with an issue "then then I am shown X". Because I'm making as much as possible of tests reusable I've also generalized a @requires_browser scenario requirement which is then defined like this:

[BeforeScenario("requires_browser")]
public void RequiresBrowserBeforeFeature()
{
    Settings.MakeNewIeInstanceVisible = false;
    ScenarioContext.Current.Set<Browser>(new IE(true));
}

[AfterScenario("requires_browser")]
public void RequiresBrowserAfterFeature()
{
    ScenarioContext.Current.Get<Browser>().Close();
    ScenarioContext.Current.Get<Browser>().Dispose();
}

and then the common step:

[Then("I am shown \"(.*)\"")]
public void ThenIAmShown(string text)
{
    Assert.IsTrue(ScenarioContext.Current.Get<Browser>().ContainsText(text));
}

From this I can define other common steps that enter text into text boxes, click buttons and so on. All this works perfectly on development environment, running in visual studio 2010 [as administrator].

Am I wrong in thinking that ScenarioContext should be preserved until the test is finished?

What I've tried so far:

  1. Configuring build agent service to run as local system (SYSTEM). This causes the issue as described - the ThenIAmShown(string text) method will always fail. It has interaction with local desktop enabled.

  2. Configured build agent service to run as network administrator (full admin rights). This setup won't even runs tests. The exception I get:

    TearDown method failed. WatiN.Core.Exceptions.BrowserNotFoundException : Could not find an IE window matching constraint: Timeout while waiting to attach to newly created instance of IE.. Search expired after '30' seconds.
    TearDown : System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
    at WatiN.Core.IE.CreateIEPartiallyInitializedInNewProcess()
    at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
    ...

  3. Already added assemblies Interop.SHDocVw.dll and Microsoft.mshtml.dll to bin directory (Copy To Output in project references).

  4. Running NUnit UI from the build agent. This runs the unit tests as expected. Leads me to believe there might be an issue with security. Runnint NUnit 2.0.5 on Windows Server 2008 R2 Enterprise.

Anyone had this issue?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文