Setting up parallellism using NUnit and SpecFlow in Visual Studio (c#)
With the latest version of Nunit I was shown error messages for all my tests:
System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host.
So the docs for that suggested I add [assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
I have done his and now I get a message for each test=
OneTimeSetUp: System.InvalidOperationException : Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode.
My AssembyInfo file reads
[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(4)]
[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
Using latest versions of Nunit, nunit runner and specflow.nunit... 3.9.58
-
I am not sure our NUnit integration can handle InstancePerTestCase, as it is written for the normal NUnit Behavior that they reuse the same instance.
Please open an issue at https://github.com/SpecFlowOSS/SpecFlow and please attach a small test project where we can reproduce the issue.
0 -
I will do as suggested, but even when I set [assembly: FixtureLifeCycle(LifeCycle.SingleInstance)] I
get a mesage on execution for all then tests>OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:50603/session/0118de093f3531cfca32911f1b040d1e/element. The status of the exception was UnknownError, and the message was: No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.
----> System.Net.WebException : No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.
----> System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it.
----> System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
What should my specflow.json file look like ?0 -
Yeah, but this is an error in your Selenium Code. It has nothing to do with NUnit and SpecFlow.
Can you post the stack trace of the original error to see who is throwing the exception? I assumed that it was NUnit, but now I am not sure anymore.
0 -
It does not seem to give a stack error - only shows OneTimeSetUp: System.InvalidOperationException : Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode.
This is the last few lines from the debug output >
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Users\chall\Source\Repos\OAP01042022\OAP Regression Alternative\bin\Debug\netcoreapp3.1\SpecFlow.Internal.Json.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Net.Security.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Security.Cryptography.X509Certificates.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Diagnostics.DiagnosticSource.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Reflection.Metadata.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Collections.Immutable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Collections.NonGeneric.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Security.Principal.Windows.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Security.Claims.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x59b8 has exited with code 0 (0x0).
The thread 0x67c0 has exited with code 0 (0x0).
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.23\System.Security.Cryptography.Encoding.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x50a4 has exited with code 0 (0x0).
The program '[18424] testhost.exe' has exited with code 0 (0x0).0 -
Do you have specified a method with these 2 attributes? If so, you need to move the code to a TestRun hook.
SpecFlow is using these to integrate into NUnit.
0 -
Sorry, I dont understand this response.
My AssembyInfo file reads
[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(4)]
[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
I know of no other place in the cde where they are referenced.
Also I am not awrae of a TestRun hook. I only have the following in my Hooks file>using System;
using System.Diagnostics;
using OpenQA.Selenium;
using TechTalk.SpecFlow;
using NUnit.Framework;
namespace OAP_Regression.Helper
{[Binding]//example
[TestFixture]
public class Hooks
{
[OneTimeSetUp]
public static void Setup ()
{
}
[OneTimeTearDown]
public static void Cleanup()
{ /* ... */ }// [Test]
// static public void Add()
// { /* ... */ }
public IWebDriver Driver;public Hooks(IWebDriver driver)
{
Driver = driver;
}
[AfterScenario]
public void AfterScenario()
{
Driver.Quit();
Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");foreach (var chromeDriverProcess in chromeDriverProcesses)
{
chromeDriverProcess.Kill();
}Process[] chromeDriverProcesses1 = Process.GetProcessesByName("chrome");
foreach (var chromeDriverProcess1 in chromeDriverProcesses1)
{
chromeDriverProcess1.Kill();
}
}[AfterTestRun]
public static void closechromedriver()
{
Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");foreach (var chromeDriverProcess in chromeDriverProcesses)
{
chromeDriverProcess.Kill();
}Process[] chromeDriverProcesses1 = Process.GetProcessesByName("chrome");
foreach (var chromeDriverProcess1 in chromeDriverProcesses1)
{
chromeDriverProcess1.Kill();
}
}}
}
0
Please sign in to leave a comment.
Comments
6 comments