UI Automation-ExpandCollapsePattern
来源:互联网 发布:notepad 排版json 编辑:程序博客网 时间:2024/05/23 16:55
ExpandCollapsePattern是可以进行展开(以显示内容)和折叠(以隐藏内容)的控件。例如ComboBox控件支持ExpandCollapsePattern。
ExpandCollapsePattern有两个主要方法:
Expand()方法和Collapse()方法。可以把Expand和Collpase再封装。示例如下:
public static void launchCal()
{
//Launch Calculator
Process proc = Process.Start("calc");
Thread.Sleep(2000);
//Recognize Calculator Window "Calculator"
AutomationElement window = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Calculator"));
//Assert.IsNotNull(window);
Thread.Sleep(2000);
//Expand view button
//Recognize view menu
AutomationElement view = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "View"));
Assert.IsNotNull(view);
Thread.Sleep(2000);
Utility.UIA.ControlPattern.ExpandCollapsepattern.Expand(view);
Thread.Sleep(2000);
//Recognize menu item Worksheets
AutomationElement worksheets = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Worksheets"));
Assert.IsNotNull(worksheets);
Utility.UIA.ControlPattern.ExpandCollapsepattern.ExpandCollapseMenuItem(worksheets);
Thread.Sleep(2000);
}
public static void Expand(AutomationElement targetControl)
{
ExpandCollapsePattern expandCollapsePattern = null;
try
{
expandCollapsePattern =
targetControl.GetCurrentPattern(
ExpandCollapsePattern.Pattern)
as ExpandCollapsePattern;
}
// Object doesn't support the ExpandCollapsePattern control pattern.
catch (InvalidOperationException)
{
throw new InvalidOperationException(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the ExpandCollapsePattern control pattern ",
targetControl.Current.AutomationId, targetControl.Current.Name));
}
expandCollapsePattern.Expand();
}
public static void Collapse(AutomationElement targetControl)
{
ExpandCollapsePattern expandCollapsePattern = null;
try
{
expandCollapsePattern =
targetControl.GetCurrentPattern(
ExpandCollapsePattern.Pattern)
as ExpandCollapsePattern;
}
// Object doesn't support the ExpandCollapsePattern control pattern.
catch (InvalidOperationException)
{
throw new InvalidOperationException(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the ExpandCollapsePattern control pattern ",
targetControl.Current.AutomationId, targetControl.Current.Name));
}
expandCollapsePattern.Collapse();
}
public static ExpandCollapsePattern GetExpandCollapsePattern(
AutomationElement targetControl)
{
ExpandCollapsePattern expandCollapsePattern = null;
try
{
expandCollapsePattern =
targetControl.GetCurrentPattern(
ExpandCollapsePattern.Pattern)
as ExpandCollapsePattern;
}
// Object doesn't support the ExpandCollapsePattern control pattern.
catch (InvalidOperationException)
{
return null;
}
return expandCollapsePattern;
}
- UI Automation-ExpandCollapsePattern
- UI Automation-ExpandCollapsePattern
- 使用UI Automation实现自动化测试--4.2 (ExpandCollapsePattern)
- UI Automation
- UI Automation Introduction.
- UI Automation(一)
- UI Automation-InvokePattern
- UI Automation-ValuePattern
- UI Automation-SelectItemPattern
- UI Automation test
- UI Automation-ScrollPattern
- UI Automation-TogglePattern
- UI automation - .net
- UI Automation-WindowPattern
- UI Automation-GridPattern
- UI Automation-TablePattern
- UI Automation-RangeValuePattern
- UI Automation-TransformPattern
- 【记】:上周团队面试应届生
- 技术日志_5 some notes
- day1
- org.apache.jasper.JasperException: /login.jsp(2,0) Unable to read TLD "META-INF/c.tld" from JAR file 、、、、、、
- 技术日志_4 some notes
- UI Automation-ExpandCollapsePattern
- OpenJTAG与JLink的区别比较
- SQL加入Joomla用户 【转】
- Linq实现string排序
- 角色--成组管理用户的方法
- 在CI中使用自己的辅助函数
- Project Euler - Problem 21
- 一个员工辞职,均衡被打破了!
- 矩阵乘法 C#