Ejemplo n.º 1
0
        private List <Run> GetTestRuns(List <string> testArns)
        {
            var runs = new List <Run>();

            foreach (string arn in testArns)
            {
                runs.Add(DFClient.GetRun(arn).Run);
            }
            return(runs);
        }
Ejemplo n.º 2
0
        public void DeviceFarmGetRun()
        {
            #region to-get-a-test-run-1471015895657

            var client   = new AmazonDeviceFarmClient();
            var response = client.GetRun(new GetRunRequest
            {
                Arn = "arn:aws:devicefarm:us-west-2:123456789101:run:5e01a8c7-c861-4c0a-b1d5-5ec6e6c6dd23/0fcac17b-6122-44d7-ae5a-12345EXAMPLE" // You can get the run ARN by using the list-runs CLI command.
            });

            Run run = response.Run;

            #endregion
        }
Ejemplo n.º 3
0
        private void Run(Options options)
        {
            this.options = options;
            client       = new AmazonDeviceFarmClient(AwsAccessKey, AwsSecretKey, RegionEndpoint.USWest2);

            if (options.ListDevicePools)
            {
                ListDevicePools();
                return;
            }

            if (options.DeleteCompletedRuns)
            {
                DeleteCompletedRuns();
                return;
            }

            var devicePoolArn = FindDevicePoolByName(options.DevicePool);

            if (string.IsNullOrEmpty(devicePoolArn))
            {
                ReportError($"Error: device pool '{options.DevicePool}' not found");
                return;
            }

            if (string.IsNullOrEmpty(options.FeaturesDir))
            {
                options.FeaturesDir = Path.Combine(Environment.CurrentDirectory, "features");
            }

            if (!Directory.Exists(options.FeaturesDir))
            {
                ReportError($"Directory '{options.FeaturesDir}' not found");
                return;
            }

            if (!options.UseLastApk && string.IsNullOrEmpty(options.Apk))
            {
                ReportError("You need to specifcy the package to use");
                return;
            }

            var appArn = options.UseLastApk
                                ? GetLatestAppArn()
                                : UploadApk(options.Apk);

            if (string.IsNullOrEmpty(appArn))
            {
                ReportError($"Package not found or failed to upload");
                return;
            }

            var testServersPath = Path.Combine(Environment.CurrentDirectory, "test_servers");

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

            var featuresZip = Path.Combine(Path.GetDirectoryName(options.FeaturesDir), "features.zip");

            File.Delete(featuresZip);
            ZipFile.CreateFromDirectory(options.FeaturesDir, featuresZip, CompressionLevel.Fastest, true);

            // Upload the tests
            var createUploadResponse = client.CreateUpload(new CreateUploadRequest
            {
                ProjectArn = ProjectArn,
                Name       = "features.zip",
                Type       = UploadType.CALABASH_TEST_PACKAGE
            });

            Console.WriteLine("Sending features.zip");
            UploadFile(featuresZip, createUploadResponse.Upload.Url);

            var testPackageArn = createUploadResponse.Upload.Arn;
            var uploadStatus   = GetUploadStatus(testPackageArn);

            if (uploadStatus == UploadStatus.FAILED)
            {
                ReportError("Failed to upload features.zip");
                return;
            }

            // Schedule test run
            var scheduleResponse = client.ScheduleRun(new ScheduleRunRequest
            {
                ProjectArn    = ProjectArn,
                AppArn        = appArn,
                DevicePoolArn = devicePoolArn,
                Name          = options.TestName ?? $"Run {DateTime.Now.ToString()}",
                Test          = new ScheduleRunTest
                {
                    Type           = TestType.CALABASH,
                    TestPackageArn = testPackageArn
                },
                Configuration = new ScheduleRunConfiguration
                {
                    Radios = new Radios {
                        Wifi = true
                    },
                    Locale = "en_US",
                }
            });

            GetRunResponse runResponse;

            ReportProgress("Waiting test to finish (it takes a long time, please be patient)");

            do
            {
                Console.Write(".");
                runArn      = scheduleResponse.Run.Arn;
                runResponse = client.GetRun(runArn);
                Thread.Sleep(3000);
            }while (runResponse.Run.Status != ExecutionStatus.COMPLETED);

            if (runResponse.Run.Result != ExecutionResult.PASSED)
            {
                ReportError("Test run failed");
                return;
            }

            DownloadAllArtifacts();
            ReportProgress("Test run finished successfully");
        }