public void ToggleTest() { using (var setup = new TestSetupHelper("SplitButton Tests")) { SplitButton splitButton = FindElement.ByName <SplitButton>("ToggleSplitButton"); TextBlock toggleStateTextBlock = FindElement.ByName <TextBlock>("ToggleStateTextBlock"); TextBlock toggleStateOnClickTextBlock = FindElement.ByName <TextBlock>("ToggleStateOnClickTextBlock"); Verify.AreEqual("Unchecked", toggleStateTextBlock.DocumentText); Verify.AreEqual("Unchecked", toggleStateOnClickTextBlock.DocumentText); Log.Comment("Click primary button to check button"); using (var toggleStateWaiter = new PropertyChangedEventWaiter(splitButton, Scope.Element, UIProperty.Get("Toggle.ToggleState"))) { ClickPrimaryButton(splitButton); Verify.IsTrue(toggleStateWaiter.TryWait(TimeSpan.FromSeconds(1)), "Waiting for the Toggle.ToggleState event should succeed"); } Verify.AreEqual("Checked", toggleStateTextBlock.DocumentText); Verify.AreEqual("Checked", toggleStateOnClickTextBlock.DocumentText); Log.Comment("Click primary button to uncheck button"); ClickPrimaryButton(splitButton); Verify.AreEqual("Unchecked", toggleStateTextBlock.DocumentText); Verify.AreEqual("Unchecked", toggleStateOnClickTextBlock.DocumentText); Log.Comment("Clicking secondary button should not change toggle state"); ClickSecondaryButton(splitButton); Verify.AreEqual("Unchecked", toggleStateTextBlock.DocumentText); Verify.AreEqual("Unchecked", toggleStateOnClickTextBlock.DocumentText); } }
bool SetToggleState(ToggleState toggleState) { for (var index = 0; index < 3; ++index) { if (this._togglePattern.ToggleState == toggleState) { return(true); } if (index < 2) { using (var changedEventWaiter = new PropertyChangedEventWaiter(root: this, scope: Scope.Element, UIProperty.Get(name: "Toggle.ToggleState"))) { Toggle(); changedEventWaiter.TryWait(timeout: 500); } } } return(false); }