UIAutomation 测试winForm
2020-12-13 05:26
标签:des winform blog http os io 2014 for MS提供的控件Pattern ScrollPattern SelectionPattern SelectionItemPattern TablePattern TextPattern TransformPattern WindowPattern UIAutomation 测试winForm,搜素材,soscw.com UIAutomation 测试winForm 标签:des winform blog http os io 2014 for 原文地址:http://www.cnblogs.com/changshuo/p/3869205.html static void Main(string[] args)
{
Console.WriteLine("\n开始窗口程序自动化测试\n");
//启动被测试程序
string path = @"程序路径";
Process p = Process.Start(path);
//自动化跟元素
AutomationElement desktop = AutomationElement.RootElement;
//查找主窗体方法1
//Thread.Sleep(2000);
//AutomationElement aeForm = AutomationElement.FromHandle(p.MainWindowHandle);
AutomationElement aeForm;
//方法2
int numWaits = 0;
do
{
Console.WriteLine("等待测试窗口……");
//查找第一个自动化元素
aeForm = desktop.FindFirst(TreeScope.Children, new PropertyCondition(
AutomationElement.NameProperty, "Form1"));
++numWaits;
Thread.Sleep(100);
} while (null == aeForm && numWaits =返回结果的长度,才可以取全值.方便起见-1也可以取全值
string expect = "800";
if (actual == expect)
{
Console.WriteLine("【实际值】=" + actual);
}
else {
Console.WriteLine("【实际值】="+actual+";【期望值】"+expect);
}
Thread.Sleep(5000);
WindowPattern wpCloseForm = (WindowPattern)aeForm.GetCurrentPattern(WindowPattern.Pattern);
wpCloseForm.Close();
Console.WriteLine("\n测试结束\n");
Console.ReadKey();
}
DockPattern
ExpandCollapsePattern
GridPattern
GridItemPattern
InvokePattern
MultipleViewPattern
RangeValuePattern
ScrollItemPattern
TableItemPattern
TogglePattern
ValuePattern
上一篇:一天不学java,浑身难受!
下一篇:PHP中生成验证码