SpecFlow.Actions
SpecFlow.Actions copied to clipboard
Crosspost from main repo: Updating SpecFlow.Actions.WindowsAppDriver NuGet package results in inability to run tests
I originally posted this issue to the main repo here: https://github.com/SpecFlowOSS/SpecFlow/issues/2691, but it seems like it is a better fit for this repo.
SpecFlow Version
3.9.74
Which test runner are you using?
xUnit
Test Runner Version Number
SpecFlow.xUnit 3.9.74, xUnit 2.4.2
.NET Implementation
.NET 6.0
Project Format of the SpecFlow project
Sdk-style project format
.feature.cs files are generated using
SpecFlow.Tools.MsBuild.Generation NuGet package
Test Execution Method
Visual Studio Test Explorer
SpecFlow Section in app.config or content of specflow.json
specflow.json:
{
"$schema": "https://specflow.org/specflow-config.json"
}
specflow.actions.json
{
"windowsAppDriver": {
"capabilities": {
"app": "../../../../WpfExample/bin/Debug/net6.0-windows/WpfExample.exe"
},
"WindowsAppDriverPath": "C:\\Program Files (x86)\\Windows Application Driver\\WinAppDriver.exe"
}
}
Issue Description
After upgrading the NuGet packages on my very simple UI test sample project (see image), I can no longer run UI tests.
Running the tests through the Visual Studio (2022) Test Explorer, I receive the following result:
Message:
System.AggregateException : One or more errors occurred. (Interface cannot be resolved: SpecFlow.Actions.Configuration.ISpecFlowActionJsonLoader (resolution path: SpecFlow.Actions.WindowsAppDriver.Configuration.WindowsAppDriverConfiguration)) (The following constructor parameters did not have matching fixture data: SpecFlow_Specs_XUnitAssemblyFixture assemblyFixture)
---- BoDi.ObjectContainerException : Interface cannot be resolved: SpecFlow.Actions.Configuration.ISpecFlowActionJsonLoader (resolution path: SpecFlow.Actions.WindowsAppDriver.Configuration.WindowsAppDriverConfiguration)
---- The following constructor parameters did not have matching fixture data: SpecFlow_Specs_XUnitAssemblyFixture assemblyFixture
Stack Trace:
----- Inner Stack Trace #1 (BoDi.ObjectContainerException) -----
<>c__DisplayClass3_0.<ResolvePerContext>b__1()
RegistrationWithStrategy.ExecuteWithLock(Object lockObject, Func`1 getter, Func`1 factory, ResolutionList resolutionPath)
TypeRegistration.ResolvePerContext(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
RegistrationWithStrategy.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
<>c__DisplayClass71_0.<ResolveArguments>b__0(ParameterInfo p)
SelectArrayIterator`2.ToArray()
Enumerable.ToArray[TSource](IEnumerable`1 source)
ObjectContainer.ResolveArguments(IEnumerable`1 parameters, RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.CreateObject(Type type, ResolutionList resolutionPath, RegistrationKey keyToResolve)
<>c__DisplayClass3_0.<ResolvePerContext>b__1()
RegistrationWithStrategy.ExecuteWithLock(Object lockObject, Func`1 getter, Func`1 factory, ResolutionList resolutionPath)
TypeRegistration.ResolvePerContext(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
RegistrationWithStrategy.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
<>c__DisplayClass71_0.<ResolveArguments>b__0(ParameterInfo p)
SelectArrayIterator`2.ToArray()
Enumerable.ToArray[TSource](IEnumerable`1 source)
ObjectContainer.ResolveArguments(IEnumerable`1 parameters, RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.CreateObject(Type type, ResolutionList resolutionPath, RegistrationKey keyToResolve)
<>c__DisplayClass3_0.<ResolvePerContext>b__1()
RegistrationWithStrategy.ExecuteWithLock(Object lockObject, Func`1 getter, Func`1 factory, ResolutionList resolutionPath)
TypeRegistration.ResolvePerContext(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
RegistrationWithStrategy.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
ObjectContainer.Resolve(Type typeToResolve, String name)
ObjectContainer.Resolve[T](String name)
ObjectContainer.Resolve[T]()
WindowsAppDriverRuntimePlugin.RuntimePluginTestExecutionLifecycleEventEmitter_BeforeTestRun(Object sender, RuntimePluginBeforeTestRunEventArgs e)
RuntimePluginTestExecutionLifecycleEvents.RaiseBeforeTestRun(IObjectContainer objectContainer)
RuntimePluginTestExecutionLifecycleEventEmitter.RaiseExecutionLifecycleEvent(HookType hookType, IObjectContainer container)
TestExecutionEngine.FireEvents(HookType hookType)
TestExecutionEngine.OnTestRunStart()
TestRunner.OnTestRunStart()
TestRunnerManager.FireTestRunStart()
TestRunnerManager.OnTestRunStart(Assembly testAssembly, IContainerBuilder containerBuilder)
SpecFlow_Specs_XUnitAssemblyFixture.ctor() line 19
RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----
Steps to Reproduce
Clone my repo, build the project, and attempt to run tests via Visual Studio Test Explorer
Link to Repro Project
https://github.com/aronweiler/random/tree/main/SpecFlowExample
As a follow-up, I tried reverting the updated NuGet packages one by one, and found that it was the update of the SpecFlow.Actions.WindowsAppDriver
that is the culprit.
If I downgrade the SpecFlow.Actions.WindowsAppDriver
to v0.1.177, the tests work again.
Going to the SpecFlow.Actions.WindowsAppDriver
v0.1.350 causes this issue.
Is there something I am missing in order to get these tests working again?
Same with #124
Same here.
Started a new project, updated nuget references. Same error. Downgraded to SpecFlow.Actions.WindowsAppDriver to v0.1.177 and tests are running now.
What's is wrong???
If you need the output, here it is:
Setup failed for test fixture MyProject_NUnitAssemblyHooks
BoDi.ObjectContainerException : Interface cannot be resolved: SpecFlow.Actions.Configuration.ISpecFlowActionJsonLoader (resolution path: SpecFlow.Actions.WindowsAppDriver.Configuration.WindowsAppDriverConfiguration)
StackTrace: at BoDi.ObjectContainer.TypeRegistration.<>c__DisplayClass3_0.<ResolvePerContext>b__1()
at BoDi.ObjectContainer.RegistrationWithStrategy.ExecuteWithLock(Object lockObject, Func1 getter, Func
1 factory, ResolutionList resolutionPath)
at BoDi.ObjectContainer.TypeRegistration.ResolvePerContext(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.RegistrationWithStrategy.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
at BoDi.ObjectContainer.<>c__DisplayClass71_0.<ResolveArguments>b__0(ParameterInfo p)
at System.Linq.Enumerable.SelectArrayIterator2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable
1 source)
at BoDi.ObjectContainer.ResolveArguments(IEnumerable1 parameters, RegistrationKey keyToResolve, ResolutionList resolutionPath) at BoDi.ObjectContainer.CreateObject(Type type, ResolutionList resolutionPath, RegistrationKey keyToResolve) at BoDi.ObjectContainer.TypeRegistration.<>c__DisplayClass3_0.<ResolvePerContext>b__1() at BoDi.ObjectContainer.RegistrationWithStrategy.ExecuteWithLock(Object lockObject, Func
1 getter, Func1 factory, ResolutionList resolutionPath) at BoDi.ObjectContainer.TypeRegistration.ResolvePerContext(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath) at BoDi.ObjectContainer.RegistrationWithStrategy.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath) at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath) at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name) at BoDi.ObjectContainer.<>c__DisplayClass71_0.<ResolveArguments>b__0(ParameterInfo p) at System.Linq.Enumerable.SelectArrayIterator
2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at BoDi.ObjectContainer.ResolveArguments(IEnumerable
1 parameters, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.CreateObject(Type type, ResolutionList resolutionPath, RegistrationKey keyToResolve)
at BoDi.ObjectContainer.TypeRegistration.<>c__DisplayClass3_0.<ResolvePerContext>b__1()
at BoDi.ObjectContainer.RegistrationWithStrategy.ExecuteWithLock(Object lockObject, Func1 getter, Func
1 factory, ResolutionList resolutionPath)
at BoDi.ObjectContainer.TypeRegistration.ResolvePerContext(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.RegistrationWithStrategy.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
at BoDi.ObjectContainer.Resolve(Type typeToResolve, String name)
at BoDi.ObjectContainer.Resolve[T](String name)
at BoDi.ObjectContainer.ResolveT
at SpecFlow.Actions.WindowsAppDriver.WindowsAppDriverRuntimePlugin.RuntimePluginTestExecutionLifecycleEventEmitter_BeforeTestRun(Object sender, RuntimePluginBeforeTestRunEventArgs e)
at TechTalk.SpecFlow.Plugins.RuntimePluginTestExecutionLifecycleEvents.RaiseBeforeTestRun(IObjectContainer objectContainer)
at TechTalk.SpecFlow.Plugins.RuntimePluginTestExecutionLifecycleEventEmitter.RaiseExecutionLifecycleEvent(HookType hookType, IObjectContainer container)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnTestRunStart()
at TechTalk.SpecFlow.TestRunner.OnTestRunStart()
at TechTalk.SpecFlow.TestRunnerManager.FireTestRunStart()
at TechTalk.SpecFlow.TestRunnerManager.OnTestRunStart(Assembly testAssembly, IContainerBuilder containerBuilder)
at MyProject_NUnitAssemblyHooks.AssemblyInitialize() in C:\Dev\MyProject\MyProject\obj\Debug\net6.0\NUnit.AssemblyHooks.cs:line 20
NUnit Adapter 4.5.0.0: Test execution complete
========== Test run finished: 1 Tests (0 Passed, 1 Failed, 0 Skipped) run in 775 ms ==========
Here is a patch that worked for me. Add the following file to your SpecFlow project (e.g. SpecFlowCalculator.Specs)
// ConfigurationRuntimePluginPatch.cs
using SpecFlow.Actions.Configuration;
using TechTalk.SpecFlow.Plugins;
using TechTalk.SpecFlow.UnitTestProvider;
[assembly:RuntimePlugin(typeof(ConfigurationRuntimePluginPatch))]
namespace SpecFlow.Actions.Configuration
{
public class ConfigurationRuntimePluginPatch : IRuntimePlugin
{
public void Initialize(
RuntimePluginEvents runtimePluginEvents,
RuntimePluginParameters runtimePluginParameters,
UnitTestProviderConfiguration unitTestProviderConfiguration)
{
runtimePluginEvents.RegisterGlobalDependencies += RuntimePluginEvents_RegisterGlobalDependencies;
}
private void RuntimePluginEvents_RegisterGlobalDependencies(object sender, RegisterGlobalDependenciesEventArgs e)
{
e.ObjectContainer.RegisterTypeAs<SpecFlowActionJsonLocator, ISpecFlowActionJsonLocator>();
e.ObjectContainer.RegisterTypeAs<SpecFlowActionJsonLoader, ISpecFlowActionJsonLoader>();
}
}
}
In ConfigurationRuntimePlugin.cs, the types SpecFlowActionJsonLocator
and SpecFlowActionJsonLoader
need to be registered in RuntimePluginEvents_RegisterGlobalDependencies
instead of RuntimePluginEvents_CustomizeScenarioDependencies
.
The issue can be reproduced and debugged using the Calculator example in Actions.WindowsAppDriver.
@maintainers: Please let me know if you would like me to create a PR.