/// ------------------------------------------------------------------- /// <summary>Common wait method for callback</summary> /// ------------------------------------------------------------------- void Wait(WaitTestState callback, int milliSeconds, AutomationElement element, CheckType checkType) { _waitElement = element; Wait(callback, milliSeconds, checkType); }
/// ------------------------------------------------------------------- /// <summary>Common wait method for callback</summary> /// ------------------------------------------------------------------- void Wait(WaitTestState callback, int milliSeconds, CheckType checkType) { object[] attribs = callback.Method.GetCustomAttributes(false); string eventMethod = ((WaitAttribute)attribs[0]).EventToWaitFor; DateTime stopTime = DateTime.Now + TimeSpan.FromMilliseconds(milliSeconds); for (; ; ) { Comment("Waiting for {0}", eventMethod); if (true == callback()) return; // Allow other processes to proceed Thread.Sleep(500); if (DateTime.Now > stopTime) ThrowMe(checkType, "Timeout waiting (Waited '{0}' seconds)", milliSeconds / 1000); } }
/// ------------------------------------------------------------------- /// <summary></summary> /// ------------------------------------------------------------------- void TS_ToggleCheckState(AutomationElement element, WaitTestState callBackOn, WaitTestState callBackOff, CheckType checkType) { Library.ValidateArgumentNonNull(element, "AutomationElement"); ToggleState currentToggleState; ToggleState newToggleState; // Verify that control supports ToggelPattern if (false == (bool)element.GetCurrentPropertyValue(AutomationElement.IsTogglePatternAvailableProperty)) ThrowMe(checkType, "Element does not support TogglePattern"); // Get the current ToggleState currentToggleState = ((ToggleState)element.GetCurrentPropertyValue(TogglePattern.ToggleStateProperty)); Comment("Current ToggleState of " + element.Current.Name + "\" is " + currentToggleState.ToString()); // Identify the desited ToggleState after it has been Toggled newToggleState = currentToggleState == ToggleState.Off ? ToggleState.On : ToggleState.Off; // Toggle the checkbox ((TogglePattern)element.GetCurrentPattern(TogglePattern.Pattern)).Toggle(); // Wait till it actually has been checked if (newToggleState == ToggleState.On) Wait(callBackOn, _WAIT_NORMAL_MILLISECONDS, CheckType.Verification); else Wait(callBackOff, _WAIT_NORMAL_MILLISECONDS, CheckType.Verification); m_TestStep++; }
/// ------------------------------------------------------------------- /// <summary></summary> /// ------------------------------------------------------------------- void TS_ChangeListValueRandom(AutomationElement element, WaitTestState callBackForChange, CheckType checkType) { Library.ValidateArgumentNonNull(element, "element"); AutomationElementCollection elements = element.FindAll(TreeScope.Descendants, new AndCondition( new Condition[] { new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem), new PropertyCondition(SelectionItemPattern.IsSelectedProperty, false) })); if (elements.Count != 0) { Random rnd = new Random(); AutomationElement newSelect = elements[rnd.Next(elements.Count)]; if (newSelect == null) ThrowMe(checkType, "Could not get a non selected item"); _changedToValue = newSelect.Current.Name; SelectionItemPattern sip = newSelect.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; sip.Select(); Wait(callBackForChange, _WAIT_NORMAL_MILLISECONDS, checkType); } m_TestStep++; }
/// ------------------------------------------------------------------- /// <summary></summary> /// -----------------------`-------------------------------------------- private void TSM_MainDialogSettings( ActionMethod actionMethod, string keyName, GetElement subMenu, GetElement checkBox, WaitTestState callbackCheckBoxIsChecked, WaitTestState callbackCheckBoxIsUnChecked, CheckType checkType) { // "Step: Toggle the \"\" menu", TS_ToggleMainFormSettingsByMenu( ActionMethod.Menu, MainForm.ApplicationMenuBar.PreferencesMenu.AutomationElement, subMenu, callbackCheckBoxIsChecked, callbackCheckBoxIsUnChecked, CheckType.Verification); HelperPersistKeyNameValuesToTable(_keyNameValuesCurrent); // "Step: Close Narrator", TS_NarratorClose(ActionMethod.UIAutomation, true, CheckType.Verification); // "Step: Restart Narrator", TS_NarratorStart(WindowVisualState.Normal, CheckType.Verification); // "Step: Verify current \"\" registry setting to previous runs value set", // "Step: Verify current \"\" check box setting to previous runs value set", // "Step: Verify the ToggleState of the sub menu", TS3_VerifyMainFormSetting(keyName, checkBox, MainForm.ApplicationMenuBar.PreferencesMenu.AutomationElement, subMenu, CheckType.Verification); }
/// ------------------------------------------------------------------- /// <summary></summary> /// ------------------------------------------------------------------- void TSM_NarratorRegistrySettingsRegistryPersistency(AutomationElement element, string keyName, WaitTestState callBackOn, WaitTestState callBackOff, CheckType checkType) { Library.ValidateArgumentNonNull(element, "AutomationElement"); switch (element.Current.ControlType.ProgrammaticName) { case "ControlType.CheckBox": { TS_ToggleCheckState(element, callBackOn, callBackOff, checkType); TS_VerifyRegistryForCheckBox(element, keyName, CheckType.Verification); } break; case "ControlType.ComboBox": case "ControlType.List": { TS_ChangeListValueRandom(element, callBackOn, checkType); } break; } }
/// ------------------------------------------------------------------- /// <summary></summary> /// ------------------------------------------------------------------- private void TS_ToggleMainFormSettingsByMenu( ActionMethod actionMethod, AutomationElement menu, GetElement subMenu, WaitTestState checkBoxOnCallBack, WaitTestState checkBoxOffCallBack, CheckType checkType) { switch (actionMethod) { case ActionMethod.Menu: { HelperExpandMenuUsingAccessKey(menu, checkType); AutomationElement subMenuItem = subMenu(); ToggleState ts = GetMenuToggleState(subMenuItem); HelperInvokeMenuItemUsingAccessKey(subMenuItem, CheckType.Verification); if (ts == ToggleState.Off) Wait(checkBoxOnCallBack, _WAIT_NORMAL_MILLISECONDS, checkType); else Wait(checkBoxOffCallBack, _WAIT_NORMAL_MILLISECONDS, checkType); } break; default: throw new ArgumentException(); } m_TestStep++; }