.net框架下实现自动化测试的三种方法

来源:互联网 发布:淘宝拍衣服的要求 编辑:程序博客网 时间:2024/05/17 08:02

基于反射的UI测试 

参考《.NET 软件测试自动化之道》作者:(美)麦克卡佛瑞 著,刘晓伟 译

UIAutomation技术

           //找到名称为 VNC Viewer : Connection Details 的窗体          
            var desktop = AutomationElement.RootElement;//得到桌面          
            //创建一个搜索条件,条件标明使用name属性,值为我们需要找的窗体名称。           
            var condition = new PropertyCondition(AutomationElement.NameProperty, "VNC Viewer : Connection Details");
            //查找符合条件的第一个窗体.           
            var window = desktop.FindFirst(TreeScope.Children, condition);
            //在需要的窗体上查找到options按钮并执行点击         
            var btncondition = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Options..."));
            //找按钮           
            var buttonoption = window.FindFirst(TreeScope.Children, btncondition);
            //获取按钮可操作事件           
            var clickPattern = (InvokePattern)buttonoption.GetCurrentPattern(InvokePattern.Pattern);
            //执行事件           
            clickPattern.Invoke();
            //GOOD,上面的代码都很顺利的执行,接下来我们继续实现向文本框内输入结果           
            //使用同样的方法先找到文本框           
            var txtcondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit);
            //Descendants 这里注意,因为现在文本框不是窗口的直接子级,因此不可以直接使用Children.       
            var txtbox = window.FindFirst(TreeScope.Descendants, txtcondition);
            var editPatten = (ValuePattern)txtbox.GetCurrentPattern(ValuePattern.Pattern);
            editPatten.SetValue("192.168.2.200");

UITest技术

参考:http://www.huiyaosoft.com/html/codeuitest.htm  


0 0
原创粉丝点击