private void VerifyBoxes(TabBase tab, RegistryHelper reg, bool inverse, OpenTarget target, Tabs.GlobalState consoleVersion) { // get the key for the current target RegistryKey consoleKey = reg.GetMatchingKey(target); // hold the parent console key in case we need to look things up for specifics. RegistryKey parentConsoleKey = reg.GetMatchingKey(OpenTarget.Defaults); // include the global checkbox in the set for verification purposes IEnumerable <CheckBoxMeta> boxes = tab.GetCheckboxesForVerification(); AutoHelpers.LogInvariant("Testing target: {0} in inverse {1} mode", target.ToString(), inverse.ToString()); // If we're opened as specifics, remove all global only boxes from the test set if (target == OpenTarget.Specifics) { AutoHelpers.LogInvariant("Reducing"); boxes = boxes.Where(box => !box.IsGlobalOnly); } foreach (CheckBoxMeta meta in boxes) { int?storedValue = consoleKey.GetValue(meta.ValueName) as int?; string boxName = AutoHelpers.FormatInvariant("Box: {0}", meta.ValueName); // if we're in specifics mode, we might have a null and if so, we check the parent value if (target == OpenTarget.Specifics) { if (storedValue == null) { AutoHelpers.LogInvariant("Specific setting missing. Checking defaults."); storedValue = parentConsoleKey.GetValue(meta.ValueName) as int?; } } else { Verify.IsNotNull(storedValue, boxName); } if (consoleVersion == Tabs.GlobalState.ConsoleV1 && meta.IsV2Property) { AutoHelpers.LogInvariant("Skipping validation of v2 property {0} after switching to v1 console.", meta.ValueName); } else { // A box can be inverse if checking it means false in the registry. // This method can be inverse if we're turning off the boxes and expecting it to be on. // Therefore, a box will be false if it's checked and supposed to be off. Or if it's unchecked and supposed to be on. if ((meta.IsInverse && !inverse) || (!meta.IsInverse && inverse)) { Verify.IsFalse(storedValue.Value.DwordToBool(), boxName); } else { Verify.IsTrue(storedValue.Value.DwordToBool(), boxName); } } } }
private void OpenPropertiesDialog(CmdApp app, OpenTarget target) { var titleBar = app.GetTitleBar(); app.Session.Mouse.ContextClick(titleBar.Coordinates); Globals.WaitForTimeout(); var contextMenu = app.Session.FindElementByClassName(Globals.PopupMenuClassId); AppiumWebElement propButton; switch (target) { case OpenTarget.Specifics: propButton = contextMenu.FindElementByName("Properties"); break; case OpenTarget.Defaults: propButton = contextMenu.FindElementByName("Defaults"); break; default: throw new NotImplementedException(AutoHelpers.FormatInvariant("Open Properties dialog doesn't yet support target type of '{0}'", target.ToString())); } propButton.Click(); Globals.WaitForTimeout(); this.PropWindow = this.app.UIRoot.FindElementByClassName(Globals.DialogWindowClassId); this.Tabs = this.PropWindow.FindElementByClassName("SysTabControl32"); okButton = this.PropWindow.FindElementByName("OK"); cancelButton = this.PropWindow.FindElementByName("Cancel"); }
public void Open(OpenTarget target) { if (this.isOpened) { throw new InvalidOperationException("Can't open an already opened window."); } this.OpenPropertiesDialog(this.app, target); this.isOpened = true; }
public RegistryKey GetMatchingKey(OpenTarget target) { switch (target) { case OpenTarget.Defaults: return(Registry.CurrentUser.OpenSubKey(@"Console")); case OpenTarget.Specifics: return(Registry.CurrentUser.OpenSubKey(@"Console").OpenSubKey("%SystemRoot%_system32_cmd.exe")); default: throw new NotImplementedException(AutoHelpers.FormatInvariant("This type of registry key isn't implemented: {0}", target.ToString())); } }
private void VerifySliders(TabBase tab, RegistryHelper reg, SliderMeta.ExpectedPosition expected, OpenTarget target, Tabs.GlobalState consoleVersion) { // get the key for the current target RegistryKey consoleKey = reg.GetMatchingKey(target); // hold the parent console key in case we need to look things up for specifics. RegistryKey parentConsoleKey = reg.GetMatchingKey(OpenTarget.Defaults); IEnumerable <SliderMeta> sliders = tab.GetSlidersForVerification(); foreach (SliderMeta meta in sliders) { int?storedValue = consoleKey.GetValue(meta.ValueName) as int?; string sliderName = AutoHelpers.FormatInvariant("Slider: {0}", meta.ValueName); if (target == OpenTarget.Specifics) { if (storedValue == null) { AutoHelpers.LogInvariant("Specific setting missing. Checking defaults."); storedValue = parentConsoleKey.GetValue(meta.ValueName) as int?; } } else { Verify.IsNotNull(storedValue, sliderName); } int transparency = 0; switch (expected) { case SliderMeta.ExpectedPosition.Maximum: transparency = meta.GetMaximum(); break; case SliderMeta.ExpectedPosition.Minimum: transparency = meta.GetMinimum(); break; default: throw new NotImplementedException(); } if (consoleVersion == Tabs.GlobalState.ConsoleV1 && meta.IsV2Property) { AutoHelpers.LogInvariant("Skipping validation of v2 property {0} after switching to v1 console.", meta.ValueName); } else { Verify.AreEqual(storedValue.Value, RescaleSlider(transparency), sliderName); } } }
private void CheckWritebacksVerifyValues(bool isRegMode, RegistryHelper reg, ShortcutHelper shortcut, OpenTarget target, TabBase tab, SliderMeta.ExpectedPosition sliderExpected, bool checkboxValue, Tabs.GlobalState consoleVersion) { if (isRegMode) { VerifyBoxes(tab, reg, checkboxValue, target, consoleVersion); VerifySliders(tab, reg, sliderExpected, target, consoleVersion); } else { // Have to wait for shortcut to get written. // There isn't really an event to know when this occurs, so just wait. Globals.WaitForTimeout(); VerifyBoxes(tab, shortcut, checkboxValue, consoleVersion); VerifySliders(tab, shortcut, sliderExpected, consoleVersion); } }
private void CheckWritebacksVerifyValues(bool isRegMode, RegistryHelper reg, ShortcutHelper shortcut, OpenTarget target, Tabs tabs, SliderMeta.ExpectedPosition sliderExpected, bool checkboxValue, Tabs.GlobalState consoleVersion) { foreach (TabBase tab in tabs.AllTabs) { CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tab, sliderExpected, checkboxValue, consoleVersion); } }
private void CheckWritebacks(RegistryHelper reg, ShortcutHelper shortcut, CmdApp app, OpenTarget target) { // either registry or shortcut are null if ((reg == null && shortcut == null) || (reg != null && shortcut != null)) { throw new NotSupportedException("Must leave either registry or shortcut null. And must supply one of the two."); } bool isRegMode = reg != null; // true is reg mode, false is shortcut mode string modeName = isRegMode ? "registry" : "shortcut"; AutoHelpers.LogInvariant("Beginning {0} writeback tests for {1}", modeName, target.ToString()); using (PropertiesDialog props = new PropertiesDialog(app)) { // STEP 1: VERIFY EVERYTHING SAVES IN AN ON/MAX STATE AutoHelpers.LogInvariant("Open dialog and check boxes."); props.Open(target); using (Tabs tabs = new Tabs(props)) { // Set V2 on. tabs.SetGlobalState(Tabs.GlobalState.ConsoleV2); AutoHelpers.LogInvariant("Toggling elements on all tabs."); foreach (TabBase tab in tabs.AllTabs) { tab.NavigateToTab(); foreach (CheckBoxMeta obj in tab.GetCheckboxesForVerification()) { obj.Check(); } foreach (SliderMeta obj in tab.GetSlidersForVerification()) { // adjust slider to the maximum obj.SetToMaximum(); } } AutoHelpers.LogInvariant("Hit OK to save."); props.Close(PropertiesDialog.CloseAction.OK); AutoHelpers.LogInvariant("Verify values changed as appropriate."); CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tabs, SliderMeta.ExpectedPosition.Maximum, false, Tabs.GlobalState.ConsoleV2); } // STEP 2: VERIFY EVERYTHING SAVES IN AN OFF/MIN STATE AutoHelpers.LogInvariant("Open dialog and uncheck boxes."); props.Open(target); using (Tabs tabs = new Tabs(props)) { AutoHelpers.LogInvariant("Toggling elements on all tabs."); foreach (TabBase tab in tabs.AllTabs) { tab.NavigateToTab(); foreach (SliderMeta slider in tab.GetSlidersForVerification()) { // adjust slider to the minimum slider.SetToMinimum(); } foreach (CheckBoxMeta obj in tab.GetCheckboxesForVerification()) { obj.Uncheck(); } } tabs.SetGlobalState(Tabs.GlobalState.ConsoleV1); AutoHelpers.LogInvariant("Hit OK to save."); props.Close(PropertiesDialog.CloseAction.OK); AutoHelpers.LogInvariant("Verify values changed as appropriate."); CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tabs, SliderMeta.ExpectedPosition.Minimum, true, Tabs.GlobalState.ConsoleV1); } // STEP 3: VERIFY CANCEL DOES NOT SAVE AutoHelpers.LogInvariant("Open dialog and check boxes."); props.Open(target); using (Tabs tabs = new Tabs(props)) { tabs.SetGlobalState(Tabs.GlobalState.ConsoleV2); AutoHelpers.LogInvariant("Toggling elements on all tabs."); foreach (TabBase tab in tabs.AllTabs) { tab.NavigateToTab(); foreach (CheckBoxMeta obj in tab.GetCheckboxesForVerification()) { obj.Check(); } foreach (SliderMeta obj in tab.GetSlidersForVerification()) { // adjust slider to the maximum obj.SetToMaximum(); } } AutoHelpers.LogInvariant("Hit cancel to not save."); props.Close(PropertiesDialog.CloseAction.Cancel); AutoHelpers.LogInvariant("Verify values did not change."); CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tabs, SliderMeta.ExpectedPosition.Minimum, true, Tabs.GlobalState.ConsoleV1); } } }
private void CheckShortcutWritebacks(ShortcutHelper shortcut, CmdApp app, OpenTarget target) { this.CheckWritebacks(null, shortcut, app, target); }
private void CheckRegistryWritebacks(RegistryHelper reg, CmdApp app, OpenTarget target) { this.CheckWritebacks(reg, null, app, target); }