基于ui automation的计算器测试例子
来源:互联网 发布:vb文本框内容不可编辑 编辑:程序博客网 时间:2024/06/05 16:00
基于ui automation的计算器测试程序
using System;
using System.Text;using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows;
using System.Windows.Automation;
using System.Diagnostics;
namespace TestProject2
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
//Process p = Process.Start(@"E:\Project\WinFormTest\WinFormTest\bin\Debug\WinFormTest.exe");
var desktop = AutomationElement.RootElement; // 先找到根元素,可以认为是桌面
var condition = new PropertyCondition(AutomationElement.NameProperty, "计算器"); // 定义我们的查找条件,名字是test
var window = desktop.FindFirst(TreeScope.Children, condition); // 在桌面的子控件中查找第一个符合条件的窗体。
// AutomationElement btnpane = window.FindFirst(TreeScope.Children,
// new PropertyCondition(AutomationElement.ClassNameProperty, "CalcFrame"));
AutomationElement btn9 = window.FindFirst(TreeScope.Children,
// new PropertyCondition(AutomationElement.NameProperty, "9"));
new PropertyCondition(AutomationElement.AutomationIdProperty, "133"));
AutomationElement btnPlus = window.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "+"));
AutomationElement btn3 = window.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "3"));
AutomationElement btnEq = window.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "="));
List<AutomationElement> ele_list = new List<AutomationElement>();
ele_list.Add(btn9);
ele_list.Add(btnPlus);
ele_list.Add(btn3);
ele_list.Add(btnEq);
InvokePattern invokeptn = null;
foreach (AutomationElement elem in ele_list)
{
invokeptn = (InvokePattern)elem.GetCurrentPattern(InvokePattern.Pattern);
invokeptn.Invoke();
}
AutomationElement result = window.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.AutomationIdProperty, "403"));
if (result.Equals(12))
{
int t1 = 9;
}
else {
int t2 = 7;
}
//通过ValuePattern设置或者获得TextBox1的值
//ValuePattern vpTextBox1 = (ValuePattern)result.GetCurrentPattern(ValuePattern.Pattern);
//vpTextBox1.SetValue("50");
TextPattern tpTextBox3 = (TextPattern)result.GetCurrentPattern(TextPattern.Pattern);
string results = tpTextBox3.DocumentRange.GetText(-1); //获取textbox3中的值
//AutomationEventHandler eventHandler = new AutomationEventHandler(autoClient.onWindowOpenOrClose);
//Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Children, eventHandler);
/*
Condition conditions = new AndCondition(new PropertyCondition(AutomationElement.AutomationIdProperty, resultTextAutoId),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));
AutomationElement btn = window.FindAll(TreeScope.Descendants, conditions)[0];
InvokePattern invokeptn = (InvokePattern)btn.GetCurrentPattern(InvokePattern.Pattern);
invokeptn.Invoke();
var btnCondition = new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button),
new PropertyCondition(AutomationElement.NameProperty, "ok"));
var button = window.FindFirst(TreeScope.Children, btnCondition);
var clickPattern = (InvokePattern)button.GetCurrentPattern(InvokePattern.Pattern);
clickPattern.Invoke();
*/
}
}
}
最后添加引用UIAutomationClientsideProviders.dll,UIAutomationTypes.dll,UIAutomationClient.dll三个dll的引用即可
0 0
- 基于ui automation的计算器测试例子
- 基于UI Automation的自动化测试框架
- 基于UI Automation的自动化测试框架
- 基于UI Automation的自动化测试工具设计指南
- 基于instruments-Automation的iOS应用UI自动化测试图文攻略
- 基于instruments-Automation的iOS应用UI自动化测试图文攻略(学习)
- 基于instruments-Automation的iOS应用UI自动化测试图文攻略
- 基于UI写的简单的计算器
- net自动化测试之道基于反射的UI自动化测试—例子程序:ReflectionUITest
- 使用UI Automation实现自动化测试 -1
- 使用UI Automation实现自动化测试 -2
- 使用UI Automation实现自动化测试 -3
- 使用UI Automation实现自动化测试 -4.1
- 使用 UI Automation 实现自动化测试--1
- 使用 UI Automation 实现自动化测试--2
- 使用 UI Automation 实现自动化测试--3
- 使用 UI Automation 实现自动化测试--4.1
- 使用 UI Automation 实现自动化测试--4.2
- 用户空间的spi驱动 .
- 最新【snapshot】DCMTK3.6.1(MD支持库)安装说明
- 對二维数组的探討
- 基于Linux下的UDP编程
- OpenCV Mat数据类型及位数总结
- 基于ui automation的计算器测试例子
- ICCV 2013
- 修改linux文件句柄数
- Linux C编程---网络编程
- 【python系列】列表list的操作讲解
- Unity3D面试题汇总
- Prim算法和Kruskal算法
- PHP的高级OOP技术(1) ,现的一年,第一篇记录
- __asm__ __volatile__