/// <summary> /// Allows searching with retrying for a list of <see cref="AutomationElement"/>s. /// </summary> /// <param name="searchMethod">The method used to search for the element list.</param> /// <param name="retrySettings">The settings to use for retrying.</param> /// <returns>The list of found elements.</returns> public static AutomationElement[] Find(Func <AutomationElement[]> searchMethod, RetrySettings retrySettings) { if (retrySettings == null) { return(searchMethod()); } return(Retry.WhileEmpty(searchMethod, retrySettings.Timeout, retrySettings.Interval, retrySettings.ThrowOnTimeout, retrySettings.IgnoreException, retrySettings.TimeoutMessage).Result); }
public void Test_simple_iec_cdd_data_source() { var aasxPath = Common.PathTo01FestoAasx(); var dictImportDir = Path.Combine(Common.TestResourcesDir(), "IecCdd", "simple"); Common.RunWithMainWindow((application, automation, mainWindow) => { Common.RequireMenuItem(mainWindow, "File", "Import ..", "Import Submodel from Dictionary ..").Click(); var window = Common.RequireTopLevelWindowByTitle(application, automation, "Dictionary Import"); var comboBoxDataSources = window.FindFirstChild("ComboBoxSource").AsComboBox(); var dataSources = comboBoxDataSources.Items; Assert.That(dataSources.Length == 1, "Expected one default sources for the dictionary import dir 'simple'"); var dataSource = dataSources[0].Text; Assert.That(dataSource == "IEC CDD: simple", $"Unexpected label for the simple IEC CDD data source: '{dataSource}'"); comboBoxDataSources.Select(0); var topLevelView = window.FindFirstChild("ClassViewControl").AsListBox(); var topLevelElements = Retry.WhileEmpty(() => topLevelView.Items, timeout: TimeSpan.FromSeconds(5), throwOnTimeout: true, timeoutMessage: "Could not find top-level elements from simple IEC CDD source" ).Result; Assert.That(topLevelElements.Select(e => e.Text), Is.EqualTo(new[] { "C1", "C2", "C3" }), "Unexpected top-level elements for the simple IEC CDD source"); Common.AssertNoErrors(application, mainWindow); }, new Run { Args = new[] { "-dict-import-dir", dictImportDir, aasxPath } }); }