This tutorial shows how to create an automated test using Microsoft Coded UI Test for an application containing an XtraGrid control.
Start Microsoft Visual Studio Ultimate or Premium with administrative permissions.
To create a new test project, do the following.
In Microsoft Visual Studio 2010, select the Test -> New Test menu command. Then select Coded UI Test in the invoked Add New Test dialog window.
In Microsoft Visual Studio 2012 and 2013, click New Project. Then select Test -> Coded UI Test Project in the Templates section of the New Project dialog.
After the test project is generated, select the first option in the Generate Code for Coded UI Test dialog and click OK.
When this dialog is closed, a Coded UI Test Builder is displayed, helping you record tests and create assertions.
Run the application on which you will be performing UI testing.
In the test, you will record changes to the grid control's cell value. Click the Record button in the Coded UI Test Builder, and after recording starts, modify the grid control's cell value. When finished, click the Pause button.
Click the Generate Code button in the Coded UI Test Builder to generate a test method. The generated method will be as follows.
public void RecordedMethod1()
#region Variable Declarations
DXTestControl uIGridControl1Table = this.UIXtraGridFeaturesDemoWindow.UIPanelControl1Client.UIGcContainerClient.UITableViewCustom.UIGridControl1Table;
DXTestControl uIGridControl1LookUpEdEdit = this.UIXtraGridFeaturesDemoWindow.UIPanelControl1Client.UIGcContainerClient.UITableViewCustom.UIGridControl1Table.UIGridControl1LookUpEdEdit;
// Type 'SetFocusedCell [View]gridView1[Row]1[Column]gridColumn2' in the 'gridControl1' table
uIGridControl1Table.Focus = this.RecordedMethod1Params.UIGridControl1TableFocus;
// Type 'System.Int32' in the 'gridControl1LookUpEdit[View]gridView1[Row]1[Column]gridColumn2' text box
uIGridControl1LookUpEdEdit.ValueType = this.RecordedMethod1Params.UIGridControl1LookUpEdEditValueType;
// Type '33 AutoSearchText0' in the 'gridControl1LookUpEdit[View]gridView1[Row]1[Column]gridColumn2' text box
uIGridControl1LookUpEdEdit.EditValue = this.RecordedMethod1Params.UIGridControl1LookUpEdEditEditValue;
As you can see, recorded actions are aggregated into corresponding method calls. The first statement below the #region block focuses the cell that belongs to the second row and second column. If you check the RecordedMethod1Params.UIGridControl1TableFocus variable, it will be defined as follows.
public string UIGridControl1TableFocus = "SetFocusedCell [View]gridView1[Row]1[Column]gridColumn2";
The other two statements in the RecordedMethod1 method change the in-place editor's value.
Next, you will create an assertion that will check the modified cell's value. To create an assertion, click the crosshair button in the Coded UI Test Builder and drag it to the modified cell. After releasing the mouse button, an Add Assertions window is displayed, allowing you to add assertions. In the following video, two assertions are added for the in-place editor's Text and EditValue properties.
Click the Generate Code button in the Coded UI Test Builder to generate an assertion method.