这是我正在使用的代码。但不幸的是它没有按预期运行。有人可以帮我解决这个问题吗?
这是编码ui测试。我想在Windows 10上自动化计算器,这是不允许我这样做的。即时通讯使用visual studio 2015和我的窗口是10.我正在通过转到新的>新项目> test>编码的ui测试模板来创建一个编码ui的新项目。
public class CodedUITest1
{
public CodedUITest1()
{
}
[TestMethod]
public void CodedUITestMethod1()
{
string ApplicationPath = "C:\\Windows\\System32\\calc.exe";
//ApplicationUnderTest application = ApplicationUnderTest.Launch(ApplicationPath);
System.Diagnostics.Process.Start(ApplicationPath);
WinWindow maW = new WinWindow();
maW.SearchProperties.Add(UITestControl.PropertyNames.Name, "Calculator");
maW.WindowTitles.Add("Calculator");
WinButton btnSeven = new WinButton(maW);
btnSeven.SearchProperties.Add(UITestControl.PropertyNames.Name, "7");
btnSeven.WindowTitles.Add("Calculator");
Mouse.Click(btnSeven);
WinButton btnPlus = new WinButton(maW);
btnPlus.SearchProperties.Add(UITestControl.PropertyNames.Name, "Add");
btnPlus.WindowTitles.Add("Calculator");
Mouse.Click(btnPlus);
WinButton btnThree = new WinButton(maW);
btnThree.SearchProperties.Add(UITestControl.PropertyNames.Name, "3");
btnThree.WindowTitles.Add("Calculator");
Mouse.Click(btnThree);
WinButton btnEquals = new WinButton(maW);
btnEquals.SearchProperties.Add(UITestControl.PropertyNames.Name, "Equals");
btnEquals.WindowTitles.Add("Calculator");
Mouse.Click(btnEquals);
WinText txtResult = new WinText(maW);
txtResult.SearchProperties.Add(UITestControl.PropertyNames.Name, "Result");
txtResult.WindowTitles.Add("Calculator");
Assert.AreEqual("10", txtResult.DisplayText);
Playback.Wait(1000);
}
#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.
//}
////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.
//}
#endregion
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
private TestContext testContextInstance;
}
}