Specflow CodedUI Generator插件不生成功能文件

时间:2017-08-30 17:47:09

标签: c# cucumber ui-automation coded-ui-tests specflow

好。所以这就是我所处的位置。我正在使用Specflow 2.2.0将自动化单元测试与我们的CodedUI测试工作配对。我正在开发一个插件,将CodedUI Test属性添加到Specflow功能测试中,我遇到了一些问题。 Specflow没有识别我的插件生成Codeflow测试属性到Specflow功能文件,我不明白为什么,因为我已经按照文档中的每个指令,并查看GitHub上的其他插件,以确保我做得对。

我在自己的类库项目中有插件,并在其中包含Specflow所在的解决方案的packages文件夹中构建其dll autocopies。我编辑了汇编文件以指向生成器。我有eventhandler的初始化器。我的CodedUI项目的app.config中的所有内容都是正确的,据我所知,我仍然会收到错误。以下是我对插件和其他相关部分的所有内容:

以下是我的插件中初始化IGenerator类的代码:

namespace SpecflowCUITPluginLib
{
    public class CodedUiPlugin : IGeneratorPlugin
    {
        public void Initialize(GeneratorPluginEvents generatorPluginEvents, GeneratorPluginParameters generatorPluginParameters)
        {
            generatorPluginEvents.CustomizeDependencies += this.GeneratorPluginEventsOnCustomizeDependencies;
        }
        private void GeneratorPluginEventsOnCustomizeDependencies(object sender, CustomizeDependenciesEventArgs customizeDependenciesEventArgs)
        {
            string unitTestProviderName =
              customizeDependenciesEventArgs.SpecFlowProjectConfiguration.SpecFlowConfiguration.UnitTestProvider;
            if (unitTestProviderName.Equals("mstest", StringComparison.InvariantCultureIgnoreCase)
              || unitTestProviderName.Equals("mstest.2010", StringComparison.InvariantCultureIgnoreCase))
            {
                customizeDependenciesEventArgs.ObjectContainer.RegisterTypeAs<CodedUIGeneratorProvider, IUnitTestGeneratorProvider>();
            }
        }
        #region IGeneratorPlugin Members
        public void RegisterConfigurationDefaults(TechTalk.SpecFlow.Generator.Configuration.SpecFlowProjectConfiguration specFlowConfiguration) { }
        public void RegisterCustomizations(BoDi.ObjectContainer container, TechTalk.SpecFlow.Generator.Configuration.SpecFlowProjectConfiguration generatorConfiguration)
        {
            container.RegisterTypeAs<CodedUIGeneratorProvider, IUnitTestGeneratorProvider>();
            container.RegisterTypeAs<MsTest2010RuntimeProvider, IUnitTestRuntimeProvider>();
        }
        public void RegisterDependencies(BoDi.ObjectContainer container) { }
        #endregion
    }
}

以下是我的Generator Provider中的代码,该代码位于单独的.cs文件中:

namespace SpecflowCUITPluginLib
{

    public class CodedUIGeneratorProvider : MsTest2010GeneratorProvider
    {
        public CodedUIGeneratorProvider(CodeDomHelper codeDomHelper)
            : base(codeDomHelper) { }
        private const string TestClassAttribute = @"Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute";
        private const string CodedUiTestClassAttribute = @"Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute";
        private const string DeploymentItemAttribute = "Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute";
        public override void SetTestClass(TestClassGenerationContext generationContext, string featureTitle, string featureDescription)
        {
            base.SetTestClass(generationContext, featureTitle, featureDescription);
            foreach (CodeAttributeDeclaration declaration in generationContext.TestClass.CustomAttributes)
            {
                if (declaration.Name == TestClassAttribute)
                {
                    generationContext.TestClass.CustomAttributes.Remove(declaration);
                    break;
                }
            }
            generationContext.TestClass.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(CodedUiTestClassAttribute)));
            string filename = new Uri(this.GetType().Assembly.CodeBase).LocalPath;
            // Add deployment item in each test for the driver.
            generationContext.TestClass.CustomAttributes.Add(
                new CodeAttributeDeclaration(
                    new CodeTypeReference(DeploymentItemAttribute),
                    new CodeAttributeArgument(new CodePrimitiveExpression("SpecflowCUITPluginLib.SpecFlowPlugin.dll"))));
        }
    }
}

这是我添加到汇编文件中的行:

[assembly: GeneratorPlugin(typeof(CodedUiPlugin))]

Here is a screencap of my build settings for the plugin project

这是我的CodedUI项目中的app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>
  <specFlow>
    <unitTestProvider name="MsTest" />
    <plugins>
      <add name="SpecflowCUITPluginLib.SpecflowPlugin" path=".\MedchartUITesting\packages\specflow2.2.0\tools" type="Generator" />
    </plugins>
  </specFlow>
</configuration>

无论我做什么,我的功能文件都会出现此错误:#error Generation error: Unable to find plugin in the plugin search path: SpecflowCUITPluginLib.SpecflowPlugin. Please check http://go.specflow.org/doc-plugins for details.

任何人都会看到解决方案或问题,因为此刻我真的不知道应该在哪里寻找解决方案。

1 个答案:

答案 0 :(得分:0)

问题是可以找到插件的路径配置错误 请参阅SpecFlow论坛中的主题:https://groups.google.com/forum/#!topic/specflow/ZcbuoJLfJ_E