Пример #1
0
        public void FromFileGeneratesCorrectProjectType(string fileName, Type expectedProjectType)
        {
            var        filePath = new FileInfo(Path.Combine("Resources", fileName));
            var        output   = new DirectoryInfo(Path.Combine("test-gen", Path.GetFileNameWithoutExtension(fileName), "bin"));
            CSProjFile proj     = null;
            var        ex       = Record.Exception(() => proj = CSProjFile.Load(filePath, output, "iOS"));

            Assert.Null(ex);
            Assert.NotNull(proj);
            Assert.IsType(expectedProjectType, proj);
        }
Пример #2
0
        public void ThrowsPlatformNotSupportedException(string fileName)
        {
            var filePath = new FileInfo(Path.Combine("Resources", fileName));
            var output   = new DirectoryInfo(Path.Combine("test-gen", Path.GetFileNameWithoutExtension(fileName), "bin"));

            CSProjFile proj = null;
            var        ex   = Record.Exception(() => proj = CSProjFile.Load(filePath, output, "Foo"));

            Assert.NotNull(ex);
            Assert.Null(proj);

            Assert.IsType <PlatformNotSupportedException>(ex);
        }
Пример #3
0
        public void HandlesIOSProjectFile()
        {
            var        filePath = new FileInfo(Path.Combine("Resources", "SampleiOSProject.xml"));
            var        output   = new DirectoryInfo(Path.Combine("test-gen", "SampleiOSProject", "bin"));
            CSProjFile proj     = null;
            var        ex       = Record.Exception(() => proj = CSProjFile.Load(filePath, output, "iOS"));

#if WINDOWS_NT
            Assert.NotNull(ex);
            Assert.IsType <PlatformNotSupportedException>(ex);
#else
            Assert.Null(ex);
            Assert.NotNull(proj);
            Assert.IsType <iOSProjectFile>(proj);
#endif
        }
Пример #4
0
        private async Task <int> OnExecuteAsync(CancellationToken cancellationToken)
        {
            IDisposable appium = null;

            Logger.Level = LogLevel;

            if (Directory.Exists(BaseWorkingDirectory))
            {
                Directory.Delete(BaseWorkingDirectory, true);
            }

            Directory.CreateDirectory(BaseWorkingDirectory);
            Logger.SetWorkingDirectory(BaseWorkingDirectory);

            try
            {
                if (!Node.IsInstalled)
                {
                    throw new Exception("Your environment does not appear to have Node installed. This is required to run Appium");
                }

                Logger.WriteLine($"Build and Test artifacts will be stored at {BaseWorkingDirectory}", LogLevel.Detailed);

                ValidatePaths();

                var headBin   = Path.Combine(BaseWorkingDirectory, "bin", "device");
                var uiTestBin = Path.Combine(BaseWorkingDirectory, "bin", "uitest");

                Directory.CreateDirectory(headBin);
                Directory.CreateDirectory(uiTestBin);

                // HACK: The iOS SDK will mess up the generated app output if a Separator is not at the end of the path.
                headBin   += Path.DirectorySeparatorChar;
                uiTestBin += Path.DirectorySeparatorChar;

                var appProject = CSProjFile.Load(DeviceProjectPathInfo, new DirectoryInfo(headBin), Platform);
                if (!await appProject.IsSupported())
                {
                    throw new PlatformNotSupportedException($"{appProject.Platform} is not supported on this machine. Please check that you have the correct build dependencies.");
                }

                await appProject.Build(Configuration, cancellationToken).ConfigureAwait(false);

                var uitestProj = CSProjFile.Load(UITestProjectPathInfo, new DirectoryInfo(uiTestBin), string.Empty);
                await uitestProj.Build(Configuration, cancellationToken).ConfigureAwait(false);

                if (cancellationToken.IsCancellationRequested)
                {
                    return(0);
                }

                if (appProject is DotNetMauiProjectFile && appProject.Platform == "Android")
                {
                    sdkVersion = 30;
                }

                await GenerateTestConfig(headBin, uiTestBin, appProject.Platform, cancellationToken).ConfigureAwait(false);

                if (!await Appium.Install(cancellationToken))
                {
                    return(0);
                }

                appium = await Appium.Run(BaseWorkingDirectory).ConfigureAwait(false);

                await DotNetTool.Test(UITestProjectPathInfo.FullName, uiTestBin, Configuration?.Trim(), Path.Combine(BaseWorkingDirectory, "results"), cancellationToken)
                .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                return(1);
            }
            finally
            {
                appium?.Dispose();

                var binDir = Path.Combine(BaseWorkingDirectory, "bin");
                if (Directory.Exists(binDir))
                {
                    Directory.Delete(binDir, true);
                }

                ReadTestResults();
            }

            return(0);
        }