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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章