Несколько улучшений были внесены в API закодированных тестов ИП для упрощения проверки сложных элементов управления, таких как деревья, таблицы, списки и группы элементов управления.
Проверка групп элементов управления
Один вызов GetNamesOfControls или GetValuesOfControls будет возвращать список массива имен и значений элементов управления, соответственно, это позволяет нам проверить имена и значения целой группы элементов управления с помощью нескольких строк кода.
GetNamesOfControls
//Validate all of the names of the edit controls on a page BrowserWindow win = BrowserWindow.Launch(new Uri(«http://www.SiteUnderTest.com«)); … UITestControl doc = win.CurrentDocumentWindow; HtmlControl control = new HtmlControl(doc); control.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, «HtmlEdit«); UITestControlCollection controlcollection = control.FindMatchingControls(); string[] expectedNames = { «txtUserId«, «txtPassword«, «btnOk» }; string[] actualNames = testCollection.GetNamesOfControls(); for (int index = 0; index < expectedNames.Length; index++) { Assert.AreEqual(expectedNames[index], actualNames[index]); }
GetValuesOfControls
//Validate all of the values of the edit controls on a page BrowserWindow win = BrowserWindow.Launch(new Uri(«http://www.SiteUnderTest.com«)); … UITestControl doc = win.CurrentDocumentWindow; HtmlControl control = new HtmlControl(doc); control.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, «HtmlEdit«); string[] expectedValues = { «Some User«, «Secret Password«, «Ok» }; string[] actualValues = testCollection.GetValuesOfControls(); for (int index = 0; index < expectedValues.Length; index++) { Assert.AreEqual(expectedValues[index], actualValues[index]); }
Аналогично если у вас есть UITestControllCollection и вы хотите оценить конкретное свойство всех этих элементов управления, вы можете использовать метод GetPropertyValuesOfControls.
GetPropertyValuesOfControls
//Validate the checked property of all of the checkbox controls on a page BrowserWindow win = BrowserWindow.Launch(new Uri(«http://www.SiteUnderTest.com«)); … UITestControl doc = win.CurrentDocumentWindow; HtmlControl control = new HtmlControl(doc); control.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, «HtmlCheckBox«); bool[] expectedCheckedValues = { true, true, false }; bool[] actualCheckedValues = testCollection.GetPropertyValuesOfControls<bool> HtmlCheckbox.PropertyNames.Checked); for (int index = 0; index < actualCheckedValues.Length; index++) { Assert.AreEqual(expectedCheckedValues [index], actualCheckedValues [index]); }
Проверка гридов / таблицы (WPF, Win Forms, HTML)
Проверка грида или таблицы в прошлом было проблемой, сейчас добавлены GetCell, GetRow, GetContent, GetColumnValues, GetColumnNames, FindFirstCellWithValue, чтобы помочь решить эту задачу.
Предположим, что мы тестируем приложение Windows Forms и грид данных.
GetCell, GetRow, FindFirstCellWithValue
Предположим, мы тестируем приложение Windows Forms и делаем проверку в гриде данных:
WinTable dataGrid = new WinTable(appUnderTest); dataGrid.SearchProperties.Add(«Name«, «dgResultsGrid«); //Test a single cell WinCell cellActual = dataGrid.GetCell(0, 1); Assert.AreEqual(«Cell 1 Value«, cellActual.Value); //Validate an entire row WinRow dataGridrow = dataGrid.GetRow(2); int index = 0; string[] actualRow = { «Order ID«, «Order Name«, «Order Status» }; foreach (WinCell cell in dataGridrow.Cells) { Assert.AreEqual(actualRow[index], cell.Value); index++; } //FindFirstCellWithValue Test WinCell dataGridCell = dataGrid.FindFirstCellWithValue(«12345«); Assert.AreEqual(«12345«, dataGridCell.Value);
Проверка List Views (Win Form)
Выполнение проверки для элемента управления ListView также упрощается с помощью следующих методов:
GetColumnValues, GetColumnNames, GetContent
WinWindow listViewWindow = new WinWindow(AppUnderTest); listViewWindow.SearchProperties.Add(«ControlName«, «lvResultsList«); WinList listView = new WinList(listViewWindow); string[] actualColumnNames = listView.GetColumnNames(); string[] expectedColumnNames = new string[] { «Order ID«, «Order Name«, «Status» }; CollectionAssert.AreEqual(expectedColumnNames, actualColumnNames); string[] actualContent = listView.GetContent(); string[] expectedContent = new string[] { «111«, «Order 1«, «Pending«, «112«, «Order 2«, «Shipped«, «113«, «Order 3«, «Closed» }; CollectionAssert.AreEqual(expectedContent, actualContent); WinListItem listViewItem = new WinListItem(listView); listViewItem.SearchProperties.Add(«Name«, «111«); //Validate the entire list item string[] actualColumnValues = listViewItem.GetColumnValues(); string[] expectedColumnValues = new string[]{«111«, «Order 1«, «Pending» }; CollectionAssert.AreEqual(expectedColumnValues, actualColumnValues);
Проверка Доступного Описания (Win Form)
Проверка доступного описания теперь возможно с помощью новых API доступных в Visual Studio 2012
WinWindow win = new WinWindow(allWinControls); win.SearchProperties.Add(«ControlName«, «lvReport«); WinList lvReport = new WinList(win); Assert.AreEqual(«This is a list view with important names and values.«, lvReport.AccessibleDescription);
Проверка ToolTipText (Win Form, WPF)
Проверка текста всплывающей подсказки теперь возможно с помощью новых API доступных в Visual Studio 2012
WpfWindow win = new WpfWindow(); win.SearchProperties.Add(«Name«, «All WPF Controls«); WpfComboBox comboBox = new WpfComboBox(allWpfControlsWindow); comboBox.SearchProperties.Add(«AutomationId«, «cbNames«); Assert.AreEqual(«The cbNames tool tip«,comboBox.ToolTipText);
Проверка Состояния Элемента (WPF)
Проверка состояния элемента также возможна с помощью новых API, доступных в Visual Studio 2012. Для этого примера предположим, что реализация расширенного элемента управления WpfButton имеет цвет сопоставленный с ItemStatus пользовательского элемента управления. Для полного рабочего примера, смотрите эту запись блога.
WpfWindow win = new WpfWindow(); win.SearchProperties.Add(«Name«, «All WPF Controls«); WpfButton itemStatusButton = new WpfButton(win); itemStatusButton.SearchProperties.Add(«AutomationId«, «ItemStatusButton«); Assert.AreEqual(Color.Red, ColorTranslator.FromHtml(itemStatusButton.ItemStatus));
Выбор и проверка элемента в списке (WPF, Win Forms, HTML)
Добавлена возможность выбора элемента из списка, которая также упрощает процесс валидации
.Select
WinList listControl = new WinList(appUnderTestWithList); listControl.SearchProperties.Add(«Name«, «lNames«); WinListItem listItem = new WinListItem(listControl); listItem.SearchProperties.Add(«Name«, «thirdItemInList«); listItem.Select(); Assert.AreEqual(«I am Number 3«, list.SelectedItemsAsString);