UIAutomation 测试winForm

2020-12-13 05:26

阅读:364

标签:des   winform   blog   http   os   io   2014   for   

soscw.com,搜素材

 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();
        }

 MS提供的控件Pattern
 
DockPattern                              
ExpandCollapsePattern

GridPattern                                 
GridItemPattern

InvokePattern                             
MultipleViewPattern

RangeValuePattern 

ScrollPattern
ScrollItemPattern

SelectionPattern

SelectionItemPattern                 

TablePattern
TableItemPattern                       

TextPattern
TogglePattern                           

TransformPattern
ValuePattern

WindowPattern

UIAutomation 测试winForm,搜素材,soscw.com

UIAutomation 测试winForm

标签:des   winform   blog   http   os   io   2014   for   

原文地址:http://www.cnblogs.com/changshuo/p/3869205.html


评论


亲,登录后才可以留言!