我正在使用Specflow和Watin编写UI测试。 我做了以下工作以确保Watin工作
在App.config中设置Thread.ApartmentState
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<!-- Valid values are STA,MTA. Others ignored. -->
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>
在InteropSHDocVw的属性中,我设置了&#34;嵌入式互操作类型&#34;为假和&#34;复制本地&#34;为真
我的代码看起来像这样...... ()中的代码是因为我不允许与此网站共享凭据和网址
指标功能
Feature: Company
In order to earn money
As a company
I want the suer to be able to shop our products
Scenario: Log In
Given I have navigated to (a companys test website)
And I have entered (a username) and (a password) as credentials
When I press Log in
Then then I should have the (permissions)
用Watin写的测试步骤
using NUnit.Framework;
using System;
using TechTalk.SpecFlow;
using WatiN.Core;
namespace Projectname.Companyname.Specs
{
[Binding]
[RequiresSTA]
public class CompanySteps
{
IE browser = new IE();
[Given]
public void Given_I_have_navigated_to_URL(string url)
{
browser.GoTo(url);
}
[Given]
public void Given_I_have_entered_EMAIL_and_PASSWORD_as_credentials(string email, string password)
{
browser.TextField(Find.ByName("UserName")).TypeText(email);
browser.TextField(Find.ByText("Password")).TypeText(password);
}
[When]
public void When_I_press_Log_in()
{
browser.Button(Find.ByText("Log in »")).Click();
}
[Then]
public void Then_then_I_should_have_the_PERMISSION_permission(string permission)
{
browser.GoTo("the page where the permissions is showing as plain text");
Assert.IsTrue(browser.ContainsText(permission));
}
}
现在,我的问题是,我已经完成了在线提到的修复STA或Interop异常的所有事情,但现在当我运行我的Specflow / Watin测试时,我仍然得到STA线程的这个异常: / p>
System.Reflection.TargetInvocationException:调用目标抛出了异常。 ----&GT; System.Threading.ThreadStateException:CurrentThread需要将它的ApartmentState设置为ApartmentState.STA才能自动化Internet Explorer。
遇到同样问题且有解决方案的人?我忘记了任何代码部分吗?某处语法错了吗?
最诚挚的问候并提前感谢您的帮助。