public void ToggleTest() { CheckBox checkbox = new CheckBox(); IRawElementProviderSimple provider = ProviderFactory.GetProvider(checkbox); IToggleProvider toggleProvider = (IToggleProvider) provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id); // Test two-state toggling Assert.AreEqual(CheckState.Unchecked, checkbox.CheckState, "Start two-state Unchecked"); TestToggleEventWithToggle(toggleProvider, ToggleState.On); Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "First two-state toggle: Checked"); TestToggleEventWithToggle(toggleProvider, ToggleState.Off); Assert.AreEqual(CheckState.Unchecked, checkbox.CheckState, "Second two-state toggle: Unchecked"); TestToggleEventWithToggle(toggleProvider, ToggleState.On); Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "Third two-state toggle: Checked"); checkbox.ThreeState = true; // Test three-state toggling Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "Start three-state Checked"); TestToggleEventWithToggle(toggleProvider, ToggleState.Off); Assert.AreEqual(CheckState.Unchecked, checkbox.CheckState, "First three-state toggle: Unchecked"); TestToggleEventWithToggle(toggleProvider, ToggleState.Indeterminate); Assert.AreEqual(CheckState.Indeterminate, checkbox.CheckState, "Second three-state toggle: Intermediate"); TestToggleEventWithToggle(toggleProvider, ToggleState.On); Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "Third three-state toggle: Checked"); checkbox.Enabled = false; // Test that an exception is thrown when not enabled try { toggleProvider.Toggle(); Assert.Fail("Should throw ElementNotEnabledException"); } catch (ElementNotEnabledException) { } }
private void TestToggleEventWithToggle(IToggleProvider provider, ToggleState expectedState) { bridge.ResetEventLists(); object oldState = provider.ToggleState; provider.Toggle(); // Test IToggleProvider.ToggleState Assert.AreEqual(expectedState, provider.ToggleState, "ToggleState"); // Test event was fired as expected Assert.AreEqual(1, bridge.AutomationPropertyChangedEvents.Count, "event count"); AutomationPropertyChangedEventArgs eventArgs = bridge.AutomationPropertyChangedEvents [0].e; Assert.AreEqual(TogglePatternIdentifiers.ToggleStateProperty, eventArgs.Property, "event args property"); Assert.AreEqual(oldState, eventArgs.OldValue, "old value"); Assert.AreEqual(expectedState, eventArgs.NewValue, "new value"); }
public void ToggleTextBoxVisibility(bool visible) { if (btnToggle.IsChecked == visible && IsBreadcrumbEnabled) { ToggleButtonAutomationPeer bap = new ToggleButtonAutomationPeer(btnToggle); IToggleProvider iip = bap.GetPattern(PatternInterface.Toggle) as IToggleProvider; iip.Toggle(); } }
internal bool DoToggle() { try { toggleProvider.Toggle(); } catch (ElementNotEnabledException e) { Log.Debug(e); return(false); } return(true); }
public virtual void ToggleProvider_Toggle() { ToggleButton toggleButton = CreateConcreteFrameworkElement() as ToggleButton; FrameworkElementAutomationPeerContract feap = CreateConcreteFrameworkElementAutomationPeer(toggleButton); toggleButton.IsEnabled = false; IToggleProvider toggleProvider = feap as IToggleProvider; try { toggleProvider.Toggle(); Assert.Fail("Should throw ElementNotEnabledException"); } catch (ElementNotEnabledException) { } toggleButton.IsEnabled = true; // TODO: Test eventing // Test two-state toggling toggleButton.IsThreeState = false; toggleButton.IsChecked = false; Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "Start two-state toggle: Unchecked"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "First two-state toggle: Checked"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "Second two-state toggle: Unchecked"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "Third two-state toggle: Checked"); // Test three-state toggling toggleButton.IsThreeState = true; toggleButton.IsChecked = true; Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "Start three-state Checked"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.Indeterminate, toggleProvider.ToggleState, "First three-state toggle: Indeterminate"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "Second three-state Off: Intermediate"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "Third three-state toggle: Checked"); }
public override void ToggleProvider_Toggle() { RadioButton radioButton = CreateConcreteFrameworkElement() as RadioButton; FrameworkElementAutomationPeerContract feap = CreateConcreteFrameworkElementAutomationPeer(radioButton); radioButton.IsEnabled = false; IToggleProvider toggleProvider = feap as IToggleProvider; try { toggleProvider.Toggle(); Assert.Fail("Should throw ElementNotEnabledException"); } catch (ElementNotEnabledException) { } radioButton.IsEnabled = true; // Test two-state toggling radioButton.IsThreeState = false; radioButton.IsChecked = false; Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "Start two-state toggle: Unchecked"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "First two-state toggle: Checked"); // Test three-state toggling radioButton.IsThreeState = true; radioButton.IsChecked = false; Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "Start three-state Checked"); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "First three-state toggle: Checked"); // NOTE: I don't think it will ever be indeterminate }
public void SetValuesWithAutomationPeers() { DataClass dataClass = null; IInvokeProvider invokeProvider; this.EnqueueCallback(() => { dataClass = DataClassList.GetDataClassList(1, ListOperations.All)[0]; this.DataForm.CurrentItem = dataClass; }); this.AddToPanelAndWaitForLoad(); this.EnqueueCallback(() => { this.GetAutomationPeer(); this.GetChildAutomationPeers(); Assert.AreEqual(true, dataClass.BoolProperty); Assert.AreEqual("test string 0", dataClass.StringProperty); invokeProvider = this._editButtonAutomationPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; this.ExpectContentLoaded(); invokeProvider.Invoke(); }); this.WaitForContentLoaded(); this.EnqueueCallback(() => { this.GetChildAutomationPeers(); IToggleProvider toggleProvider = (this._inputControlAutomationPeers[0] as CheckBoxAutomationPeer).GetPattern(PatternInterface.Toggle) as IToggleProvider; IValueProvider valueProvider = (this._inputControlAutomationPeers[2] as TextBoxAutomationPeer).GetPattern(PatternInterface.Value) as IValueProvider; toggleProvider.Toggle(); valueProvider.SetValue("new string"); invokeProvider = this._commitButtonAutomationPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; this.ExpectContentLoaded(); invokeProvider.Invoke(); }); this.WaitForContentLoaded(); this.EnqueueCallback(() => { Assert.AreEqual(false, dataClass.BoolProperty); Assert.AreEqual("new string", dataClass.StringProperty); }); this.EnqueueTestComplete(); }
public static void autoCheckBatteryCapacity(DataModels.FilterDataModel filters) { //ShowingDevices _devicesobj = new ShowingDevices(); foreach (CheckBox cb in ShowingDevices.AppWindow.filter4Stack.Children) { foreach (var fil in filters.batterycapacity) { if ((int)cb.Content == int.Parse(fil)) { CheckBoxAutomationPeer peer = new CheckBoxAutomationPeer(cb); IToggleProvider toggleProvider = peer.GetPattern(PatternInterface.Toggle) as IToggleProvider; toggleProvider.Toggle(); } } } }
public static void autoCheckWeight(DataModels.FilterDataModel filters) { //ShowingDevices _devicesobj = new ShowingDevices(); foreach (CheckBox cb in ShowingDevices.AppWindow.filter2Stack.Children) { foreach (var weight in filters.weight) { if (weight.Equals(cb.Content.ToString().Split(' ')[0])) { CheckBoxAutomationPeer peer = new CheckBoxAutomationPeer(cb); IToggleProvider toggleProvider = peer.GetPattern(PatternInterface.Toggle) as IToggleProvider; toggleProvider.Toggle(); } } } }
public static void autoCheckResolution(DataModels.FilterDataModel filters) { //ShowingDevices _devicesobj = new ShowingDevices(); foreach (CheckBox cb in ShowingDevices.AppWindow.filter3Stack.Children) { foreach (var resolution in filters.resolution) { if (cb.Content.Equals(resolution)) { CheckBoxAutomationPeer peer = new CheckBoxAutomationPeer(cb); IToggleProvider toggleProvider = peer.GetPattern(PatternInterface.Toggle) as IToggleProvider; toggleProvider.Toggle(); } } } }
public virtual void TestHasKeyboardFocusAfterPattern() { ToggleButton fe = CreateConcreteFrameworkElement() as ToggleButton; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(fe); IToggleProvider provider = null; CreateAsyncTest(fe, () => { provider = (IToggleProvider)peer.GetPattern(PatternInterface.Toggle); Assert.IsNotNull(provider, "#0"); }, () => provider.Toggle(), () => Assert.IsTrue(peer.HasKeyboardFocus(), "#1")); }
public override bool DoAction(int action) { if (toggleProvider != null) { try { if (action != 0) { return(false); } toggleProvider.Toggle(); return(true); } catch (ElementNotEnabledException e) { Log.Debug(e); } } return(false); }
public void ToggleTest() { ToolBarButton toggleButton = new ToolBarButton(); toggleButton.Style = ToolBarButtonStyle.ToggleButton; toolBar.Buttons.Add(toggleButton); IRawElementProviderSimple provider = ProviderFactory.GetProvider(toggleButton); Assert.IsFalse(toggleButton.Pushed, "Button is not pushed by default."); IToggleProvider toggleProvider = (IToggleProvider) provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id); toggleProvider.Toggle(); Assert.IsTrue(toggleButton.Pushed, "Button is pushed."); }
public void ToggleEventTest() { ToolBarButton toggleButton = new ToolBarButton(); toggleButton.Style = ToolBarButtonStyle.ToggleButton; toolBar.Buttons.Add(toggleButton); IRawElementProviderSimple provider = ProviderFactory.GetProvider(toggleButton); IToggleProvider toggleProvider = (IToggleProvider) provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id); Label label = new Label(); label.Text = "Old Text"; toolBar.Controls.Add(label); Assert.AreEqual(label.Text, "Old Text", "Button is not pushed by default."); toolBar.ButtonClick += delegate(object sender, ToolBarButtonClickEventArgs e) { label.Text = "New Text"; }; toggleProvider.Toggle(); Assert.AreEqual(label.Text, "New Text", "Button is pushed."); }
public void ToggleTest() { IRawElementProviderSimple provider = ProviderFactory.GetProvider(button); IToggleProvider toggleProvider = provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id) as IToggleProvider; // LAMESPEC: We're going against the spec here -- if // CheckOnClick is set, support Toggle provider. button.CheckOnClick = false; // Depends -> No Assert.IsNull(toggleProvider, "Implements IToggleProvider"); button.CheckOnClick = true; toggleProvider = provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id) as IToggleProvider; // Depends -> Yes Assert.IsNotNull(toggleProvider, "Should implement IToggleProvider"); Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "ToggleState"); bridge.ResetEventLists(); toggleProvider.Toggle(); Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "ToggleState"); Assert.AreEqual(1, bridge.AutomationPropertyChangedEvents.Count, "event count"); }
public void Toggle() { provider.Toggle(); }
public virtual void ToggleProvider_ToggleEvents() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } ToggleButton toggleButton = CreateConcreteFrameworkElement() as ToggleButton; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(toggleButton); AutomationPropertyEventTuple tuple = null; IToggleProvider toggleProvider = (IToggleProvider)peer; CreateAsyncTest(toggleButton, () => { EventsManager.Instance.Reset(); toggleButton.IsThreeState = false; toggleButton.IsChecked = false; }, // Test two-state toggling () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNull(tuple, "#0"); Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "Start two-state toggle: Unchecked"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#1"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.OldValue, "#2"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.NewValue, "#3"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#4"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.OldValue, "#5"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.NewValue, "#6"); }, // Test three-state toggling () => { EventsManager.Instance.Reset(); toggleButton.IsThreeState = true; toggleButton.IsChecked = true; }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#7"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.OldValue, "#8"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.NewValue, "#9"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#10"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.OldValue, "#11"); Assert.AreEqual(ToggleState.Indeterminate, (ToggleState)tuple.NewValue, "#12"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#13"); Assert.AreEqual(ToggleState.Indeterminate, (ToggleState)tuple.OldValue, "#14"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.NewValue, "#15"); }, () => { EventsManager.Instance.Reset(); toggleProvider.Toggle(); }, () => { tuple = EventsManager.Instance.GetAutomationEventFrom(peer, TogglePatternIdentifiers.ToggleStateProperty); Assert.IsNotNull(tuple, "#16"); Assert.AreEqual(ToggleState.Off, (ToggleState)tuple.OldValue, "#17"); Assert.AreEqual(ToggleState.On, (ToggleState)tuple.NewValue, "#18"); }); }
public void ToggleTest() { picker.Format = DateTimePickerFormat.Long; picker.ShowCheckBox = false; IRawElementProviderSimple child = ((IRawElementProviderFragmentRoot)pickerProvider) .Navigate(NavigateDirection.FirstChild); IToggleProvider toggleProvider = child.GetPatternProvider( TogglePatternIdentifiers.Pattern.Id) as IToggleProvider; Assert.IsNull(toggleProvider, "With ShowCheckBox = false, DateTimePicker does not implement IToggleProvider"); picker.ShowCheckBox = true; // FirstChild changes when ShowCheckBox = true child = ((IRawElementProviderFragmentRoot)pickerProvider) .Navigate(NavigateDirection.FirstChild); TestProperty(child, AutomationElementIdentifiers.ControlTypeProperty, ControlType.CheckBox.Id); toggleProvider = child.GetPatternProvider( TogglePatternIdentifiers.Pattern.Id) as IToggleProvider; Assert.IsNotNull(toggleProvider, "With ShowCheckBox = true, DateTimePicker does not implement IToggleProvider"); picker.Checked = false; Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "With Checked = false, toggleProvider is not returning ToggleState.Off"); picker.Checked = true; Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "With Checked = true, toggleProvider is not returning ToggleState.On"); toggleProvider.Toggle(); Assert.IsFalse(picker.Checked, "After toggling off, Checked is still true"); Assert.AreEqual(ToggleState.Off, toggleProvider.ToggleState, "After toggling off, toggleProvider is not returning ToggleState.Off"); // Verify that parts aren't enabled for (int i = 0; i < 6; i++) { child = ((IRawElementProviderFragment)child).Navigate( NavigateDirection.NextSibling); } TestProperty(child, AutomationElementIdentifiers.ControlTypeProperty, ControlType.Spinner.Id); TestProperty(child, AutomationElementIdentifiers.IsEnabledProperty, false); IRangeValueProvider rangeValueProvider = child.GetPatternProvider( RangeValuePatternIdentifiers.Pattern.Id) as IRangeValueProvider; bool gotException = false; try { rangeValueProvider.SetValue(1); } catch (ElementNotEnabledException) { gotException = true; } if (!gotException) { Assert.Fail("Able to set RangeValue's value when picker is disabled"); } toggleProvider.Toggle(); Assert.IsTrue(picker.Checked, "After toggling on, Checked is still false"); Assert.AreEqual(ToggleState.On, toggleProvider.ToggleState, "After toggling on, toggleProvider is not returning ToggleState.On"); }
void IToggleProvider.Toggle() => publicIToggleProvider.Toggle();
private void TestToggleEventWithToggle (IToggleProvider provider, ToggleState expectedState) { bridge.ResetEventLists (); object oldState = provider.ToggleState; provider.Toggle (); // Test IToggleProvider.ToggleState Assert.AreEqual (expectedState, provider.ToggleState, "ToggleState"); // Test event was fired as expected Assert.AreEqual (1, bridge.AutomationPropertyChangedEvents.Count, "event count"); AutomationPropertyChangedEventArgs eventArgs = bridge.AutomationPropertyChangedEvents [0].e; Assert.AreEqual (TogglePatternIdentifiers.ToggleStateProperty, eventArgs.Property, "event args property"); Assert.AreEqual (oldState, eventArgs.OldValue, "old value"); Assert.AreEqual (expectedState, eventArgs.NewValue, "new value"); }