예제 #1
0
        protected static bool GetSupportsRotation()
        {
            var currentPlatform  = AppInitializer.GetLocalPlatform();
            var supportsRotation = currentPlatform == Platform.Android || currentPlatform == Platform.iOS;

            return(supportsRotation);
        }
예제 #2
0
 public void AndroidFullScreenTearDown()
 {
     if (AppInitializer.GetLocalPlatform() == Platform.Android)
     {
         _app.InvokeGeneric("browser:SampleRunner|SetFullScreenMode", false);
     }
 }
예제 #3
0
 public void AndroidFullScreenSetup()
 {
     if (AppInitializer.GetLocalPlatform() == Platform.Android)
     {
         // workaround for #2747: force the app into fullscreen
         // to prevent status bar from reappearing when popup are shown.
         _app.InvokeGeneric("browser:SampleRunner|SetFullScreenMode", true);
     }
 }
예제 #4
0
#pragma warning restore 618
        // ************************
        // Physical vs Logical Rect
        // ************************
        //
        // On Android. _app.GetRect() will return values in the PHYSICAL coordinate space.
        // On iOS, _app.GetRect() will return values in the LOGICAL coordinate space.
        // On Wasm (Browser), _app.GetRect() will be 1:1 for PHYSICAL:LOGICAL, so no need to convert.
        //
        // ************************
        private static IAppRect ToPhysicalRect(IApp app, IAppRect rect)
        {
            return(AppInitializer.GetLocalPlatform() switch
            {
                Platform.Android => rect,
                Platform.iOS => rect.ApplyScale(app.GetDisplayScreenScaling()),
                Platform.Browser => rect,
                _ => throw new InvalidOperationException("Unknown current platform.")
            });
예제 #5
0
#pragma warning restore 618
        // ************************
        // Physical vs Logical Rect
        // ************************
        //
        // On Android. _app.GetRect() will return values in the PHYSICAL coordinate space.
        // On iOS, _app.GetRect() will return values in the LOGICAL coordinate space.
        // On Wasm (Browser), _app.GetRect() will be 1:1 for PHYSICAL:LOGICAL, so no need to convert.
        //
        // ************************
        private static IAppRect ToPhysicalRect(IApp app, IAppRect rect)
        {
#if IS_RUNTIME_UI_TESTS
            return(rect);
#else
            return(AppInitializer.GetLocalPlatform() switch
            {
                Platform.Android => rect,
                Platform.iOS => rect.LogicalToPhysicalPixels(app),
                Platform.Browser => rect,
                _ => throw new InvalidOperationException("Unknown current platform.")
            });
예제 #6
0
        internal IAppRect GetScreenDimensions()
        {
            if (AppInitializer.GetLocalPlatform() == Platform.Browser)
            {
                var sampleControl = _app.Marked("sampleControl");

                return(_app.WaitForElement(sampleControl).First().Rect);
            }
            else
            {
                return(_app.GetScreenDimensions());
            }
        }
예제 #7
0
        public void BeforeEachTest()
        {
            _startTime = DateTime.Now;

            ValidateAutoRetry();

            // Check if the test needs to be ignore or not
            // If nothing specified, it is considered as a global test
            var platforms = GetActivePlatforms().Distinct().ToArray();

            if (platforms.Length != 0)
            {
                // Otherwise, we need to define on which platform the test is running and compare it with targeted platform
                var shouldIgnore    = false;
                var currentPlatform = AppInitializer.GetLocalPlatform();

                if (_app is Uno.UITest.Xamarin.XamarinApp xa)
                {
                    if (Xamarin.UITest.TestEnvironment.Platform == Xamarin.UITest.TestPlatform.Local)
                    {
                        shouldIgnore = !platforms.Contains(currentPlatform);
                    }
                    else
                    {
                        var testCloudPlatform = Xamarin.UITest.TestEnvironment.Platform == Xamarin.UITest.TestPlatform.TestCloudiOS
                                                        ? Platform.iOS
                                                        : Platform.Android;

                        shouldIgnore = !platforms.Contains(testCloudPlatform);
                    }
                }
                else
                {
                    shouldIgnore = !platforms.Contains(currentPlatform);
                }

                if (shouldIgnore)
                {
                    var list = string.Join(", ", platforms.Select(p => p.ToString()));

                    Assert.Ignore($"This test is ignored on this platform (runs on {list})");
                }
            }

            var app = AppInitializer.AttachToApp();

            _app = app ?? _app;

            Helpers.App = _app;
        }
예제 #8
0
        private void WriteSystemLogs(string fileName)
        {
            if (_app != null && AppInitializer.GetLocalPlatform() == Platform.Browser)
            {
                var outputPath = string.IsNullOrEmpty(_screenShotPath)
                                        ? Environment.CurrentDirectory
                                        : _screenShotPath;

                using (var logOutput = new StreamWriter(Path.Combine(outputPath, $"{fileName}_{DateTime.Now:yyyy-MM-dd-HH-mm-ss.fff}.txt")))
                {
                    foreach (var log in _app.GetSystemLogs(_startTime.ToUniversalTime()))
                    {
                        logOutput.WriteLine($"{log.Timestamp}/{log.Level}: {log.Message}");
                    }
                }
            }
        }
예제 #9
0
        public PointerDeviceType CurrentPointerType => DefaultPointerType;         // We cannot change pointer type on this platform

        public void ValidateAppMode()
        {
            if (GetCurrentFixtureAttributes <TestAppModeAttribute>().FirstOrDefault() is TestAppModeAttribute testAppMode)
            {
                if (
                    _totalTestFixtureCount != 0 &&
                    testAppMode.CleanEnvironment &&
                    testAppMode.Platform == AppInitializer.GetLocalPlatform()
                    )
                {
                    // If this is not the first run, and the fixture requested a clean environment, request a cold start.
                    // If this is the first run, as the app is cold-started during the type constructor, we can skip this.
                    _app = AppInitializer.ColdStartApp();
                }
            }

            _totalTestFixtureCount++;
        }
예제 #10
0
        public void BeforeEachTest()
        {
            // Check if the test needs to be ignore or not
            // If nothing specified, it is considered as a global test
            if (_platform == null)
            {
                return;
            }

            // Otherwise, we need to define on which platform the test is running and compare it with targeted platform
            var shouldIgnore    = false;
            var currentPlatform = AppInitializer.GetLocalPlatform();

            if (_app is Uno.UITest.Xamarin.XamarinApp xa)
            {
                if (Xamarin.UITest.TestEnvironment.Platform == Xamarin.UITest.TestPlatform.Local)
                {
                    shouldIgnore = currentPlatform != _platform;
                }
                else
                {
                    var testCloudPlatform = Xamarin.UITest.TestEnvironment.Platform == Xamarin.UITest.TestPlatform.TestCloudiOS
                                                ? Platform.iOS
                                                : Platform.Android;

                    shouldIgnore = _platform != testCloudPlatform;
                }
            }
            else
            {
                shouldIgnore = _platform != currentPlatform;
            }

            if (shouldIgnore)
            {
                Assert.Ignore("This test is ignored on this platform");
            }
        }
예제 #11
0
        protected void Run(string metadataName, bool waitForSampleControl = true, bool skipInitialScreenshot = false, int sampleLoadTimeout = 5)
        {
            if (waitForSampleControl)
            {
                var sampleControlQuery = AppInitializer.GetLocalPlatform() == Platform.Browser
                                        ? new QueryEx(q => q.Marked("sampleControl"))
                                        : new QueryEx(q => q.All().Marked("sampleControl"));

                _app.WaitForElement(sampleControlQuery, timeout: TimeSpan.FromSeconds(sampleLoadTimeout));
            }

            var testRunId = _app.InvokeGeneric("browser:SampleRunner|RunTest", metadataName);

            _app.WaitFor(() =>
            {
                var result = _app.InvokeGeneric("browser:SampleRunner|IsTestDone", testRunId).ToString();
                return(bool.TryParse(result, out var testDone) && testDone);
            }, retryFrequency: TimeSpan.FromMilliseconds(50));

            if (!skipInitialScreenshot)
            {
                TakeScreenshot(metadataName.Replace(".", "_"));
            }
        }
예제 #12
0
        protected static bool GetIsTouchInteraction()
        {
            var currentPlatform = AppInitializer.GetLocalPlatform();

            return(currentPlatform == Platform.Android || currentPlatform == Platform.iOS);
        }
예제 #13
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);
        }
예제 #14
0
        [ActivePlatforms(Platform.Android, Platform.Browser)]         // Disabled on iOS (xamarin.uitest 3.2 or iOS 15) https://github.com/unoplatform/uno/issues/8012
        public void Keyboard_Textbox_InsideScrollViewer_Validation()
        {
            Run("Uno.UI.Samples.Content.UITests.TextBoxControl.Input_Test_InsideScrollerViewer_Automated");

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

            var normalTextBox          = _app.Marked("NormalTextBox");
            var filledTextBox          = _app.Marked("FilledTextBox");
            var placeholderTextTextBox = _app.Marked("PlaceholderTextTextBox");
            var disabledTextBox        = _app.Marked("DisabledTextBox");
            var multilineTextBox       = _app.Marked("MultilineTextBox");
            var numberTextBox          = _app.Marked("NumberTextBox");

            // Assert initial state
            Assert.AreEqual(string.Empty, normalTextBox.GetDependencyPropertyValue("Text")?.ToString());
            Assert.AreEqual("Text", filledTextBox.GetDependencyPropertyValue("Text")?.ToString());
            Assert.AreEqual(string.Empty, placeholderTextTextBox.GetDependencyPropertyValue("Text")?.ToString());
            Assert.AreEqual(string.Empty, disabledTextBox.GetDependencyPropertyValue("Text")?.ToString());
            Assert.AreEqual(string.Empty, multilineTextBox.GetDependencyPropertyValue("Text")?.ToString());
            Assert.AreEqual(string.Empty, numberTextBox.GetDependencyPropertyValue("Text")?.ToString());

            {
                // Setting focus on normalTextBox
                _app.FastTap(normalTextBox);
                _app.Wait(1);
                TakeScreenshot("0 - Focus on normalTextBox ", ignoreInSnapshotCompare: true);

                // Removing focus on normalTextBox
                _app.TapCoordinates(0f, 0f);
                _app.Wait(1);
                TakeScreenshot("0 - Remove Focus on normalTextBox", ignoreInSnapshotCompare: AppInitializer.GetLocalPlatform() == Platform.Android /*Keyboard predicted text can change*/);
            }

            {
                // Setting focus on normalTextBox
                _app.FastTap(filledTextBox);
                _app.Wait(1);
                TakeScreenshot("1 - Focus on filledTextBox", ignoreInSnapshotCompare: true);

                // Removing focus on normalTextBox
                _app.TapCoordinates(0f, 0f);
                _app.Wait(1);
                TakeScreenshot("1 - Remove Focus on filledTextBox", ignoreInSnapshotCompare: AppInitializer.GetLocalPlatform() == Platform.Android /*Keyboard predicted text can change*/);
            }

            {
                // Setting focus on placeholderTextTextBox
                _app.FastTap(placeholderTextTextBox);
                _app.Wait(1);
                TakeScreenshot("2 - Focus on placeholderTextTextBox", ignoreInSnapshotCompare: true);

                // Removing focus on placeholderTextTextBox
                _app.TapCoordinates(0f, 0f);
                _app.Wait(1);
                TakeScreenshot("2 - Remove Focus on placeholderTextTextBox");
            }

            {
                // Setting focus on disabledTextBox
                _app.FastTap(disabledTextBox);
                _app.Wait(1);
                TakeScreenshot("3 - Focus on disabledTextBox", ignoreInSnapshotCompare: true);

                // Removing focus on disabledTextBox
                _app.TapCoordinates(0f, 0f);
                _app.Wait(1);
                TakeScreenshot("3 - Remove Focus on disabledTextBox");
            }

            {
                // Setting focus on multilineTextBox
                _app.FastTap(multilineTextBox);
                _app.Wait(1);
                TakeScreenshot("4 - Focus on multilineTextBox", ignoreInSnapshotCompare: true);

                // Removing focus on multilineTextBox
                _app.TapCoordinates(0f, 0f);
                _app.Wait(1);
                TakeScreenshot("4 - Remove Focus on multilineTextBox");
            }

            {
                // Setting focus on numberTextBox
                _app.FastTap(numberTextBox);
                _app.Wait(1);
                TakeScreenshot("5 - Focus on numberTextBox", ignoreInSnapshotCompare: true);

                // Removing focus on numberTextBox
                _app.TapCoordinates(0f, 0f);
                _app.Wait(1);
                TakeScreenshot("5 - Remove Focus on numberTextBox");
            }
        }