white学习5(官方网站的内容)

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值