由于缺少程序集引用,CodedUI测试失败了吗?

时间:2013-05-23 17:55:06

标签: visual-studio-2010 visual-studio tfs tfs2010 coded-ui-tests

我在机器A上运行了使用VS2010为TFS2010构建的编码UI测试。我在机器A上安装了测试代理,测试成功运行。我的testsettings文件>角色设置为RemoteExecution,因为这些编码的测试总是需要在机器A上运行。文件总是说"连接到控制器"我指定的。

我将代码检查到构建服务器(机器B),但它失败了。在codedUI程序集上将copy local设置为false时,构建将失败并显示错误:

  

"不可运行:无法初始化单元测试扩展   ' urn:CodedUITest':未注册单元测试扩展   以下属性:   Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute"

在机器B上的应用程序日志中,我得到了这个:

  

(QTAgent32.exe,PID 5308,Thread 8)GetCollectorType:无法获取   收集器的类型   ' Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo.SystemInfoDataCollector,   Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo,   Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a':   System.IO.FileNotFoundException:无法加载文件或程序集   ' Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo,   Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'要么   其中一个依赖项。该系统找不到指定的文件。   文件名:   ' Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo,   Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'
  在System.RuntimeTypeHandle.GetTypeByName(String name,Boolean   throwOnError,Boolean ignoreCase,Boolean reflectionOnly,   StackCrawlMarkHandle stackMark,IntPtr pPrivHostBinder,Boolean   loadTypeFromPartialName,ObjectHandleOnStack type)at   System.RuntimeTypeHandle.GetTypeByName(String name,Boolean   throwOnError,Boolean ignoreCase,Boolean reflectionOnly,   StackCrawlMark&安培; stackMark,IntPtr pPrivHostBinder,Boolean   System.RuntimeType.GetType(String。的loadTypeFromPartialName)   typeName,Boolean throwOnError,Boolean ignoreCase,Boolean   reflectionOnly,StackCrawlMark& stackMark)at   System.Type.GetType(String typeName,Boolean throwOnError)at   Microsoft.VisualStudio.TestTools.DataCollection.ExecutionPluginManager.GetCollectorType(字符串   collectorTypeName,Exception& loadException)

     

警告:装配绑定日志记录已关闭。要启用程序集绑定   失败日志记录,设置注册表值   [HKLM \ Software \ Microsoft \ Fusion!EnableLog](DWORD)为1.注意:有   与程序集绑定失败相关的一些性能损失   日志记录。要关闭此功能,请删除注册表值   [HKLM \ SOFTWARE \微软\融合!EnableLog]。

在管理控制台中我得到了这个:

  

在读取sqm注册表项时遇到以下错误:   TF255003:找不到以下安装路径   功能:ApplicationTier。您没有安装该功能   必须使用不同的安装路径。

在编码的UI程序集上将copy local设置为true,我在VS中的Build Explorer中没有收到任何错误,但是构建失败并且说0/0测试运行。在机器B的应用程序日志中,我得到:

  

来自源VSTTExecution的事件ID 0的描述不能   找到。未安装引发此事件的组件   您的本地计算机或安装已损坏。你可以安装   或修复本地计算机上的组件。

     

如果事件源自另一台计算机,则显示信息   不得不与事件一起得救。

     

活动中包含以下信息:

     

(MSTest.exe,PID 5544,线程1)枚举时抛出异常   部件:   Microsoft.VisualStudio.TestTools.Exceptions.EqtDataException:无法使用   加载测试容器   ' C:\构建\ 1个\项目\二进制\ Microsoft.VisualStudio.QualityTools.CodedUITestFramework.dll'   或其中一个依赖项。错误详情:   System.IO.FileNotFoundException:无法加载文件或程序集   ' Microsoft.VisualStudio.QualityTools.Vsip ,版本= 10.0.0.0,   Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个   依赖。系统找不到指定的文件。

     

在   Microsoft.VisualStudio.TestTools.TestTypes.Unit.AssemblyEnumerator.EnumerateAssembly(IWarningHandler   warningHandler,String location,ProjectData projectData,ObjectHandle   assemblyResolverWrapper)at   Microsoft.VisualStudio.TestTools.TestTypes.Unit.AssemblyEnumerator.EnumerateAssembly(IWarningHandler   warningHandler,String location,ProjectData projectData,ObjectHandle   assemblyResolverWrapper)at   Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAttributeEnumerator.Read(ITestTypeExtensionClientSidesProvider   provider,IWarningHandler warningHandler,String assemblyFileName,   ProjectData projectData,TestRunConfiguration testRunConfiguration)

机器B确实安装了VS2010 express。

我需要做什么才能在机器B(构建机器)上进行此构建,而在机器A上运行测试(使用测试代理)?我还能做些什么来诊断这个?

更新:我尝试手动将qualitytools.vsip dll复制到项目中并以复制本地设置为true的方式引用它,但现在我又回到了

  

"无法初始化单元测试扩展程序' urn:CodedUITest':A   单元测试扩展未注册以下属性:   Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute"

3 个答案:

答案 0 :(得分:2)

请检查项目属性,即目标框架未设置为.NET framework 4客户端配置文件。而是设置为.Net framework 4(没有客户端配置文件)

答案 1 :(得分:0)

using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodedUITestProject1.Libraries
{
    class generic
    {
        public static BrowserWindow mParentWindow { get; set; }
        public static BrowserWindow ParentWindow
        {
            get
            {
                if(mParentWindow==null)
                { mParentWindow = TopParentWindow(); }
                return mParentWindow;
            }
        }

        public static BrowserWindow TopParentWindow()
        {
            BrowserWindow window = new BrowserWindow();
            window.SearchProperties[UITestControl.PropertyNames.ClassName]=BrowserWindow.CurrentBrowser.ToString();
            return window;
        }


        public enum PropertyType
        { Id,
          Name,
          ClassName,
          InnerText,
          TagInstance
        }

        public static void EnterText<T>(PropertyType type,string propvalue,string text) where T:HtmlControl
        {
            HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
            if (type==PropertyType.Id)
            {
                genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;

            }

            else if (type == PropertyType.Id)
            {
                genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;

            }
            Keyboard.SendKeys(genericControl, text);
        }

        public static void ClickLink<T>(PropertyType type, string propvalue) where T : HtmlControl
        {
            HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
            if (type == PropertyType.Id)
            {
                genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;

            }

            else if (type == PropertyType.Id)
            {
                genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;

            }
            //Assert.IsTrue(genericControl.WaitForControlExist(40000));
            Mouse.Click(genericControl);

        }

         public static Boolean ExistLink<T>(PropertyType type, string propvalue) where T : HtmlControl
        {
            HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
            if (type == PropertyType.Id)
            {
                genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;

            }

            else if (type == PropertyType.Id)
            {
                genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propvalue;

            }
            try
            {
                Assert.IsTrue(genericControl.WaitForControlExist(4000));
                return true;

            }
            catch (Exception e)
            {
                return false;
            }
            //Mouse.Click(genericControl);

        }

    }
}

答案 2 :(得分:0)

    Solution 1:  Replace the name as that seen in pop UP. Might be this code can help clicking it

    WinWindow pop = new WinWindow(null);
                pop.SearchProperties.Add("Name", "Message from webpage", "ClassName", "#32770");

    ‘Windows Internet Explorer
                pop.TechnologyName = "MSAA";
                pop.DrawHighlight();

//------------
“Usinng MSTEST.exe to generate result”

C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE>MSTest /testcontainer:
D:\Practise\CodedUITestProject1\CodedUITestProject1\CodedUITestProject1\bin\Debu
g\CodedUITestProject1.dll /test:CodedUITestMethod1 /resultsfile:D:\SachintestRes
.trx


 public void CodedUITestMethod1()
        {
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            string testcase = " /testcontainer:" + "D:\\Practise\\CodedUITestProject1\\CodedUITestProject1\\CodedUITestProject1\\bin\\Debug\\CodedUITestProject1.dll /test:CodedUITestMethod1 /resultsfile:D:\\SachintestResAut.trx";

            string Path = @"C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\MSTest";

            Process myProcess = new Process();
            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, testcase);
            myProcessStartInfo.UseShellExecute = false;
            try
            {
                myProcess.StartInfo = myProcessStartInfo;
                myProcess.Start();
                myProcess.BeginOutputReadLine();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

                WinText text = new WinText(pop);

                text.SearchProperties.Add("Name", "Some Name");
                String msg = text.GetProperty("DisplayText").ToString();

                if (msg.Contains("Data saved."))
                {
                    Console.WriteLine("System is displaying " + msg);
                }
                else
                {
                    Console.WriteLine("System is displaying " + msg);
                }

                WinButton ok = new WinButton(pop);
                ok.TechnologyName = "MSAA";
                ok.SearchProperties.Add("Name", "OK");
                Mouse.Click(ok);

    Solution 2: Try the Browser Dialog Actions like OK,Cancel,Close .May be it can be helpful. PFB snapshot below.

    try
                {
                    BrowserWindow browserWindow = new BrowserWindow();
                    browserWindow.PerformDialogAction(BrowserDialogAction.Ok);
                }
                catch (Exception)
                {
                    // If a popup does not exists and an error is thrown, continue...
                    Playback.PlaybackSettings.ContinueOnError = true;
                }

// C:\ Program Files \ Microsoft Visual Studio 12.0 \ Common7 \ IDE&gt; MSTest / testcontainer: d:\实践\ CodedUITestProject1 \ CodedUITestProject1 \ CodedUITestProject1 \ BIN \得不 g \ CodedUITestProject1.dll / test:CodedUITestMethod1 / resultsfile:D:\ SachintestRes 带有.trx

 public void CodedUITestMethod1()
        {
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            string testcase = " /testcontainer:" + "D:\\Practise\\CodedUITestProject1\\CodedUITestProject1\\CodedUITestProject1\\bin\\Debug\\CodedUITestProject1.dll /test:CodedUITestMethod1 /resultsfile:D:\\SachintestResAut.trx";

            string Path = @"C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\MSTest";

            Process myProcess = new Process();
            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, testcase);
            myProcessStartInfo.UseShellExecute = false;
            try
            {
                myProcess.StartInfo = myProcessStartInfo;
                myProcess.Start();
                myProcess.BeginOutputReadLine();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
相关问题