HOW TO CLICK IN HYPERLINKS WITHOUT RECORDING ACTIONS

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

In the next method is shown how to click on a hyperlink:

private static Dictionary objDict = UiTestHtmlHyperlinkDict.UiTestHtmlHyperlink();

public static void MouseClickInHyperlink(string dictKey)
{
	Mouse.Click(objDict[dictKey]);
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls

HOW TO CLICK IN BUTTONS WITHOUT RECORDING ACTIONS

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

In the next class is shown a method to click in buttons such as ok, cancel, confirm, exit….

public static WinButton WinButton;

private static Dictionary<string, WinButton> objDict = UiTestWinButtonDict.UiTestWinButton();

public static void DoubleClickInButton(string tableKey)
{
	WinButton winButton = objDict[tableKey];
	if (winButton.WaitForControlReady(2000))
	{
		Mouse.DoubleClick(winButton);
	}
	else
	{
		Assert.Fail("The button is not ready or does not exist.");
	}
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls

HOW TO SET VALUES IN WINEDIT BOXES

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

In the next class is shown a method to set data in a box using SetProperty():

private static Dictionary<string, WinEdit> objDict = UiTestWinEditDict.UiTestWinEdit();

public static void SetValueInWinEdit(string textComments, string tableKey)
{
	WinEdit winEdit = objDict[tableKey];
	if (winEdit.WaitForControlEnabled(2000))
	{
		winEdit.SetProperty("Text", textComments);
	}
	else
	{
		Assert.Fail("The next value cannot be written in the box: " + textComments);
	}
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls

HOW TO CLICK IN CELL ELEMENTS FROM A PARENT GRID

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

Therefore, the best option is to get Coded UI controls from the parent control and to get from it all the children items using the Add a new control to the UIMap tool (see https://automatedtestingtools.wordpress.com/2016/04/11/how-to-capture-ui-control-with-coded-ui-test-builder-without-recording-actions).

In the next example a table grid is presented with two columns.  The strategy to follow is to get only the squared UI Control and from it get both all the cells of the grid.

tablegrid

A method to click in any cell of the grid from the parent element is shown in the next class. The key point is to use first GetCell():

private static Dictionary<string, WinTable> objDict = UiTestTableGridDict.UiTestGridTables();

public static void ClickInCellElement(int row, int colum, string dictKey)
{
	WinTable table = objDict[dictKey];
	UITestControl children = table.GetCell(row, colum);
	if (!children.Enabled)
	{
		Assert.Fail("The cell element is not enabled or does not exist.");
	}
	else
	{
		Mouse.Click(children);
	}
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls

How to get combo box items from the parent element

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

Therefore, the best option is to get Coded UI controls from the parent control and to get from it all the children items using  the Add a new control to the UIMap tool (see https://automatedtestingtools.wordpress.com/2016/04/11/how-to-capture-ui-control-with-coded-ui-test-builder-without-recording-actions).

In the next example a combo box is presented with a list of countries.  The strategy to follow is to get only the red squared UI Control and from it get both all the countries items of the list.

combobox

A method to click in any list item of a combo box (for example Germany) from the parent element is shown in the next class. The key point is to use first Items.ToList():

public static WinComboBox ComboBox;

public static List GetElementsFromComboBox;

private static Dictionary objDict = UiTestComboBoxDict.UiTestComboBox();

public static void MouseClickInComboBoxElement(string nameComboBoxElement, string dictKey)
{
	ComboBox = objDict[dictKey];
	UITestControl elemeUiTestControl =
		ComboBox.Items.ToList().FirstOrDefault(element => element.Name == nameComboBoxElement);

	if (elemeUiTestControl != null)
	{
		Mouse.Click(ComboBox);
		Mouse.Click(elemeUiTestControl);
	}
	else
	{
		Assert.Fail("The next combobox element does  not exist: " + nameComboBoxElement);
	}
}

As it is shown in the previous code the UI Control of the combo box parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls