未能使用Microsoft CodedUI查找Chrome浏览器窗口以进行自动化测试

时间:2014-11-05 07:34:14

标签: asp.net visual-studio-2012 coded-ui-tests automated-tests

以下是我的开发环境的详细信息:

使用Update 4的Visual Studio 2012 Ultimate 谷歌浏览器版本38.0.2125.111米 带有32位操作系统的Windows 7 Professional 编码的UITest Builder 11.0.60315.1

我们的软件团队正在创建一个ASP.NET Web应用程序,客户已要求我们使用Microsoft Visual Studio 2012和Microsoft CodedUI来运行自动化测试。

我在Google Chrome版本38.0.2125.111 m中运行了我们的ASP.NET应用程序 我采取措施使用Microsoft CodedUI在我们的ASP.NET应用程序上记录一些浏览器用户交互步骤,最终导致生成一些代码。 以下是基于我在ASP.NET Web应用程序上执行的Brower-user交互记录生成的代码

// ------------------------------------------------------------------------------
//  <auto-generated>
//      This code was generated by coded UI test builder.
//      Version: 11.0.0.0
//
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </auto-generated>
// ------------------------------------------------------------------------------

namespace JigsawEMISTCodedUITestProject
{
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text.RegularExpressions;
    using System.Windows.Input;
    using Microsoft.VisualStudio.TestTools.UITest.Extension;
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
    using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
    using MouseButtons = System.Windows.Forms.MouseButtons;
    using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;

    [GeneratedCode("Coded UITest Builder", "11.0.60315.1")]
    public partial class UIMap
    {

        /// <summary>
        /// RecordedMethod1
        /// </summary>
        public void RecordedMethod1()
        {
        #region Variable Declarations
        WinClient uIChromeLegacyWindowClient = this.UIJigsawBetaEnviromentWindow.UIChromeLegacyWindowWindow.UIChromeLegacyWindowClient;
        #endregion

        // Click 'Chrome Legacy Window' client
        Mouse.Click(uIChromeLegacyWindowClient, new Point(151, 25));

        // Click 'Chrome Legacy Window' client
        Mouse.Click(uIChromeLegacyWindowClient, new Point(150, 35));

        // Click 'Chrome Legacy Window' client
        Mouse.Click(uIChromeLegacyWindowClient, new Point(709, 90));
    }

    #region Properties
    public UIJigsawBetaEnviromentWindow UIJigsawBetaEnviromentWindow
    {
        get
        {
            if ((this.mUIJigsawBetaEnviromentWindow == null))
            {
                this.mUIJigsawBetaEnviromentWindow = new UIJigsawBetaEnviromentWindow();
            }
            return this.mUIJigsawBetaEnviromentWindow;
        }
    }
    #endregion

    #region Fields
    private UIJigsawBetaEnviromentWindow mUIJigsawBetaEnviromentWindow;
    #endregion
}

[GeneratedCode("Coded UITest Builder", "11.0.60315.1")]
public class UIJigsawBetaEnviromentWindow : WinWindow
{

    public UIJigsawBetaEnviromentWindow()
    {
        #region Search Criteria
        this.SearchProperties[WinWindow.PropertyNames.Name] = "Jigsaw [Beta Enviroment] - Google Chrome";
     //   this.SearchProperties[WinWindow.PropertyNames.Name] = "Jigsaw";
       this.SearchProperties[WinWindow.PropertyNames.ClassName] = "Chrome_WidgetWin_1";
       // this.SearchProperties[WinWindow.PropertyNames.ClassName] = "Chrome";
       this.WindowTitles.Add("Jigsaw [Beta Enviroment] - Google Chrome");
     //   this.WindowTitles.Add("Jigsaw");
        #endregion
    }

    #region Properties
    public UIChromeLegacyWindowWindow UIChromeLegacyWindowWindow
    {
        get
        {
            if ((this.mUIChromeLegacyWindowWindow == null))
            {
                this.mUIChromeLegacyWindowWindow = new UIChromeLegacyWindowWindow(this);
            }
            return this.mUIChromeLegacyWindowWindow;
        }
    }
    #endregion

    #region Fields
    private UIChromeLegacyWindowWindow mUIChromeLegacyWindowWindow;
    #endregion
}

[GeneratedCode("Coded UITest Builder", "11.0.60315.1")]
public class UIChromeLegacyWindowWindow : WinWindow
{

    public UIChromeLegacyWindowWindow(UITestControl searchLimitContainer) : 
            base(searchLimitContainer)
    {
        #region Search Criteria
        this.SearchProperties[WinWindow.PropertyNames.ControlId] = "144212160";
       this.WindowTitles.Add("Jigsaw [Beta Enviroment] - Google Chrome");
      //  this.WindowTitles.Add("Jigsaw");
        #endregion
    }

    #region Properties
    public WinClient UIChromeLegacyWindowClient
    {
        get
        {
            if ((this.mUIChromeLegacyWindowClient == null))
            {
                this.mUIChromeLegacyWindowClient = new WinClient(this);
                #region Search Criteria
               this.mUIChromeLegacyWindowClient.SearchProperties[WinControl.PropertyNames.Name] = "Chrome Legacy Window";
          //      this.mUIChromeLegacyWindowClient.SearchProperties[WinControl.PropertyNames.Name] = "Chrome";
                this.mUIChromeLegacyWindowClient.WindowTitles.Add("Jigsaw [Beta Enviroment] - Google Chrome");
            //    this.mUIChromeLegacyWindowClient.WindowTitles.Add("Jigsaw");
                #endregion
            }
            return this.mUIChromeLegacyWindowClient;
        }
    }
    #endregion

    #region Fields
    private WinClient mUIChromeLegacyWindowClient;
    #endregion
}

}

Microsoft CodedUI抛出错误,因为它无法看到“Chrome Legacy Window”

我运行了代码,但是我收到以下错误:

Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException was     unhandled by user code
  HResult=-268111872
  Message=The playback failed to find the control with the given search properties.     Additional Details: 
TechnologyName:  'MSAA'
ControlType:  'Client'
Name:  'Chrome Legacy Window'

  Source=Microsoft.VisualStudio.TestTools.UITesting
  BasicMessage=The playback failed to find the control with the given search     properties.
  RootElement=""
  StackTrace:
       at     Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException    (COMException ex, IPlaybackContext context)
       at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException        (COMException innerException, IPlaybackContext context)
       at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException    (SystemException exception, IPlaybackContext context)
       at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException    (SystemException exception, String queryId)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant    (String     queryId, Int32 maxDepth, Int32& timeLeft)
       at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean     useCache, ISearchArgument searchArg)
       at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search    (ISearchArgument searchArg)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindPrivate()
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<Find>b__d()
       at     Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1     function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean     logAsAction)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Find()
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyPrivate    (String     propertyName)
       at     Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass11.<GetProperty>b    __10()
       at     Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1     function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean     logAsAction)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String     propertyName)
       at     Microsoft.VisualStudio.TestTools.UITesting.ALUtility.GetTechElementFromUITestControl    (UITestControl uiTestControl)
       at     Microsoft.VisualStudio.TestTools.UITesting.ActionExecutorManager.GetActionExecutor    (UITestControl uiControl)
       at Microsoft.VisualStudio.TestTools.UITesting.Mouse.ClickImplementation    (UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point     relativeCoordinate)
       at     Microsoft.VisualStudio.TestTools.UITesting.Mouse.<>c__DisplayClass6.<Click>b__5()
       at     Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1     function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean     logAsAction)
       at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl     control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
       at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl     control, Point relativeCoordinate)
       at JigsawEMISTCodedUITestProject.UIMap.RecordedMethod1() in     d:\EMIS\JigsawEMISTCodedUITestProject\JigsawEMISTCodedUITestProject\UIMap.cs:line 42
       at JigsawEMISTCodedUITestProject.CodedUITest1.CodedUITestMethod1() in     d:\EMIS\JigsawEMISTCodedUITestProject\JigsawEMISTCodedUITestProject\CodedUITest1.cs:line 30
  InnerException: System.Runtime.InteropServices.COMException
       HResult=-2147467259
       Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
       Source=Microsoft.VisualStudio.TestTools.UITest.Playback
       ErrorCode=-2147467259
       StackTrace:
            at     Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants    (String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth)
            at     Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String     queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean     resetSkipStep)
            at     Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String     queryId, Int32 depth, Boolean resetSkipStep)
            at     Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String     queryId, Int32 depth)
            at     Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String     queryId, Int32 maxDepth, Int32& timeLeft)
       InnerException: 

我是否需要为流行的浏览器安装一些驱动程序(例如Google Chrome,Mozilla Firefox,IE等)? 我重新启动了我的开发计算机几次,但仍然有同样的问题。 请帮帮我。

1 个答案:

答案 0 :(得分:1)

实际上有一个Selenium框架被移植到Microsoft的开发人员使用Coded UI运行,您可以找到here,它将使用Selenium组件在Chrome或Firefox中运行测试。 IE由Coded UI本身处理,因此,如果您的BrowserWindow.BrowserType是&#34; IE&#34;,那么它只会运行随Visual Studio一起提供的vanilla Coded UI。

该页面的问答部分是您对工具本身问题的最大支持,但如果您无法入门,this blog非常有帮助。