white学习5(官方网站的内容)
2011-04-26 14:01
295 查看
Checkout ControlTypeToUIItemMapping in order to find the mapping between white types and UI Automation types.
List View
In order to select multiple rows in ListView use MultiSelect method.
listView.Rows[0].Select();
listView.Rows[1].MultiSelect(); //This would keep the 0th row selected as well
ListBox
listBox.Check("item1"); // in checked listBox, to check the item
listBox.UnCheck("item1");
ListItems items = listBox.Items; // get all the items
listBox.Select("item1"); // select an item
ListItem listItem = listBox.SelectedItem; // get a selected item
ComboBox
comboBox.Select("Arundhati Roy");
ListItem listItem = comboBox.SelectedItem;
Tree
Tree consists of TreeNodes. Each of the TreeNode object can contain further TreeNodes.
In order to select a TreeNode first find the node and call select method on it.
TreeNode treeNode = tree.Node("Root", "Child1");
treeNode.Select(); //Just selects the node without expanding it. Depending on your application logic this might also expand and collapse the node.
treeNode.Expand(); //Expand the node and display child nodes belonging to this node.
treeNode.Collapse(); //Collapse this node
treeNode.IsExpanded; //Return the state expansion state
DateTimePicker
Currently it supports only Date and not the time. Since there is no native support for DateTimePicker in UIAutomation for setting the value, White uses keyboard to set the value. When the value is set it enters the value, without opening the calendar. Hence it is important for it to know the DateFormat.
There are two ways to set the date.
DateTimePicker dateTimePicker = window.Get<DateTimePicker>("dob");
dateTimePicker.Date = DateTime.Now.AddMonth(1);
In this case DateTimePicker would use the configured DateFormat (in case no explicit configuration it uses default format based on the current culture).
DateTimePicker dateTimePicker = window.Get<DateTimePicker>("dob");
dateTimePicker.SetDate(DateTime.Now.AddMonth(1), DateFormat.YearDayMonth);
These are possible DateFormats:
DayMonthYear, DayYearMonth, MonthDayYear, MonthYearDay, YearMonthDay and YearDayMonth
Configuring DateFormat
You need to set the DefaultDateFormat property in the configuration file under section Core. The possible values are:
"DayMonthYear", "DayYearMonth", "MonthDayYear", "MonthYearDay", "YearMonthDay" and "YearDayMonth"
WPF Items
WPF allows the UI developer to compose controls of dynamic types. Since the control structure is not predictable in WPF, white's UIItem structure allows one to do the same while testing.
e.g. If ListItem has a text box
// other imports
using White.Core.UIItems.WPFUIItems; //add this using allows one use Get and GetMultiple methods on any UIItem
namespace White.Core.UIItems.ListBoxItems
{
[TestFixture]
public class WPFListBoxTest
{
[Test]
public void ListItemContainingTextbox()
{
// code to get the window object
var listBox = window.Get<ListBox>("listBox");
var listItem = (WPFListItem) listBox.Items.Find(item => "Foo".Equals(item.Text));
var textBox = listItem.Get<TextBox>(SearchCriteria.All);
}
}
}
Thumb
Used to control the splitter control, which can be slid by dragging the mouse.
Thumb thumb = window.Get<Thumb>("splitter");
thumb.SlideHorizontally(10); //move the splitter 10 pixels to the right
thumb.SlideHorizontally(-15); //move the splitter 15 pixels to the left
// in case of vertical splitter
thumb.SlideVertically(10); //move the splitter 10 pixels down
thumb. SlideVertically(-15); //move the splitter 15 pixels up
GroupBox/Panel
Since GroupBox and Panel extend from UIItemContainer one can retrieve items from within groupbox or panel using:
GroupBox groundBox = window.Get<GroupBox>("groupBox1");
Button button = groupBox.Get<Button>("button1"); //provides button which is inside the group box
groupBox.Get<Button>(SearchCriteria.ByText("OK")); //other search techniques available on window are also available here.
ToolBar/ToolStrip
ToolStrip toolStrip = window.Get< ToolStrip >("toolStrip1");
WPF Expander Control
// other imports
using White.Core.UIItems.WPFUIItems; //add this using allows one use Get and GetMultiple methods on any UIItem
namespace White.Core.UIItems.ListBoxItems
{
[TestFixture]
public class UseExpanderControlTest
{
[Test]
public void Sample()
{
// code to get the window object
var expander = window.Get<GroupBox>("expander1"); //Expander control is really a GroupBox
var buttonToExpand = expander.Get<Button>("expanderButton1");
buttonToExpand.Click();
}
}
}
It is recommended you create an abstraction for your expander. Since its structure is not a standard, white cannot provide the same.
List View
In order to select multiple rows in ListView use MultiSelect method.
listView.Rows[0].Select();
listView.Rows[1].MultiSelect(); //This would keep the 0th row selected as well
ListBox
listBox.Check("item1"); // in checked listBox, to check the item
listBox.UnCheck("item1");
ListItems items = listBox.Items; // get all the items
listBox.Select("item1"); // select an item
ListItem listItem = listBox.SelectedItem; // get a selected item
ComboBox
comboBox.Select("Arundhati Roy");
ListItem listItem = comboBox.SelectedItem;
Tree
Tree consists of TreeNodes. Each of the TreeNode object can contain further TreeNodes.
In order to select a TreeNode first find the node and call select method on it.
TreeNode treeNode = tree.Node("Root", "Child1");
treeNode.Select(); //Just selects the node without expanding it. Depending on your application logic this might also expand and collapse the node.
treeNode.Expand(); //Expand the node and display child nodes belonging to this node.
treeNode.Collapse(); //Collapse this node
treeNode.IsExpanded; //Return the state expansion state
DateTimePicker
Currently it supports only Date and not the time. Since there is no native support for DateTimePicker in UIAutomation for setting the value, White uses keyboard to set the value. When the value is set it enters the value, without opening the calendar. Hence it is important for it to know the DateFormat.
There are two ways to set the date.
DateTimePicker dateTimePicker = window.Get<DateTimePicker>("dob");
dateTimePicker.Date = DateTime.Now.AddMonth(1);
In this case DateTimePicker would use the configured DateFormat (in case no explicit configuration it uses default format based on the current culture).
DateTimePicker dateTimePicker = window.Get<DateTimePicker>("dob");
dateTimePicker.SetDate(DateTime.Now.AddMonth(1), DateFormat.YearDayMonth);
These are possible DateFormats:
DayMonthYear, DayYearMonth, MonthDayYear, MonthYearDay, YearMonthDay and YearDayMonth
Configuring DateFormat
You need to set the DefaultDateFormat property in the configuration file under section Core. The possible values are:
"DayMonthYear", "DayYearMonth", "MonthDayYear", "MonthYearDay", "YearMonthDay" and "YearDayMonth"
WPF Items
WPF allows the UI developer to compose controls of dynamic types. Since the control structure is not predictable in WPF, white's UIItem structure allows one to do the same while testing.
e.g. If ListItem has a text box
// other imports
using White.Core.UIItems.WPFUIItems; //add this using allows one use Get and GetMultiple methods on any UIItem
namespace White.Core.UIItems.ListBoxItems
{
[TestFixture]
public class WPFListBoxTest
{
[Test]
public void ListItemContainingTextbox()
{
// code to get the window object
var listBox = window.Get<ListBox>("listBox");
var listItem = (WPFListItem) listBox.Items.Find(item => "Foo".Equals(item.Text));
var textBox = listItem.Get<TextBox>(SearchCriteria.All);
}
}
}
Thumb
Used to control the splitter control, which can be slid by dragging the mouse.
Thumb thumb = window.Get<Thumb>("splitter");
thumb.SlideHorizontally(10); //move the splitter 10 pixels to the right
thumb.SlideHorizontally(-15); //move the splitter 15 pixels to the left
// in case of vertical splitter
thumb.SlideVertically(10); //move the splitter 10 pixels down
thumb. SlideVertically(-15); //move the splitter 15 pixels up
GroupBox/Panel
Since GroupBox and Panel extend from UIItemContainer one can retrieve items from within groupbox or panel using:
GroupBox groundBox = window.Get<GroupBox>("groupBox1");
Button button = groupBox.Get<Button>("button1"); //provides button which is inside the group box
groupBox.Get<Button>(SearchCriteria.ByText("OK")); //other search techniques available on window are also available here.
ToolBar/ToolStrip
ToolStrip toolStrip = window.Get< ToolStrip >("toolStrip1");
WPF Expander Control
// other imports
using White.Core.UIItems.WPFUIItems; //add this using allows one use Get and GetMultiple methods on any UIItem
namespace White.Core.UIItems.ListBoxItems
{
[TestFixture]
public class UseExpanderControlTest
{
[Test]
public void Sample()
{
// code to get the window object
var expander = window.Get<GroupBox>("expander1"); //Expander control is really a GroupBox
var buttonToExpand = expander.Get<Button>("expanderButton1");
buttonToExpand.Click();
}
}
}
It is recommended you create an abstraction for your expander. Since its structure is not a standard, white cannot provide the same.
相关文章推荐
- white学习14(官方网站的内容)
- white学习2(官方网站的内容)
- white学习15(官方网站的内容)
- white学习3(官方网站的内容)
- white学习4(官方网站的内容)
- white学习6(官方网站的内容)
- white学习7(官方网站的内容)
- white学习8(官方网站的内容)
- white学习9(官方网站的内容)
- white学习16(官方网站的内容)
- white学习10(官方网站的内容)
- white学习10(官方网站的内容)
- white学习13(官方网站的内容),介绍White.NUnit
- white学习12(官方网站的内容),介绍一个捕获元素工具UISpy
- 参考TinyOS官方网站学习建立新platform-yamp
- TensorFlow 中文资源精选,官方网站,安装教程,入门教程,实战项目,学习路径
- [Groovy] 学习Groovy的好网站(内容全面)
- 廖雪峰官方网站python学习笔记:第一个Pyhon程序
- 参考TinyOS官方网站学习基于printf库的打印调试
- 学习笔记 - EasyUI官方网站演示