Specflow场景在Visual Studio 2012中引发异常

时间:2013-07-29 08:47:23

标签: coded-ui-tests specflow

我正在尝试使用specflow / CodedUI / VSTS 2012进行UI自动化。

当我尝试运行该方案时,我收到以下错误: 无法加载文件或程序集“Microsoft.VisualStudio.TestTools.UITest.Playback,Version = 11.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”或其中一个依赖项。系统找不到指定的文件。

有谁能告诉我如何解决此错误?

1 个答案:

答案 0 :(得分:1)

最后,我找到了解决此问题的方法。我不知道为什么,但你必须编写自己的程序集解析器。我在这里找到了解决方案:

http://blog.csdn.net/marryshi/article/details/8100194

但是,我必须更新VS2012的注册表路径:

static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    AssemblyName assemblyName = new AssemblyName(args.Name);
    if (assemblyName.Name.StartsWith("Microsoft.VisualStudio.TestTools.UITest", StringComparison.Ordinal))
    {
        string path = string.Empty;
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\VisualStudio\11.0"))
        {
            if (key != null)
            {
                path = key.GetValue("InstallDir") as string;
            }
        }

        if (!string.IsNullOrWhiteSpace(path))
        {
            string assemblyPath = Path.Combine(path, "PublicAssemblies",
                string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name));

            if (!File.Exists(assemblyPath))
            {
                assemblyPath = Path.Combine(path, "PrivateAssemblies",
                   string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name));

                if (!File.Exists(assemblyPath))
                {
                   string commonFiles = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86);
                   if (string.IsNullOrWhiteSpace(commonFiles))
                   {
                       commonFiles = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
                   }

                   assemblyPath = Path.Combine(commonFiles, "Microsoft Shared", "VSTT", "10.0",
                       string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name));
                }
            }

            if (File.Exists(assemblyPath))
            {
                return Assembly.LoadFrom(assemblyPath);
            }
        }
    }

    return null;
}

在运行该功能之前我是注册表解析器:

[BeforeFeature]
public static void Initialize()
{
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}