MSilva
MSilva

Reputation: 1

Error Primitive types or structs cannot be resolved when running specflow Xamarin test

I'm trying to use SpecFlow integrated with Xamarin. During the test I'm able to insltall the application (*.apk) and çainch it getting to the login page but then i get the error:

BoDi.ObjectContainerException was unhandled by user code
HResult=-2146233088
Message=Primitive types or structs cannot be resolved: Xamarin.UITest.Platform (resolution path: VVM_SpecFlow.LoginApplicationSteps)
  Source=TechTalk.SpecFlow
  StackTrace:
   at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
   at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
   at BoDi.ObjectContainer.<>c__DisplayClass53_0.<ResolveArguments>b__0(ParameterInfo p)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 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.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 TechTalk.SpecFlow.Infrastructure.BindingInstanceResolver.ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer)
   at lambda_method(Closure , IContextManager )
   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
   at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
   at VVM___SpecFlow.LoginApplicationFeature.ScenarioCleanup()
   at VVM___SpecFlow.LoginApplicationFeature.LoginWithValidCredentials() in <……..\SpecFlowFeature1.feature:line> 12
  InnerException:  a

I believe this is happeing after specflow reads the feature file.

Can anyone help me please?

Upvotes: 0

Views: 4993

Answers (2)

Gucu112
Gucu112

Reputation: 966

If anyone uses BoDi as container between steps classes here is my workaround for resolving to the primitive type:

var test = (string)objectContainer.Resolve<object>("testString");

Upvotes: 0

Andreas Willich
Andreas Willich

Reputation: 5835

Your LoginApplicationSteps has a constructor with parameter Xamarin.UITest.Platform. This is the primitive type which makes you trouble.
SpecFlow has an integrated DI framework which is used to resolve the binding classes. It uses constructor injection. In your case, it is searching for a registration of the platform enum, which does not work. Solution would be to wrap the enum in a class and register it in the BeforeScenario hook (see Advanced options on linked documentation page).

Documentation to the DI- framework (called Context injection in SpecFlow) is here: http://specflow.org/documentation/Context-Injection/

Upvotes: 4

Related Questions