Exemplo n.º 1
0
        public override Task Build(string configuration, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(configuration))
            {
                configuration = "Release";
            }

            // dotnet build HelloForms -t:Run -f net6.0-ios
            return(DotNetTool.Build(b =>
                                    b.Add($"{ProjectFile.FullName}")
                                    .Add($"--output={OutputDirectory.FullName}")
                                    .Add($"--configuration={configuration}"), cancellationToken));
        }
Exemplo n.º 2
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);
        }