Exemplo n.º 1
0
        public void When_Foreground_Changed_With_Visibility()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.TextBlockControl.TextBlock_Foreground_While_Collapsed");

            _app.WaitForText("FunnyTextBlock", "Look at me now");

            using var blueBefore = TakeScreenshot("Before - blue", ignoreInSnapshotCompare: true);

            _app.FastTap("ChangeTextBlockButton");

            using var blackBefore = TakeScreenshot("Before - black");

            var textRect = _app.GetPhysicalRect("FunnyTextBlock");

            ImageAssert.AreNotEqual(blueBefore, blackBefore, textRect);

            _app.FastTap("ChangeTextBlockButton");

            //_app.WaitForNoElement("FunnyTextBlock"); // This times out on WASM because view is considered to be still there when collapsed - https://github.com/unoplatform/Uno.UITest/issues/25

            _app.FastTap("ChangeTextBlockButton");

            _app.WaitForElement("FunnyTextBlock");

            using var blueAfter = TakeScreenshot("After - blue");

            ImageAssert.AreEqual(blueBefore, blueAfter, textRect);
        }
        public void ProgressRing_IsEnabled_Running()
        {
            Run("UITests.Windows_UI_Xaml_Controls.ProgressRing.WindowsProgressRing_GH1220");

            var isEnabledTest = _app.Marked("isEnabledTest");
            var placeHolder   = _app.Marked("placeHolder");

            var before = TakeScreenshot("before", new ScreenshotOptions()
            {
                IgnoreInSnapshotCompare = true
            });
            var placeholderRect   = _app.Query(placeHolder).First().Rect;
            var isEnabledTestRect = _app.Query(isEnabledTest).First().Rect;

            ImageAssert.AreNotEqual(before, placeholderRect, before, isEnabledTestRect);

            isEnabledTest.SetDependencyPropertyValue("IsEnabled", "True");

            var after = TakeScreenshot("after", new ScreenshotOptions()
            {
                IgnoreInSnapshotCompare = true
            });

            ImageAssert.AreNotEqual(before, placeholderRect, after, isEnabledTestRect);
        }
Exemplo n.º 3
0
        // WASM: ClickCheckBoxAt() fails because AtIndex() isn't supported https://github.com/unoplatform/Uno.UITest/issues/47
        public void ListView_ExpandableItem_ExpandMultipleItems()
        {
            Run("SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Expandable_Item");

            var checkBox = _app.Marked("CheckBox");

            _app.WaitForElement(checkBox);

            // Save initial state(not expanded)
            using var screenshot1 = TakeScreenshot("Initial State");

            // Expand multiple items and compare
            ClickCheckBoxAt(0);
            ClickCheckBoxAt(1);
            ClickCheckBoxAt(2);
            using var screenshot2 = TakeScreenshot("Expanded State");
            ImageAssert.AreNotEqual(screenshot1, screenshot2);

            // Collapse all and compare
            ClickCheckBoxAt(0);
            ClickCheckBoxAt(1);
            ClickCheckBoxAt(2);
            using var screenshot3 = TakeScreenshot("Collapsed State");
            ImageAssert.AreEqual(screenshot1, screenshot3);
        }
Exemplo n.º 4
0
        // WASM: ListView.Header not implemented https://github.com/unoplatform/uno/issues/1979
        public void ListView_ExpandableItemLarge_ExpandHeaderWithMultipleItems_Validation()
        {
            Run("SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Expandable_Item_Large");

            var checkBoxHeader = _app.Marked("CheckBoxHeader");

            _app.WaitForElement(checkBoxHeader);

            // Save initial state(not expanded)
            using var screenshot1 = TakeScreenshot("Initial State");

            // Expand and compare
            checkBoxHeader.FastTap();
            ClickCheckBoxAt(0);
            ClickCheckBoxAt(1);
            ClickCheckBoxAt(2);
            using var screenshot2 = TakeScreenshot("Expanded State");
            ImageAssert.AreNotEqual(screenshot1, screenshot2);

            // Collapse and compare
            checkBoxHeader.FastTap();
            ClickCheckBoxAt(0);
            ClickCheckBoxAt(1);
            ClickCheckBoxAt(2);
            using var screenshot3 = TakeScreenshot("Collapsed State");
            ImageAssert.AreEqual(screenshot1, screenshot3);
        }
        public void TestProgressRing_InitialState()
        {
            Run("UITests.Microsoft_UI_Xaml_Controls.ProgressRing.WinUIProgressRing_Features");

            _app.WaitForElement("dyn8");

            using var screenshot = TakeScreenshot("scrn", ignoreInSnapshotCompare: true);

            _app.Marked("dynamicValue").SetDependencyPropertyValue("Value", "90");
            _app.Marked("dynamicValue").SetDependencyPropertyValue("Value", "30");

            using var screenshot2 = TakeScreenshot("scrn2", ignoreInSnapshotCompare: true);

            var rects = Enumerable
                        .Range(1, 8)
                        .Select(i => "dyn" + i)
                        .Select(marked => _app.GetPhysicalRect(marked))
                        .ToArray();

            var i = 1;

            foreach (var rect in rects)
            {
                ImageAssert.AreNotEqual(screenshot2, screenshot, rect);
                _app.Marked("dyn" + i++).SetDependencyPropertyValue("Opacity", "0");
            }

            using var screenshot3 = TakeScreenshot("scrn3", ignoreInSnapshotCompare: true);

            foreach (var rect in rects)
            {
                // Ensure initial state is not empty
                ImageAssert.AreNotEqual(screenshot3, screenshot, rect);
            }
        }
        public void ProgressRing_Visibility_Collapsed()
        {
            Run("UITests.Windows_UI_Xaml_Controls.ProgressRing.WindowsProgressRing_GH1220");

            var isVisible           = _app.Marked("isVisible");
            var visibilityTest      = _app.Marked("visibilityTest");
            var placeHolder         = _app.Marked("placeHolder");
            var collapsedTestBorder = _app.Marked("collapsedTestBorder");

            var placeholderRect         = _app.Query(placeHolder).First().Rect;
            var collapsedTestBorderRect = _app.Query(collapsedTestBorder).FirstOrDefault()?.Rect;

            Assert.AreEqual(0f, collapsedTestBorderRect?.Height ?? 0f);

            isVisible.SetDependencyPropertyValue("IsChecked", "True");

            collapsedTestBorderRect = _app.Query(collapsedTestBorder).First().Rect;
            Assert.AreNotEqual(0f, collapsedTestBorderRect.Height);

            var after = TakeScreenshot("after", new ScreenshotOptions()
            {
                IgnoreInSnapshotCompare = true
            });

            var visibilityTestRect = _app.Query(visibilityTest).First().Rect;

            ImageAssert.AreNotEqual(after, placeholderRect, after, visibilityTestRect);
        }
Exemplo n.º 7
0
        public void TextBox_Readonly_ShouldNotBringUpKeyboard()
        {
            Run("Uno.UI.Samples.UITests.TextBoxControl.TextBox_IsReadOnly");

            var target         = _app.Marked("txt");
            var readonlyToggle = _app.Marked("tglReadonly");             // default: checked

            // initial state
            _app.WaitForElement(target);
            using var screenshot1 = TakeScreenshot("textbox readonly", ignoreInSnapshotCompare: true);

            // remove readonly and focus textbox
            readonlyToggle.Tap();             // now: unchecked
            target.Tap();
            _app.Wait(seconds: 1);            // allow keyboard to fully open
            using var screenshot2 = TakeScreenshot("textbox focused with keyboard", ignoreInSnapshotCompare: true);

            // reapply readonly and try focus textbox
            readonlyToggle.Tap();             // now: checked
            target.Tap();
            _app.Wait(seconds: 1);            // allow keyboard to fully open (if ever possible)
            _app.WaitForElement(target);
            using var screenshot3 = TakeScreenshot("textbox readonly again", ignoreInSnapshotCompare: true);

            // the bottom half should only contains the keyboard and some blank space,
            // but not the textbox nor the toggle buttons that needs to be excluded.
            var screen         = _app.GetScreenDimensions();
            var bottomHalfRect = new Rectangle(
                0, (int)screen.Height / 2,
                (int)screen.Width, (int)screen.Height / 2
                );

            ImageAssert.AreNotEqual(screenshot1, screenshot2, bottomHalfRect);          // no keyboard != keyboard
            ImageAssert.AreEqual(screenshot1, screenshot3, bottomHalfRect);             // no keyboard == no keyboard
        }
Exemplo n.º 8
0
        [ActivePlatforms(Platform.Android, Platform.Browser)]         // Test authoring problem on iOS
        public void FlyoutTest_Simple_FlyoutsCanBeDismissed()
        {
            Run("Uno.UI.Samples.Content.UITests.Flyout.Flyout_Simple");

            var majorStepIndex        = 0;
            var testableFlyoutButtons = new string[]
            {
                "LeftFlyoutButton",
                "RightFlyoutButton",
                "BottomFlyoutButton",
                "TopFlyoutButton",
                //"FullFlyoutButton", // unclosable without native back button/gesture
                //"FullFlyoutButtonNoConstraint", // unclosable without native back button/gesture
                "CenteredFullFlyoutButton",
                //"FullOverlayFlyoutButton", // unclosable without native back button/gesture
                "WithOffsetFlyoutButton",
            }.ToDictionary(x => x, x => _app.Marked(x));

            // initial state
            _app.WaitForElement(testableFlyoutButtons.First().Value);
            using var initialScreenshot = TakeScreenshot($"{majorStepIndex++} Initial State", ignoreInSnapshotCompare: true);

            var dismissArea = GetDismissAreaCenter();

            foreach (var button in testableFlyoutButtons)
            {
                // show flyout
                button.Value.FastTap();
                using var flyoutOpenedScreenshot = TakeScreenshot($"{majorStepIndex} {button.Key} 0 Opened", ignoreInSnapshotCompare: true);

                // dismiss flyout
                _app.TapCoordinates(dismissArea.X, dismissArea.Y);
                _app.Wait(1);
                using var flyoutDismissedScreenshot = TakeScreenshot($"{majorStepIndex} {button.Key} 1 Dismissed", ignoreInSnapshotCompare: true);

                // compare
                ImageAssert.AreNotEqual(flyoutOpenedScreenshot, initialScreenshot);
                ImageAssert.AreEqual(flyoutDismissedScreenshot, initialScreenshot);

                majorStepIndex++;
            }

            (float X, float Y) GetDismissAreaCenter()
            {
                // the dismiss area is safe to click, since no flyout should block this area (except: FullFlyoutButton, FullOverlayFlyoutButton)

                /* [LeftFlyoutButton]
                 * ...
                 * [FullOverlayFlyoutButton]
                 *         (dismiss area)
                 *       [WithOffsetFlyoutButton margin=100] */
                var rect1 = _app.GetPhysicalRect("FullOverlayFlyoutButton");
                var rect2 = _app.GetPhysicalRect("WithOffsetFlyoutButton");

                return(rect2.CenterX + rect2.Width, (rect1.Bottom + rect2.Y) / 2);
            }
        }
Exemplo n.º 9
0
        public void ContentDialog_Simple_NotLightDismissible()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.ContentDialogTests.ContentDialog_Simple");

            var showDialogButton    = _app.Marked("showDialog1");
            var statusBarBackground = _app.Marked("statusBarBackground");
            var dialogSpace         = _app.Marked("DialogSpace");     // from ContentDialog default ControlTemplate
            var primaryButton       = _app.Marked("PrimaryButton");

            // initial state
            _app.WaitForElement(showDialogButton);
            var initialScreenshot = CurrentTestTakeScreenShot("0 Initial State");

            // open dialog
            _app.FastTap(showDialogButton);
            _app.WaitForElement(primaryButton);
            var dialogOpenedScreenshot = CurrentTestTakeScreenShot("1 ContentDialog Opened");

            // tapping outside of dialog
            var dialogRect = _app.GetRect(dialogSpace);

            _app.TapCoordinates(dialogRect.CenterX, dialogRect.Bottom + 50);
            var dialogStillOpenedScreenshot = CurrentTestTakeScreenShot("2 ContentDialog Still Opened");

            // close dialog
            _app.FastTap(primaryButton);
            _app.Wait(seconds: 1);
            var dialogClosedScreenshot = CurrentTestTakeScreenShot("3 ContentDialog Closed");

            // compare
            var comparableRect = GetOsComparableRect();

            ImageAssert.AreNotEqual(initialScreenshot, dialogOpenedScreenshot, comparableRect);
            ImageAssert.AreEqual(dialogOpenedScreenshot, dialogStillOpenedScreenshot, comparableRect);
            ImageAssert.AreNotEqual(dialogStillOpenedScreenshot, dialogClosedScreenshot, comparableRect);

            Rectangle?GetOsComparableRect()
            {
                if (AppInitializer.GetLocalPlatform() == Platform.Android)
                {
                    // the status bar area needs to be excluded for image comparison
                    var screen        = _app.GetScreenDimensions();
                    var statusBarRect = _app.GetRect(statusBarBackground);

                    return(new Rectangle(
                               0,
                               (int)statusBarRect.Height,
                               (int)screen.Width,
                               (int)screen.Height - (int)statusBarRect.Height
                               ));
                }
                else
                {
                    return(default);
Exemplo n.º 10
0
        private void Test(bool aboveEquals, bool belowEquals, [CallerMemberName] string test = null)
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.ComboBox.ComboBox_DropDownPlacement", skipInitialScreenshot: true);

            _app.WaitForElement(test);

            var rect = _app.GetPhysicalRect(test);

            using var notOpened = TakeScreenshot("not_opened", ignoreInSnapshotCompare: true);

            // Open the combo
            _app.TapCoordinates(rect.Right - 10, rect.CenterY);

            // Wait for popup to open
            _app.WaitForElement("PopupBorder");

            using var opened = TakeScreenshot("opened", ignoreInSnapshotCompare: true);

            // Make sure to close the combo
            _app.TapCoordinates(rect.X - 10, rect.Y - 10);

            // Assertions
            const int testHeight = 50;
            const int tolerance  = 10;            // Margins, etc
            var       above      = new Rectangle((int)rect.X, (int)rect.Y - testHeight - tolerance, (int)rect.Width, testHeight);
            var       below      = new Rectangle((int)rect.X, (int)rect.Bottom + tolerance, (int)rect.Width, testHeight);

            if (aboveEquals)
            {
                ImageAssert.AreEqual(notOpened, opened, above);
            }
            else
            {
                ImageAssert.AreNotEqual(notOpened, opened, above);
            }

            if (belowEquals)
            {
                // On Android the StatusBar may flicker when we open a ComboBox, so validate the
                ImageAssert.AreEqual(notOpened, opened, below);
            }
            else
            {
                ImageAssert.AreNotEqual(notOpened, opened, below);
            }
        }
Exemplo n.º 11
0
        public void PointMovement()
        {
            Run("SamplesApp.Windows_UI_Xaml_Media.Geometry.LineSegmentPage");

            var path   = _app.Marked("Path");
            var button = _app.Marked("MovePointButton");

            _app.WaitForElement(path);

            var before = TakeScreenshot("Before point movement");

            button.Tap();

            var after = TakeScreenshot("After point movement");

            ImageAssert.AreNotEqual(before, after);
        }
Exemplo n.º 12
0
        public void WriteableBitmap_Invalidate()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.ImageTests.ImageSourceWriteableBitmapInvalidate");

            // Request to render
            var button = _app.Marked("_update");

            _app.WaitForElement(button);

            var screenshotBefore = TakeScreenshot("WriteableBitmap_Invalidate - Before");

            button.FastTap();

            // Take screenshot
            var screenshotAfter = TakeScreenshot("WriteableBitmap_Invalidate - Result");

            ImageAssert.AreNotEqual(screenshotBefore, screenshotAfter);
        }
Exemplo n.º 13
0
        public void DatePickerFlyout_Native_HasContentTest()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.DatePicker.DatePicker_SampleContent", skipInitialScreenshot: true);

            var theDatePicker = _app.Marked("theDatePicker");

            _app.WaitForElement(theDatePicker);
            theDatePicker.SetDependencyPropertyValue("UseNativeStyle", "True");

            var datePickerFlyout = _app.CreateQuery(q => q.WithClass("Windows_UI_Xaml_Controls_DatePickerFlyoutPresenter"));

            theDatePicker.GetDependencyPropertyValue("Date");
            theDatePicker.GetDependencyPropertyValue("Date");

            using var screenshotNotOpened = TakeScreenshot("NotOpenedPicker", ignoreInSnapshotCompare: true);

            // Open flyout
            theDatePicker.Tap();

            if (Helpers.Platform == Platform.Android)
            {
                // On Android, the presenter is not part of the visual tree
                theDatePicker.GetDependencyPropertyValue("Date");
                theDatePicker.GetDependencyPropertyValue("Date");
            }
            else
            {
                _app.WaitForElement(datePickerFlyout);

                _app.WaitForDependencyPropertyValue(datePickerFlyout, "Content",
                                                    "Windows.UI.Xaml.Controls.DatePickerSelector");
            }

            using var screenshotOpened = TakeScreenshot("OpenedPicker");

            ImageAssert.AreNotEqual(screenshotNotOpened, screenshotOpened);

            _app.Marked("btn").Tap();

            using var screenshotClosed = TakeScreenshot("ClosedPicker", ignoreInSnapshotCompare: true);

            ImageAssert.AreEqual(screenshotNotOpened, screenshotClosed);
        }
Exemplo n.º 14
0
        [ActivePlatforms(Platform.Browser)]         // Only WASM supports mouse-based tests for now
        public void ToolTip_Large_Text()
        {
            Run("UITests.Windows_UI_Xaml_Controls.ToolTip.ToolTip_Long_Text");

            const string ButtonWithTooltip   = "ButtonWithTooltip";
            const string BorderInsideToolTip = "BorderInsideToolTip";

            _app.WaitForElement(ButtonWithTooltip);
            var buttonRect = _app.GetRect(ButtonWithTooltip);

            var upperRect = _app.GetRect("UpperLocator");
            var lowerRect = _app.GetRect("LowerLocator");

            using var before = TakeScreenshot("Before", ignoreInSnapshotCompare: true);

            var lowerHoverY = buttonRect.Bottom - buttonRect.Height / 10;

            _app.TapCoordinates(buttonRect.CenterX, lowerHoverY);

            _app.WaitForElement(BorderInsideToolTip);

            using var lowerToolTip = TakeScreenshot("Lower ToolTip");

            ImageAssert.AreEqual(before, lowerToolTip, lowerRect);
            ImageAssert.AreEqual(before, lowerToolTip, upperRect);             // ToolTip should be just above mouse, shouldn't extend above Button bounds
            ImageAssert.AreNotEqual(before, lowerToolTip, buttonRect);

            _app.FastTap("DummyButton");

            _app.WaitForNoElement(BorderInsideToolTip);

            var upperHoverY = buttonRect.Y + buttonRect.Height / 10;

            _app.TapCoordinates(buttonRect.CenterX, upperHoverY);

            _app.WaitForElement(BorderInsideToolTip);

            using var upperToolTip = TakeScreenshot("Upper ToolTip");

            ImageAssert.AreEqual(before, upperToolTip, lowerRect);
            ImageAssert.AreNotEqual(before, upperToolTip, upperRect);             // Mouse is close to top of button, ToolTip should extend above Button bounds
            ImageAssert.AreNotEqual(before, upperToolTip, buttonRect);
        }
Exemplo n.º 15
0
        public void When_Foreground_Brush_Color_Changed()
        {
            Run("Uno.UI.Samples.Content.UITests.TextBlockControl.TextBlock_BrushColorChanging");

            var textColor = _app.Marked("textColor");

            var rectBefore         = _app.GetRect("textResult");
            var beforeColorChanged = TakeScreenshot("beforeColor");

            textColor.SetDependencyPropertyValue("Text", "Blue");

            var afterColorChanged = TakeScreenshot("afterColor");

            ImageAssert.AreNotEqual(afterColorChanged, beforeColorChanged);

            var scale = (float)GetDisplayScreenScaling();

            ImageAssert.HasColorAt(afterColorChanged, (rectBefore.X + 10) * scale, (rectBefore.Y + 10) * scale, Color.Blue);
        }
Exemplo n.º 16
0
        [ActivePlatforms(Platform.Android, Platform.iOS)]         // This should be enabled for WASM once it no longer uses the LEGACY_SHAPE_MEASURE code path
        public void When_GradientStops_Changed()
        {
            Run("UITests.Windows_UI_Xaml_Media.GradientBrushTests.LinearGradientBrush_Change_Stops");

            var rectangle = _app.Marked("GradientBrushRectangle");

            _app.WaitForElement(rectangle);

            var screenRect = _app.GetRect(rectangle);

            var before = TakeScreenshot("Before");

            _app.FastTap("ChangeBrushButton");

            _app.WaitForText("StatusTextBlock", "Changed");

            var after = TakeScreenshot("After");

            ImageAssert.AreNotEqual(before, after, screenRect);
        }
Exemplo n.º 17
0
        public void When_Foreground_Brush_Color_Changed()
        {
            Run("Uno.UI.Samples.Content.UITests.TextBlockControl.TextBlock_BrushColorChanging");

            var textColor = _app.Marked("textColor");

            var rect   = _app.GetPhysicalRect("textResult");
            var xCheck = rect.CenterX;
            var yCheck = rect.CenterY;

            using var beforeColorChanged = TakeScreenshot("beforeColor", ignoreInSnapshotCompare: true);
            ImageAssert.HasColorAt(beforeColorChanged, xCheck, yCheck, Color.Red);

            textColor.SetDependencyPropertyValue("Text", "Blue");

            using var afterColorChanged = TakeScreenshot("afterColor");

            ImageAssert.AreNotEqual(afterColorChanged, beforeColorChanged);

            ImageAssert.HasColorAt(afterColorChanged, xCheck, yCheck, Color.Blue);
        }
Exemplo n.º 18
0
        [ActivePlatforms(Platform.Browser)]         // Only applicable for mouse input since we're testing mouse-over state
        public void ScrollViewer_Fluent_ScrollBar_Appears()
        {
            Run("UITests.Windows_UI_Xaml_Controls.ScrollViewerTests.ScrollViewer_Fluent");

            _app.WaitForElement("ScrollViewerVisibilityCheckBox");

            _app.FastTap("ScrollViewerVisibilityCheckBox");

            _app.WaitForText("ScrollViewerVisibilityTextBlock", "True");

            var rect = _app.GetPhysicalRect("HostBorder");

            using var noScrollIndicator = TakeScreenshot("No scroll indicators");

            _app.FastTap("ButtonInScrollViewer");             // Put pointer over ScrollViewer so scroll bars appear

            _app.WaitForText("ButtonStatusTextBlock", "Clicked");

            using var scrollIndicator = TakeScreenshot("Scroll indicators visible");             // If this takes a *really* long time the scroll indicators might have
            // disappeared already... hopefully that doesn't happen

            ImageAssert.AreNotEqual(noScrollIndicator, scrollIndicator, rect);
        }
Exemplo n.º 19
0
        [ActivePlatforms(Platform.iOS, Platform.Android)]         // IsIntermediate is not supported on Wasm yet
        public void ScrollViewer_Clipping()
        {
            Run("UITests.Windows_UI_Xaml_Controls.ScrollViewerTests.ScrollViewer_Clipping");

            var sut          = _app.WaitForElement(_app.Marked("scrollViewer1")).Single();
            var updateButton = _app.Marked("UpdateButton");

            var updateButtonRect = _app.WaitForElement(_app.Marked("intentionallyBlank")).Single().Rect;

            updateButton.FastTap();

            //Drag upward
            _app.DragCoordinates(sut.Rect.CenterX, sut.Rect.CenterY, sut.Rect.CenterX, sut.Rect.CenterY - (sut.Rect.Height / 2));

            using var res = TakeScreenshot("Result", ignoreInSnapshotCompare: true);

            ImageAssert.AreNotEqual(
                expected: res,
                expectedRect: new Rectangle((int)sut.Rect.X, (int)sut.Rect.Bottom - 20, (int)updateButtonRect.Width, (int)updateButtonRect.Height),
                actual: res,
                actualRect: new Rectangle((int)updateButtonRect.X, (int)updateButtonRect.Y, (int)updateButtonRect.Width, (int)updateButtonRect.Height)
                );
        }
Exemplo n.º 20
0
        public async Task When_TextDecoration_Changed()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.TextBlockControl.TextBlock_Decorations");

            var text01 = _app.Marked("text01");
            var text02 = _app.Marked("text02");

            using var before = TakeScreenshot("Before", ignoreInSnapshotCompare: true);

            text01.SetDependencyPropertyValue("TextDecorations", "1");             // Underline
            text02.SetDependencyPropertyValue("TextDecorations", "2");             // Strikethrough

            using var after = TakeScreenshot("Updated");

            ImageAssert.AreNotEqual(before, after);

            text01.SetDependencyPropertyValue("TextDecorations", "0");             // None
            text02.SetDependencyPropertyValue("TextDecorations", "0");             // None

            using var restored = TakeScreenshot("Restored");

            ImageAssert.AreEqual(before, restored);
        }
Exemplo n.º 21
0
        private void TestTransformsFinalState([CallerMemberName] string testName = null)
        {
            var match = Regex.Match(testName, @"When_Transforms_(?<type>\w+)_With_FillBehavior(?<fill>\w+)_Then_(?<expected>\w+)");

            if (!match.Success)
            {
                throw new InvalidOperationException("Invalid test name.");
            }

            var type     = match.Groups["type"].Value;
            var fill     = match.Groups["fill"].Value;
            var expected = match.Groups["expected"].Value;

            int expectedDelta, tolerance = 0;

            switch (type)
            {
            case "Completed" when expected == "Hold":
                expectedDelta = 150;
                break;

            case "Completed" when expected == "Rollback":
                expectedDelta = 0;
                break;

            case "Paused":
                expectedDelta = 150 / 2;
                tolerance     = 50;                     // We only want to validate that the element is not at 0 or 150
                break;

            case "Canceled":
                expectedDelta = 0;
                break;

            default:
                throw new InvalidOperationException("Invalid test name.");
            }

            Run(_finalStateTransformsTestControl, skipInitialScreenshot: true);

            var initial         = TakeScreenshot("Initial", ignoreInSnapshotCompare: true);
            var initialLocation = _app.WaitForElement($"{type}AnimationHost_{fill}").Single().Rect;

            var scale = ((int)initialLocation.Width) / 50;

            expectedDelta *= scale;
            tolerance     *= scale;

            _app.Marked("StartButton").FastTap();
            _app.WaitForDependencyPropertyValue(_app.Marked("Status"), "Text", "Completed");

            // Assert
            var final         = TakeScreenshot("Final", ignoreInSnapshotCompare: true);
            var finalLocation = _app.WaitForElement($"{type}AnimationHost_{fill}").Single().Rect;
            var actualDelta   = finalLocation.Y - initialLocation.Y;

            // For some reason, the finalLocation might not reflect the effective location of the control,
            // instead we rely on pixel validation ...
            // Assert.IsTrue(Math.Abs(actualDelta - expectedDelta) <= tolerance);
            if (expectedDelta > 0)
            {
                ImageAssert.AreNotEqual(initial, final, initialLocation);
            }
            else
            {
                ImageAssert.AreEqual(initial, final, initialLocation);
            }
        }
        private void TestOpacityFinalState([CallerMemberName] string testName = null)
        {
            var match = Regex.Match(testName, @"When_Opacity_(?<type>\w+)_With_FillBehavior(?<fill>\w+)_Then_(?<expected>\w+)");

            if (!match.Success)
            {
                throw new InvalidOperationException("Invalid test name.");
            }

            var type     = match.Groups["type"].Value;
            var fill     = match.Groups["fill"].Value;
            var expected = match.Groups["expected"].Value;

            bool isSame = false, isGray = false, isDifferent = false;

            switch (type)
            {
            case "Completed" when expected == "Hold":
                isGray = true;
                break;

            case "Completed" when expected == "Rollback":
                isSame = true;
                break;

            case "Paused":
                isDifferent = true;
                break;

            case "Canceled":
                isSame = true;
                break;

            default:
                throw new InvalidOperationException("Invalid test name.");
            }

            Run(_finalStateOpacityTestControl, skipInitialScreenshot: true);

            using var initial = TakeScreenshot("Initial", ignoreInSnapshotCompare: true);
            var element = _app.WaitForElement($"{type}AnimationHost_{fill}").Single().Rect;

            _app.Marked("StartButton").FastTap();
            _app.WaitForDependencyPropertyValue(_app.Marked("Status"), "Text", "Completed");

            // Assert
            using var final = TakeScreenshot("Final", ignoreInSnapshotCompare: true);

            if (isSame)
            {
                ImageAssert.AreEqual(initial, final, element);
            }
            else if (isGray)
            {
                ImageAssert.HasColorAt(final, element.CenterX, element.CenterY, Color.LightGray);
            }
            else if (isDifferent)
            {
                ImageAssert.AreNotEqual(initial, final, element);
                ImageAssert.DoesNotHaveColorAt(final, element.CenterX, element.CenterY, Color.LightGray);
            }
        }