public override bool Execute()
{
// Verify required parameters have been provided
CheckParameters();
DFClient = new AmazonDeviceFarmClient(RegionEndpoint.USWest2);
string runName = RunNamePrefix + DateTime.Now.ToFileTime();
string projectArn = GetProjectArn(TestProjectName);
string devicePoolArn = GetDevicePool(projectArn, DevicePoolName).Arn;
UploadType applicationUploadType = InferUploadTypeFromFilePath(ApplicationLocation);
string appUploadArn = UploadApplication(projectArn, ApplicationLocation, applicationUploadType);
string calibashUploadArn = UploadCalibashArchive(projectArn, CalabashZipLocation);
// wait for all uploads to complete
var uploadArns = new List<string>() { appUploadArn, calibashUploadArn };
WaitForCompletion(
TimeSpan.FromMinutes(5),
TimeSpan.FromSeconds(10),
() => { return CheckForUploadsSuccessful(uploadArns); });
Log.LogMessage("Scheduling test run for {0}", runName);
// Schedule test run
var runArn = DFClient.ScheduleRun(new ScheduleRunRequest()
{
ProjectArn = projectArn,
AppArn = appUploadArn,
Name = runName,
DevicePoolArn = devicePoolArn,
Test = new ScheduleRunTest()
{
TestPackageArn = calibashUploadArn,
Type = TestType.CALABASH
}
}).Run.Arn;
// following operations will apply generically to all test runs, in case we
// end up wanting to have multiple test runs executing in parallel
var testRunArns = new List<string>() { runArn };
// Wait for all test runs to finish
WaitForCompletion(TimeSpan.FromMinutes(TestTimeoutMinutes), TimeSpan.FromMinutes(1), () => { return CheckForTestsCompleted(testRunArns); });
// Gather the final results of all runs
var runs = GetTestRuns(testRunArns);
// Log test run results and determine if all were successful
bool testsSuccessful = true;
foreach (var run in runs)
{
Log.LogMessage("Run '{0}' completed with result '{1}'.", run.Name, run.Result);
if (run.Result != ExecutionResult.PASSED && run.Result != ExecutionResult.SKIPPED)
{
testsSuccessful = false;
}
}
// Download artifacts for each test run and organize into directories
DownloadArtifacts(runs, ArtifactDownloadLocation);
if (!testsSuccessful)
{
Log.LogError("Some tests failed.");
}
return testsSuccessful;
}