2

我是 codedUI 的新手,一开始我正在阅读很多关于什么应该是最佳实践的内容。我已经读过,如果您使用的是复杂的应用程序,建议您使用多个 UImap。虽然目前我看不到任何好处,但我已经用两个 UImaps 创建了一个小项目。

在第一个初始设置中(使用初始 UImap 和 CodedUITest1),我可以选择是使用测试构建器还是现有的操作记录来生成代码。我所做的一切都会“进入”初始 UImap。当我创建新的 UI 时,测试生成器会启动,我可以记录一些操作,当我保存它时,它会添加到新创建的 UImap 中,在我的案例中称为 AdvanceSettings。但我无法从现有录音中生成代码。这是为什么?我想根据带有记录的手动测试用例创建自动化测试用例。

下面是我的代码。我对两个 UImap 都使用 CodedUITest1 类。我应该为每个 UImap 使用新类吗?

如果您对代码有一些评论,请写一些。

照我看来。如果您有复杂的应用程序,则使用多个 UImap,以便您可以更轻松地更改某些内容。每个 GUI 元素都有一个 UImap,因此如果该 GUI 上的某些内容发生变化,您只需编辑该 UImap。但是,如果您有一个 UImap 并且使用正确的命名,您也可以轻松替换或重新录制某些方法。所以我错过了具有多个 UImap 的大图。

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using EAEP.AdvanceSettingsClasses;

namespace EAEP
{
    /// <summary>
    /// Summary description for CodedUITest1
    /// </summary>
    [CodedUITest]
    public class CodedUITest1
    {
        public CodedUITest1()
        {
        }

        [TestInitialize]
        public void InitializationForTest()
        {

            this.UIMap.AppLaunch();

        }

        [TestMethod]
        public void MainGUIMethod()
        {
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463

            this.UIMap.AssertMethod1();
            this.UIMap.RestoreDefaults();
            this.UIMap.AssertMethod1();

            }

        [TestMethod]
        public void AdvanceSettignsWindowMethod()
        {

            AdvanceSettings advanceSettings = new AdvanceSettings();

            advanceSettings.MoreSettingsReopenedAfterCancel();
            this.UIMap.AssertVerificationAfterCancel();
            advanceSettings.MoreSettingsReopenedAfterOK();
            this.UIMap.AssertVerificationAfterOK();

        }

        #region Additional test attributes

        // You can use the following additional attributes as you write your tests:

        ////Use TestInitialize to run code before running each test 
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        //}

        ////Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        //}

        #endregion


        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        private TestContext testContextInstance;

        public UIMap UIMap
        {
            get
            {
                if ((this.map == null))
                {
                    this.map = new UIMap();
                }

                return this.map;
            }
        }

        private UIMap map;
    }
}
4

2 回答 2

0
  1. 拥有多个 UIMap 可以加快测试执行速度。此外,这使版本、断言、属性和设置变得更加容易。

  2. 要为第二个 UIMap 创建测试,您只需右键单击它并按“使用编码的 UI 测试生成器编辑”

关于But I can not generate code from existing recording. Why is that?我不知道 - 你是什么意思can not

于 2012-11-08T13:26:53.680 回答
0

您不能使用来自现有录制功能的多个 UI 地图。此功能始终在名为 UIMap 的地图中生成代码。我在一篇关于将 specflow 与 Coded Ui 测试集成的博客文章中解释了一些关于这些限制的内容

http://rburnham.wordpress.com/2011/05/30/record-your-coded-ui-test-methods/

如果您想使用 Multiple UIMaps 以获得更好的可维护性,您必须使用此方法

  1. 通过右键单击 UIMap 并选择 Coded UI Test Builder 分别记录每个操作。
  2. 通过创建一个空白的编码 UI 测试手动将测试连接到操作,更新它引用的 UIMap,然后在测试方法中调用所需的操作来执行测试。

它是一个限制,使 MTM 集成的优点变得毫无意义。

于 2012-11-09T06:51:15.827 回答