我是 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;
}
}