예제 #1
0
        public void PopupWithOverlay()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.Popup.Popup_Overlay_On");

            var before = TakeScreenshot("Before");
            var rect   = _app.GetRect("LocatorRectangle");

            ImageAssert.HasColorAt(before, rect.CenterX, rect.CenterY, Color.Blue);

            _app.Tap("PopupCheckBox");

            _app.WaitForElement("PopupChild");

            var during = TakeScreenshot("During", ignoreInSnapshotCompare: AppInitializer.GetLocalPlatform() == Platform.Android /*Status bar appears with clock*/);

            ImageAssert.AssertDoesNotHaveColorAt(during, rect.CenterX, rect.CenterY, Color.Blue);

            // Dismiss popup
            var screenRect = _app.Marked("sampleContent").FirstResult().Rect;

            _app.TapCoordinates(10, screenRect.Bottom - 10);

            _app.WaitForNoElement("PopupChild");

            var after = TakeScreenshot("After");

            ImageAssert.HasColorAt(after, rect.CenterX, rect.CenterY, Color.Blue);
        }
예제 #2
0
        public void Verify_Canvas_ZIndex()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.Canvas.Canvas_ZIndex");

            var screenshot = TakeScreenshot("Rendered");

            var redBorderRect1 = _app.GetRect("CanvasBorderRed1");

            ImageAssert.HasColorAt(screenshot, redBorderRect1.CenterX, redBorderRect1.CenterY, Color.Green /*psych*/);
            var redBorderRect2 = _app.GetRect("CanvasBorderRed2");

            ImageAssert.HasColorAt(screenshot, redBorderRect2.CenterX, redBorderRect2.CenterY, Color.Green /*psych*/);

            if (AppInitializer.GetLocalPlatform() != Platform.Android)             // Android doesn't support Canvas.ZIndex on any panel
            {
                var redBorderRect3 = _app.GetRect("CanvasBorderRed3");
                ImageAssert.HasColorAt(screenshot, redBorderRect3.CenterX, redBorderRect3.CenterY, Color.Green /*psych*/);
            }

            var greenBorderRect1 = _app.GetRect("CanvasBorderGreen1");

            ImageAssert.HasColorAt(screenshot, greenBorderRect1.CenterX, greenBorderRect1.CenterY, Color.Brown);
            ImageAssert.HasColorAt(screenshot, greenBorderRect1.Right - 1, greenBorderRect1.CenterY, Color.Blue);
            var greenBorderRect2 = _app.GetRect("CanvasBorderGreen2");

            ImageAssert.HasColorAt(screenshot, greenBorderRect2.CenterX, greenBorderRect2.CenterY, Color.Brown);
            ImageAssert.HasColorAt(screenshot, greenBorderRect2.Right - 1, greenBorderRect2.CenterY, Color.Blue);

            if (AppInitializer.GetLocalPlatform() != Platform.Android)             // Android doesn't support Canvas.ZIndex on any panel
            {
                var CanvasBorderGreen3 = _app.GetRect("CanvasBorderGreen3");
                ImageAssert.HasColorAt(screenshot, CanvasBorderGreen3.CenterX, CanvasBorderGreen3.CenterY, Color.Brown);
                ImageAssert.HasColorAt(screenshot, CanvasBorderGreen3.Right - 1, CanvasBorderGreen3.CenterY, Color.Blue);
            }
        }
예제 #3
0
        public void FlyoutTest_Target()
        {
            Run("Uno.UI.Samples.Content.UITests.Flyout.Flyout_Target");

            var result       = _app.Marked("result");
            var innerContent = _app.Marked("innerContent");
            var target1      = _app.Marked("target1");
            var target2      = _app.Marked("target2");
            var flyoutFull   = _app.Marked("flyoutFull");

            _app.WaitForElement(result);

            {
                var target1Result = _app.WaitForElement(target1).First();

                _app.FastTap(target1);

                var innerContentResult = _app.WaitForElement(innerContent).First();

                Assert.IsTrue(target1Result.Rect.X <= innerContentResult.Rect.X);
                Assert.IsTrue(target1Result.Rect.Width > innerContentResult.Rect.Width);

                _app.TapCoordinates(50, 100);
            }

            {
                var target2Result = _app.WaitForElement(target2).First();

                _app.FastTap(target2);

                var innerContentResult = _app.WaitForElement(innerContent).First();

                Assert.IsTrue(target2Result.Rect.X <= innerContentResult.Rect.X);
                Assert.IsTrue(target2Result.Rect.Width > innerContentResult.Rect.Width);

                _app.TapCoordinates(50, 100);
            }

            {
                _app.FastTap(flyoutFull);

                var innerContentResult = _app.WaitForElement(innerContent).First();

                var rect = base.GetScreenDimensions();

                Assert.AreEqual(innerContentResult.Rect.CenterX, rect.CenterX, 1);

                if (AppInitializer.GetLocalPlatform() == Platform.Browser)
                {
                    // Flyout positioning does not take proper app bar positioning yet.
                    Assert.AreEqual(innerContentResult.Rect.CenterY, rect.CenterY, 1);
                }

                _app.TapCoordinates(10, 100);
            }
        }
예제 #4
0
        private QueryEx QueryAll(string name)
        {
            IAppQuery AllQuery(IAppQuery query)
            // TODO: .All() is not yet supported for wasm.
            => AppInitializer.GetLocalPlatform() == Platform.Browser ? query : query.All();

            Query allQuery = q => AllQuery(q).Marked(name);

            return(new QueryEx(allQuery));
        }
예제 #5
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);
예제 #6
0
        public void DatePicker_Flyout()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.DatePicker.DatePickerFlyout_Automated", skipInitialScreenshot: true);

            //DatePicker is broken: https://github.com/unoplatform/uno/issues/188
            //Using a Button with DatePickerFlyout to simulate a DatePicker
            var button = _app.Marked("TestDatePickerFlyoutButton");

            _app.WaitForElement(button);

            button.FastTap();

            TakeScreenshot("DatePicker - Flyout", ignoreInSnapshotCompare: AppInitializer.GetLocalPlatform() == Platform.Android /*Status bar appears with clock*/);

            _app.TapCoordinates(20, 20);
        }
예제 #7
0
        [ActivePlatforms(Platform.Android, Platform.iOS)]         // We cannot test right button click on WASM yet
        public void When_InListViewWithItemClick()
        {
            Run(_xamlTestPage);

            const string targetName = "ListViewWithItemClick";

            // Scroll a bit in the ListView
            var target = _app.WaitForElement(targetName).Single().Rect;

            _app.DragCoordinates(target.CenterX, target.Bottom - 3, target.CenterX, target.Y + 3);

            // Tap and hold an item
            _app.TouchAndHoldCoordinates(target.CenterX, target.CenterY - 5);

            var result       = GestureResult.Get(_app.Marked("LastRightTapped"));
            var expectedItem = AppInitializer.GetLocalPlatform() == Platform.Browser
                                ? "none" // Long press not supported with mouse
                                : "Item_3";

            result.Element.Should().Be(expectedItem);
        }
예제 #8
0
        public void When_InListViewWithoutItemClick()
        {
            Run(_xamlTestPage);

            const string targetName = "ListViewWithoutItemClick";

            // Scroll a bit in the ListView
            var target = _app.WaitForElement(targetName).Single().Rect;

            _app.DragCoordinates(target.CenterX, target.Bottom - 3, target.CenterX, target.Y + 3);

            // Tap and hold an item
            _app.TapCoordinates(target.CenterX, target.CenterY - 5);

            var result       = GestureResult.Get(_app.Marked("LastTapped"));
            var expectedItem = AppInitializer.GetLocalPlatform() == Platform.Browser
                                ? "Item_1" // We were not able to scroll on WASM!
                                : "Item_3";

            result.Element.Should().Be(expectedItem);
        }
예제 #9
0
        public void MenuFlyoutItem_ClickTest()
        {
            Run("UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutItemTests.MenuFlyoutItem_Click");

            _app.WaitForElement(_app.Marked("mfiButton"));

            TakeScreenshot("Initial");

            // step 1: press button to show menu
            _app.Tap(_app.Marked("mfiButton"));

            TakeScreenshot("menuShown", ignoreInSnapshotCompare: AppInitializer.GetLocalPlatform() == Platform.Android /*Menu animation is midflight*/);

            // step 2: click MenuFlyoutItem
            _app.Tap(_app.Marked("mfiItem"));

            // step 3: check result
            _app.WaitForText(_app.Marked("mfiResult"), "success");

            TakeScreenshot("AfterSuccess", ignoreInSnapshotCompare: AppInitializer.GetLocalPlatform() == Platform.Android /*Status bar appears with clock*/);
        }
예제 #10
0
 private ScreenshotInfo CurrentTestTakeScreenShot(string name) =>
 // Screenshot taking for this fixture is disabled on Android because of the
 // presence of the status bar when native popups are opened, adding the clock
 // (that is always changing :)).
 TakeScreenshot(name, ignoreInSnapshotCompare: AppInitializer.GetLocalPlatform() == Platform.Android);
예제 #11
0
        // [Timeout(3000000)] // Timeout is now moved to individual platorms runners configuration in CI
        public async Task RunRuntimeTests()
        {
            Run("SamplesApp.Samples.UnitTests.UnitTestsPage");

            IAppQuery AllQuery(IAppQuery query)
            // .All() is not yet supported for wasm.
            => AppInitializer.GetLocalPlatform() == Platform.Browser ? query : query.All();

            var runButton          = new QueryEx(q => AllQuery(q).Marked("runButton"));
            var failedTests        = new QueryEx(q => AllQuery(q).Marked("failedTests"));
            var failedTestsDetails = new QueryEx(q => AllQuery(q).Marked("failedTestDetails"));
            var unitTestsControl   = new QueryEx(q => AllQuery(q).Marked("UnitTestsRootControl"));

            async Task <bool> IsTestExecutionDone()
            {
                return(await GetWithRetry("IsTestExecutionDone", () => unitTestsControl.GetDependencyPropertyValue("RunningStateForUITest")?.ToString().Equals("Finished", StringComparison.OrdinalIgnoreCase) ?? false));
            }

            _app.WaitForElement(runButton);

            _app.FastTap(runButton);

            var lastChange = DateTimeOffset.Now;
            var lastValue  = "";

            while (DateTimeOffset.Now - lastChange < TestRunTimeout)
            {
                var newValue = await GetWithRetry("GetRunTestCount", () => unitTestsControl.GetDependencyPropertyValue("RunTestCountForUITest")?.ToString());

                if (lastValue != newValue)
                {
                    lastChange = DateTimeOffset.Now;
                }

                await Task.Delay(TimeSpan.FromSeconds(.5));

                if (await IsTestExecutionDone())
                {
                    break;
                }
            }

            if (!await IsTestExecutionDone())
            {
                Assert.Fail("A test run timed out");
            }

            TestContext.AddTestAttachment(ArchiveResults(unitTestsControl), "runtimetests-results.zip");

            var count = GetValue(nameof(unitTestsControl), unitTestsControl, "FailedTestCountForUITest");

            if (count != "0")
            {
                var tests = GetValue(nameof(failedTests), failedTests)
                            .Split(new char[] { '§' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select((x, i) => $"\t{i + 1}. {x}\n")
                            .ToArray();
                var details = GetValue(nameof(failedTestsDetails), failedTestsDetails);

                Assert.Fail($"{tests.Length} unit test(s) failed (count={count}).\n\tFailing Tests:\n{string.Join("", tests)}\n\n---\n\tDetails:\n{details}");
            }

            TakeScreenshot("Runtime Tests Results", ignoreInSnapshotCompare: true);
        }
예제 #12
0
        [Timeout(2000000)]         // Adjust this timeout based on average test run duration
        public async Task RunBenchmarks()
        {
            Run("Benchmarks.Shared.Controls.BenchmarkDotNetTestsPage");

            IAppQuery AllQuery(IAppQuery query)
            // .All() is not yet supported for wasm.
            => AppInitializer.GetLocalPlatform() == Platform.Browser ? query : query.All();

            var runButton        = new QueryEx(q => AllQuery(q).Marked("runButton"));
            var runStatus        = new QueryEx(q => AllQuery(q).Marked("runStatus"));
            var runCount         = new QueryEx(q => AllQuery(q).Marked("runCount"));
            var benchmarkControl = new QueryEx(q => AllQuery(q).Marked("benchmarkControl"));

            bool IsTestExecutionDone()
            {
                try
                {
                    var text = runStatus.GetDependencyPropertyValue("Text")?.ToString();
                    var r2   = text?.Equals("Finished", StringComparison.OrdinalIgnoreCase) ?? false;

                    Console.WriteLine($"IsTestExecutionDone: {text} {r2}");

                    return(r2);
                }
                catch
                {
                    Console.WriteLine("Skip IsTestExecutionDone");

                    // Skip exceptions as they may be timeouts
                    return(false);
                }
            }

            _app.WaitForElement(runButton);

            TakeScreenshot("Begin", ignoreInSnapshotCompare: true);

            _app.FastTap(runButton);

            var lastChange = DateTimeOffset.Now;
            var lastValue  = "";

            while (DateTimeOffset.Now - lastChange < TestRunTimeout)
            {
                try
                {
                    if (IsTestExecutionDone())
                    {
                        break;
                    }

                    var newValue = runCount.GetDependencyPropertyValue("Text")?.ToString();

                    if (lastValue != newValue)
                    {
                        Console.WriteLine($"Loop: Test changed now:{DateTimeOffset.Now} lastChange: {lastChange}");

                        lastChange = DateTimeOffset.Now;
                        TakeScreenshot($"Run {newValue}", ignoreInSnapshotCompare: true);
                    }
                }
                catch (Exception e)
                {
                    // Skip exceptions as they may be timeouts
                }

                await Task.Delay(TimeSpan.FromSeconds(.5));

                Console.WriteLine($"Loop: now:{DateTimeOffset.Now} lastChange: {lastChange}");
            }

            if (!IsTestExecutionDone())
            {
                Assert.Fail("A test run timed out");
            }

            var finalFile = ArchiveResults(benchmarkControl);

            TestContext.AddTestAttachment(finalFile, "benchmark-results.zip");

            TakeScreenshot("Runtime Tests Results", ignoreInSnapshotCompare: true);
        }
예제 #13
0
        public void BasicExpressionTest()
        {
            Run("UITests.Shared.Microsoft_UI_Xaml_Controls.NumberBoxTests.MUX_Test");

            var currentPlatform = AppInitializer.GetLocalPlatform();

            // Use the .All() so the Query returns the TextBox even if covered by the keyboard, until Uno.UITest
            // supports it for Browsers.
            var supportsAllQuery = currentPlatform == Platform.Android || currentPlatform == Platform.iOS;

            var numBox = supportsAllQuery
                                ? new QueryEx(q => q.All().Marked("TestNumberBox"))
                                : _app.Marked("TestNumberBox");

            _app.EnterText(numBox, "5 + 3");
            Assert.AreEqual("0", numBox.GetText());

            _app.Tap("ExpressionCheckBox");

            int          numErrors  = 0;
            const double resetValue = double.NaN;

            Dictionary <string, double> expressions = new Dictionary <string, double>
            {
                // Valid expressions. None of these should evaluate to the reset value.
                { "5", 5 },
                { "-358", -358 },
                { "12.34", 12.34 },
                { "5 + 3", 8 },
                { "12345 + 67 + 890", 13302 },
                { "000 + 0011", 11 },
                { "5 - 3 + 2", 4 },
                { "3 + 2 - 5", 0 },
                { "9 - 2 * 6 / 4", 6 },
                { "9 - -7", 16 },
                { "9-3*2", 3 },                         // no spaces
                { " 10  *   6  ", 60 },                 // extra spaces
                { "10 /( 2 + 3 )", 2 },
                { "5 * -40", -200 },
                { "(1 - 4) / (2 + 1)", -1 },
                { "3 * ((4 + 8) / 2)", 18 },
                { "23 * ((0 - 48) / 8)", -138 },
                { "((74-71)*2)^3", 216 },
                { "2 - 2 ^ 3", -6 },
                { "2 ^ 2 ^ 2 / 2 + 9", 17 },
                { "5 ^ -2", 0.04 },
                { "5.09 + 14.333", 19.423 },
                { "2.5 * 0.35", 0.875 },
                { "-2 - 5", -7 },                       // begins with negative number
                { "(10)", 10 },                         // number in parens
                { "(-9)", -9 },                         // negative number in parens
                { "0^0", 1 },                           // who knew?

                // These should not parse, which means they will reset back to the previous value.
                { "5x + 3y", resetValue },                        // invalid chars
                { "5 + (3", resetValue },                         // mismatched parens
                { "9 + (2 + 3))", resetValue },
                { "(2 + 3)(1 + 5)", resetValue },                 // missing operator
                { "9 + + 7", resetValue },                        // extra operators
                { "9 - * 7", resetValue },
                { "9 - - 7", resetValue },
                { "+9", resetValue },
                { "1 / 0", resetValue },                          // divide by zero

                // These don't currently work, but maybe should.
                { "-(3 + 5)", resetValue },                 // negative sign in front of parens -- should be -8
            };

            foreach (KeyValuePair <string, double> pair in expressions)
            {
                numBox.ClearText();
                numBox.EnterText(pair.Key);
                _app.PressEnter();

                var    value  = numBox.GetDependencyPropertyValue <double>("Value");
                string output = "Expression '" + pair.Key + "' - expected: " + pair.Value + ", actual: " + value;
                if (Math.Abs(pair.Value - value) > 0.00001)
                {
                    numErrors++;
                    Console.WriteLine(output);
                }
                else
                {
                    Console.WriteLine(output);
                }
            }

            Assert.AreEqual(0, numErrors);
        }
예제 #14
0
 private static string GetReddish() =>
 AppInitializer.GetLocalPlatform() switch
 {
예제 #15
0
        [Timeout(7200000)]         // Adjust this timeout based on average test run duration
        public async Task RunRuntimeTests()
        {
            Run("SamplesApp.Samples.UnitTests.UnitTestsPage");

            IAppQuery AllQuery(IAppQuery query)
            // .All() is not yet supported for wasm.
            => AppInitializer.GetLocalPlatform() == Platform.Browser ? query : query.All();

            var runButton        = new QueryEx(q => AllQuery(q).Marked("runButton"));
            var failedTestsCount = new QueryEx(q => AllQuery(q).Marked("failedTestCount"));
            var failedTests      = new QueryEx(q => AllQuery(q).Marked("failedTests"));
            var runningState     = new QueryEx(q => AllQuery(q).Marked("runningState"));
            var runTestCount     = new QueryEx(q => AllQuery(q).Marked("runTestCount"));
            var unitTestsControl = new QueryEx(q => AllQuery(q).Marked("UnitTestsRootControl"));

            async Task <bool> IsTestExecutionDone()
            {
                var       sw            = Stopwatch.StartNew();
                Exception lastException = null;

                do
                {
                    try
                    {
                        return(runningState.GetDependencyPropertyValue("Text")?.ToString().Equals("Finished", StringComparison.OrdinalIgnoreCase) ?? false);
                    }
                    catch (Exception e)
                    {
                        lastException = e;
                        Console.WriteLine($"IsTestExecutionDone failed with {e.Message}");
                    }

                    await Task.Delay(TimeSpan.FromSeconds(.5));

                    Console.WriteLine($"IsTestExecutionDone retrying");
                }while (sw.Elapsed < TimeSpan.FromSeconds(10));

                throw lastException;
            }

            _app.WaitForElement(runButton);

            _app.FastTap(runButton);

            var lastChange = DateTimeOffset.Now;
            var lastValue  = "";

            while (DateTimeOffset.Now - lastChange < TestRunTimeout)
            {
                var newValue = runTestCount.GetDependencyPropertyValue("Text")?.ToString();

                if (lastValue != newValue)
                {
                    lastChange = DateTimeOffset.Now;
                }

                await Task.Delay(TimeSpan.FromSeconds(.5));

                if (await IsTestExecutionDone())
                {
                    break;
                }
            }

            if (!await IsTestExecutionDone())
            {
                Assert.Fail("A test run timed out");
            }

            TestContext.AddTestAttachment(ArchiveResults(unitTestsControl), "runtimetests-results.zip");

            var count = failedTestsCount.GetDependencyPropertyValue("Text").ToString();

            if (count != "0")
            {
                var tests = failedTests.GetDependencyPropertyValue <string>("Text")
                            .Split(new char[] { '§' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select((x, i) => $"\t{i + 1}. {x}\n")
                            .ToArray();

                var details = _app.Marked("failedTestDetails").GetDependencyPropertyValue("Text");

                Assert.Fail(
                    $"{tests.Length} unit test(s) failed.\n\tFailing Tests:\n{string.Join("", tests)}\n\n---\n\tDetails:\n{details}");
            }

            TakeScreenshot("Runtime Tests Results", ignoreInSnapshotCompare: true);
        }
예제 #16
0
        [Timeout(600000)]         // Adjust this timeout based on average test run duration
        public async Task RunRuntimeTests()
        {
            Run("SamplesApp.Samples.UnitTests.UnitTestsPage");

            IAppQuery AllQuery(IAppQuery query)
            // .All() is not yet supported for wasm.
            => AppInitializer.GetLocalPlatform() == Platform.Browser ? query : query.All();

            var runButton        = new QueryEx(q => AllQuery(q).Marked("runButton"));
            var failedTestsCount = new QueryEx(q => AllQuery(q).Marked("failedTestCount"));
            var failedTests      = new QueryEx(q => AllQuery(q).Marked("failedTests"));
            var runningState     = new QueryEx(q => AllQuery(q).Marked("runningState"));
            var runTestCount     = new QueryEx(q => AllQuery(q).Marked("runTestCount"));

            bool IsTestExecutionDone()
            => runningState.GetDependencyPropertyValue("Text")?.ToString().Equals("Finished", StringComparison.OrdinalIgnoreCase) ?? false;

            _app.WaitForElement(runButton);

            _app.FastTap(runButton);

            var lastChange = DateTimeOffset.Now;
            var lastValue  = "";

            while (DateTimeOffset.Now - lastChange < TestRunTimeout)
            {
                var newValue = runTestCount.GetDependencyPropertyValue("Text")?.ToString();

                if (lastValue != newValue)
                {
                    lastChange = DateTimeOffset.Now;
                }

                await Task.Delay(TimeSpan.FromSeconds(.5));

                if (IsTestExecutionDone())
                {
                    break;
                }
            }

            if (!IsTestExecutionDone())
            {
                Assert.Fail("A test run timed out");
            }

            var count = failedTestsCount.GetDependencyPropertyValue("Text").ToString();

            if (count != "0")
            {
                var tests = failedTests.GetDependencyPropertyValue <string>("Text")
                            .Split(new char[] { '§' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select((x, i) => $"\t{i + 1}. {x}\n")
                            .ToArray();

                var details = _app.Marked("failedTestDetails").GetDependencyPropertyValue("Text");

                Assert.Fail(
                    $"{tests.Length} unit test(s) failed.\n\tFailing Tests:\n{string.Join("", tests)}\n\n---\n\tDetails:\n{details}");
            }

            TakeScreenshot("Runtime Tests Results", ignoreInSnapshotCompare: true);
        }
예제 #17
0
        public void Default_StrokeThickness()
        {
            const string red     = "#FF0000";
            const string reddish = "#FF8080";

            var shapeExpectations = new[]
            {
                new ShapeExpectation
                {
                    Name    = "MyLine",
                    Offsets = new [] { 0, 0, 0, 0 },
                    Colors  = red,
                },
                new ShapeExpectation
                {
                    Name    = "MyRect",
                    Offsets = new [] { 0, 0, -1, -1 },
                    Colors  = red,
                },
                new ShapeExpectation
                {
                    Name    = "MyPolyline",
                    Offsets = new [] { 2, 2, -1, -1 },
                    Colors  = AppInitializer.GetLocalPlatform() == Platform.Browser ? reddish : red,
                },
                new ShapeExpectation
                {
                    Name    = "MyPolygon",
                    Offsets = new [] { 2, 2, -1, -1 },
                    Colors  = AppInitializer.GetLocalPlatform() == Platform.Browser ? reddish : red,
                },
                new ShapeExpectation
                {
                    Name    = "MyEllipse",
                    Offsets = new [] { 0, 0, -1, -1 },
                    Colors  = red,
                },
                new ShapeExpectation
                {
                    Name    = "MyPath",
                    Offsets = new [] { 0, 0, 0, 0 },
                    Colors  = red,
                },
            };

            Run("UITests.Windows_UI_Xaml_Shapes.Shapes_Default_StrokeThickness");

            _app.WaitForElement("TestZone");

            foreach (var expectation in shapeExpectations)
            {
                _app.Marked($"{expectation.Name}Selector").FastTap();

                using var screenshot = TakeScreenshot($"{expectation}");
                if (expectation.Name == "MyLine" || expectation.Name == "MyPath")
                {
                    var targetRect = _app.GetPhysicalRect($"{expectation.Name}Target");
                    ImageAssert.DoesNotHaveColorAt(screenshot, targetRect.CenterX, targetRect.CenterY, Color.White);

                    _app.Marked("StrokeThicknessButton").FastTap();

                    using var zeroStrokeThicknessScreenshot = TakeScreenshot($"{expectation.Name}_0_StrokeThickness");
                    ImageAssert.HasColorAt(zeroStrokeThicknessScreenshot, targetRect.CenterX, targetRect.CenterY, Color.White);
                }
                else
                {
                    var shapeContainer = _app.GetPhysicalRect($"{expectation}Grid");

                    ImageAssert.HasColorAt(screenshot, shapeContainer.X + expectation.Offsets[0], shapeContainer.CenterY, expectation.Colors, tolerance: 15);
                    ImageAssert.HasColorAt(screenshot, shapeContainer.CenterX, shapeContainer.Y + expectation.Offsets[1], expectation.Colors, tolerance: 15);
                    ImageAssert.HasColorAt(screenshot, shapeContainer.Right + expectation.Offsets[2], shapeContainer.CenterY, expectation.Colors, tolerance: 15);
                    ImageAssert.HasColorAt(screenshot, shapeContainer.CenterX, shapeContainer.Bottom + expectation.Offsets[3], expectation.Colors, tolerance: 15);

                    _app.Marked("StrokeThicknessButton").FastTap();

                    using var zeroStrokeThicknessScreenshot = TakeScreenshot($"{expectation.Name}_0_StrokeThickness");

                    ImageAssert.DoesNotHaveColorAt(zeroStrokeThicknessScreenshot, shapeContainer.X + expectation.Offsets[0], shapeContainer.CenterY, expectation.Colors);
                    ImageAssert.DoesNotHaveColorAt(zeroStrokeThicknessScreenshot, shapeContainer.CenterX, shapeContainer.Y + expectation.Offsets[1], expectation.Colors);
                    ImageAssert.DoesNotHaveColorAt(zeroStrokeThicknessScreenshot, shapeContainer.Right + expectation.Offsets[2], shapeContainer.CenterY, expectation.Colors);
                    ImageAssert.DoesNotHaveColorAt(zeroStrokeThicknessScreenshot, shapeContainer.CenterX, shapeContainer.Bottom + expectation.Offsets[3], expectation.Colors);
                }
            }
        }