使用 Specrun 1.5.2 和 Specflow 2.1.0 运行我的测试。我遇到了测试不断中止使用硒等待很长时间的问题(因为我必须这样做,现在有办法解决它)。
WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromHours(1));
wait.PollingInterval = TimeSpan.FromMinutes(10);
wait.Timeout = TimeSpan.FromHours(1);
//TimeSpan.MaxValue.TotalHours
wait.IgnoreExceptionTypes(typeof(ThreadAbortException));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
wait.Until(ExpectedConditions.TextToBePresentInElementLocated(By.XPath($"//*[@data-ths=\"engagement_{EngagementId}\"]/../div[1]/span[2]"), "Ready"));
无论我是从命令行还是使用 C# 从 Visual Studio Enterprise 中运行测试,我都会收到以下异常:
TechTalk.SpecRun.Framework.SpecRunException:至少一个测试线程中止。---> System.ServiceModel.CommunicationObjectFaultedException:通信对象 System.ServiceModel.Channels.ServiceChannel 不能用于通信,因为它处于故障状态。
服务器堆栈跟踪:在 System.ServiceModel.Channels.CommunicationObject.ThrowIfFaulted() 在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
在 [0] 处重新引发异常:在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型) 在 TechTalk.SpecRun 的 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)。 Framework.IOutProcTestAssemblyExecutor.RunTests(TestThreadState testThreadState) at TechTalk.SpecRun.Framework.TestThread.Run(ITestExecutionManager executionManagerForRun) at TechTalk.SpecRun.Framework.AsyncTestThreadRunner.RunSync(TestExecutionManager executionManager) --- 内部异常堆栈跟踪结束--- 结果: 测试框架错误:至少一个测试线程中止。总计:1(测试执行:0) 成功:0 忽略:0 待处理:0 跳过:0 失败:0
> Here is my default.srprofile after removing 'apartmentStatew' parameter hoping it would resolve it:
<?xml version="1.0" encoding="utf-8"?>
<TestProfile xmlns="http://www.specflow.org/schemas/plus/TestProfile/1.5">
<Settings projectName="Symphony.AcceptanceTests" projectId="{04deb5e2-c1a0-4b15-930d-8247c4d4954b}" />
<Execution retryFor="None" stopAfterFailures="-1" testThreadCount="3" testSchedulingMode="Sequential" />
<!--<Execution retryFor="None" stopAfterFailures="-1" testSchedulingMode="Sequential" />-->
<Environment testThreadIsolation="Process" />
<TestAssemblyPaths>
<TestAssemblyPath>Symphony.AcceptanceTests.dll</TestAssemblyPath>
</TestAssemblyPaths>
<DeploymentTransformation>
<Steps>
<RelocateConfigurationFile target="CustomConfig{TestThreadId}.config" />
<ConfigFileTransformation configFile="Symphony.AcceptanceTests.dll.config" >
<Transformation>
<![CDATA[<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="browser" value="{Target}"
xdt:Locator="Match(key)" xdt:Transform="SetAttributes(value)" />
</appSettings>
</configuration>
]]>
</Transformation>
</ConfigFileTransformation>
</Steps>
</DeploymentTransformation>
<Targets>
<Target name="Edge">
<Filter>Browser_Edge</Filter>
</Target>
<Target name="GhostDriver">
<Filter>Ghost_Driver</Filter>
</Target>
<Target name="Chrome">
<Filter>Browser_Chrome</Filter>
</Target>
<Target name="Firefox">
<Filter>Browser_Firefox</Filter>
</Target>
<Target name="Safari">
<Filter>Browser_Safari</Filter>
</Target>
<Target name="API">
<Filter>API</Filter>
</Target>
<Target name="IE">
<Filter>Browser_IE</Filter>
</Target>
</Targets>
<TestThreads>
<TestThread id="0">
<TestAffinity>testPath:Target:Chrome</TestAffinity>
</TestThread>
<TestThread id="1">
<TestAffinity>testPath:Target:API</TestAffinity>
</TestThread>
<TestThread id="2">
<TestAffinity>testPath:Target:Edge</TestAffinity>
</TestThread>
</TestThreads>
</TestProfile>