public static void ToggleAndWait(this ToggleButton toggleButton) { if (toggleButton == null) { Log.Error("Attempted to toggle a null toggle button! Dumping context..."); DumpHelper.DumpFullContext(); throw new ArgumentNullException("toggleButton"); } using (var waiter = toggleButton.GetToggledWaiter()) { toggleButton.Toggle(); waiter.Wait(); } Wait.ForIdle(); }
public void CanTapOnSecondaryItems() { if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2)) { Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2"); return; } using (var setup = new CommandBarFlyoutTestSetupHelper()) { Button showCommandBarFlyoutButton = FindElement.ByName <Button>("Show CommandBarFlyout"); ToggleButton isFlyoutOpenCheckBox = FindElement.ById <ToggleButton>("IsFlyoutOpenCheckBox"); Action openCommandBarAction = () => { Log.Comment("Tapping on a button to show the CommandBarFlyout."); InputHelper.Tap(showCommandBarFlyoutButton); // Pre-RS5, CommandBarFlyouts always open expanded, // so we don't need to tap on the more button in that case. if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5)) { Log.Comment("Expanding the CommandBar by invoking the more button."); FindElement.ById <Button>("MoreButton").InvokeAndWait(); } }; Log.Comment("Opening the CommandBar and invoking the first button in the secondary commands list."); openCommandBarAction(); using (var waiter = isFlyoutOpenCheckBox.GetToggledWaiter()) { setup.ExecuteAndWaitForEvents(() => FindElement.ById <Button>("UndoButton1").Invoke(), new List <string>() { "UndoButton1 clicked" }); waiter.Wait(); } Verify.IsTrue(isFlyoutOpenCheckBox.ToggleState == ToggleState.Off); Log.Comment("Opening the CommandBar and invoking the second button in the secondary commands list."); openCommandBarAction(); using (var waiter = isFlyoutOpenCheckBox.GetToggledWaiter()) { setup.ExecuteAndWaitForEvents(() => FindElement.ById <Button>("RedoButton1").Invoke(), new List <string>() { "RedoButton1 clicked" }); waiter.Wait(); } Verify.IsTrue(isFlyoutOpenCheckBox.ToggleState == ToggleState.Off); Log.Comment("Opening the CommandBar and invoking the third button in the secondary commands list."); openCommandBarAction(); using (var waiter = isFlyoutOpenCheckBox.GetToggledWaiter()) { setup.ExecuteAndWaitForEvents(() => FindElement.ById <Button>("SelectAllButton1").Invoke(), new List <string>() { "SelectAllButton1 clicked" }); waiter.Wait(); } Verify.IsTrue(isFlyoutOpenCheckBox.ToggleState == ToggleState.Off); Log.Comment("Opening the CommandBar and invoking the toggle button in the secondary commands list."); openCommandBarAction(); using (var waiter = isFlyoutOpenCheckBox.GetToggledWaiter()) { setup.ExecuteAndWaitForEvents(() => FindElement.ById <ToggleButton>("FavoriteToggleButton1").Toggle(), new List <string>() { "FavoriteToggleButton1 checked" }); waiter.Wait(); } Verify.IsTrue(isFlyoutOpenCheckBox.ToggleState == ToggleState.Off); } }
public void VerifyDynamicSecondaryCommandLabel() { if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2)) { Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2"); return; } using (var setup = new CommandBarFlyoutTestSetupHelper()) { Log.Comment("Retrieving FlyoutTarget6"); Button showCommandBarFlyoutButton = FindElement.ByName <Button>("Show CommandBarFlyout with no primary commands"); Log.Comment("Retrieving IsFlyoutOpenCheckBox"); ToggleButton isFlyoutOpenCheckBox = FindElement.ById <ToggleButton>("IsFlyoutOpenCheckBox"); Log.Comment("Retrieving UseSecondaryCommandDynamicLabelCheckBox"); ToggleButton useSecondaryCommandDynamicLabelCheckBox = FindElement.ById <ToggleButton>("UseSecondaryCommandDynamicLabelCheckBox"); Log.Comment("SecondaryCommandDynamicLabelChangedCheckBox"); ToggleButton secondaryCommandDynamicLabelChangedCheckBox = FindElement.ById <ToggleButton>("SecondaryCommandDynamicLabelChangedCheckBox"); Log.Comment("Retrieving DynamicLabelTimerIntervalTextBox"); Edit dynamicLabelTimerIntervalTextBox = new Edit(FindElement.ById("DynamicLabelTimerIntervalTextBox")); Log.Comment("Retrieving DynamicLabelChangeCountTextBox"); Edit dynamicLabelChangeCountTextBox = new Edit(FindElement.ById("DynamicLabelChangeCountTextBox")); Verify.AreEqual(ToggleState.Off, isFlyoutOpenCheckBox.ToggleState); Log.Comment("Change the first command bar element's Label property asynchronously after the command bar is opened"); useSecondaryCommandDynamicLabelCheckBox.Check(); Log.Comment("Setting DynamicLabelTimerIntervalTextBox to 1s"); dynamicLabelTimerIntervalTextBox.SetValue("1000"); Log.Comment("Setting DynamicLabelChangeCountTextBox to 1 single change"); dynamicLabelChangeCountTextBox.SetValue("1"); Wait.ForIdle(); Verify.AreEqual(ToggleState.Off, secondaryCommandDynamicLabelChangedCheckBox.ToggleState); Log.Comment("Invoking button 'Show CommandBarFlyout with no primary commands' to show the Flyout6 command bar."); showCommandBarFlyoutButton.Invoke(); Wait.ForIdle(); Verify.AreEqual(ToggleState.On, isFlyoutOpenCheckBox.ToggleState); Button undoButton6 = FindElement.ById <Button>("UndoButton6"); Verify.IsNotNull(undoButton6); UIObject commandBarElementsContainer = undoButton6.Parent; Verify.IsNotNull(commandBarElementsContainer); Rectangle initialBoundingRectangle = commandBarElementsContainer.BoundingRectangle; Log.Comment("Initial commandBarElementsContainer.BoundingRectangle.Width=" + initialBoundingRectangle.Width); Log.Comment("Initial commandBarElementsContainer.BoundingRectangle.Height=" + initialBoundingRectangle.Height); Verify.AreEqual(ToggleState.Off, secondaryCommandDynamicLabelChangedCheckBox.ToggleState); Log.Comment("Waiting for SecondaryCommandDynamicLabelChangedCheckBox becoming checked indicating the asynchronous Label property change occurred"); secondaryCommandDynamicLabelChangedCheckBox.GetToggledWaiter().Wait(); Wait.ForIdle(); Rectangle finalBoundingRectangle = commandBarElementsContainer.BoundingRectangle; Log.Comment("Final commandBarElementsContainer.BoundingRectangle.Width=" + finalBoundingRectangle.Width); Log.Comment("Final commandBarElementsContainer.BoundingRectangle.Height=" + finalBoundingRectangle.Height); Log.Comment("Hitting Escape key to close the command bar."); KeyboardHelper.PressKey(Key.Escape); Wait.ForIdle(); Verify.AreEqual(ToggleState.Off, isFlyoutOpenCheckBox.ToggleState); Log.Comment("Verifying the command bar flyout width was increased to accommodate the longer label."); Verify.IsGreaterThan(finalBoundingRectangle.Width, initialBoundingRectangle.Width); Verify.AreEqual(finalBoundingRectangle.Height, initialBoundingRectangle.Height); } }