/* List suites */ func listSuites(svc *devicefarm.DeviceFarm, filterArn string) { listReq := &devicefarm.ListSuitesInput{ ARN: aws.String(filterArn), } resp, err := svc.ListSuites(listReq) failOnErr(err, "error listing suites") fmt.Println(awsutil.Prettify(resp)) }
/* List suites */ func listSuites(svc *devicefarm.DeviceFarm, filterArn string) { listReq := &devicefarm.ListSuitesInput{ Arn: aws.String(filterArn), } resp, err := svc.ListSuites(listReq) failOnErr(err, "error listing suites") //fmt.Println(awsutil.Prettify(resp)) table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"Name", "Status", "Result", "Message"}) table.SetAlignment(tablewriter.ALIGN_LEFT) table.SetColWidth(120) for _, m := range resp.Suites { line := []string{*m.Name, *m.Status, *m.Result, *m.Message} table.Append(line) } table.Render() // Send output }
/* Get Run Report */ func runReport(svc *devicefarm.DeviceFarm, runArn string) { infoReq := &devicefarm.GetRunInput{ Arn: aws.String(runArn), } resp, err := svc.GetRun(infoReq) failOnErr(err, "error getting run info") fmt.Printf("Reporting on run %s\n", *resp.Run.Name) fmt.Printf("Run arn %s\n", runArn) //fmt.Println(awsutil.Prettify(resp)) jobReq := &devicefarm.ListJobsInput{ Arn: aws.String(runArn), } // Find all artifacts artifactReq := &devicefarm.ListArtifactsInput{ Arn: aws.String(runArn), } types := []string{"LOG", "SCREENSHOT", "FILE"} artifacts := map[string][]devicefarm.ListArtifactsOutput{} for _, artifactType := range types { artifactReq.Type = aws.String(artifactType) artifactResp, err := svc.ListArtifacts(artifactReq) failOnErr(err, "error getting run info") // Store type artifacts artifacts[artifactType] = append(artifacts[artifactType], *artifactResp) } respJob, err := svc.ListJobs(jobReq) failOnErr(err, "error getting jobs") // Find all jobs within this run for _, job := range respJob.Jobs { fmt.Println("==========================================") time.Sleep(2 * time.Second) jobFriendlyName := fmt.Sprintf("%s - %s - %s", *job.Name, *job.Device.Model, *job.Device.Os) fmt.Println(awsutil.Prettify(job)) suiteReq := &devicefarm.ListSuitesInput{ Arn: aws.String(*job.Arn), } suiteResp, err := svc.ListSuites(suiteReq) failOnErr(err, "error getting run info") for _, suite := range suiteResp.Suites { message := "" if suite.Message != nil { message = *suite.Message } debug := true if debug { fmt.Printf("%s -> %s : %s \n----> %s\n", jobFriendlyName, *suite.Name, message, *suite.Arn) } dirPrefix := fmt.Sprintf("report/%s/%s", jobFriendlyName, *suite.Name) downloadArtifactsForSuite(dirPrefix, artifacts, *suite) } fmt.Println(awsutil.Prettify(suiteResp)) } params := &devicefarm.ListUniqueProblemsInput{ Arn: aws.String(runArn), // Required } problems, err := svc.ListUniqueProblems(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(awsutil.Prettify(problems)) problemsJson, _ := jsonutil.BuildJSON(problems) writeFile(problemsJson, "./report/unique_problems.json") }
/* Get Run Report */ func runReport(svc *devicefarm.DeviceFarm, runArn string) { infoReq := &devicefarm.GetRunInput{ ARN: aws.String(runArn), } resp, err := svc.GetRun(infoReq) failOnErr(err, "error getting run info") fmt.Printf("%s\n", *resp.Run.Name) //fmt.Println(awsutil.Prettify(resp)) jobReq := &devicefarm.ListJobsInput{ ARN: aws.String(runArn), } // Find all artifacts artifactReq := &devicefarm.ListArtifactsInput{ ARN: aws.String(runArn), } types := []string{"LOG", "SCREENSHOT", "FILE"} artifacts := map[string][]devicefarm.ListArtifactsOutput{} for _, artifactType := range types { artifactReq.Type = aws.String(artifactType) artifactResp, err := svc.ListArtifacts(artifactReq) failOnErr(err, "error getting run info") // Store type artifacts artifacts[artifactType] = append(artifacts[artifactType], *artifactResp) /* for _, artifact := range artifactResp.Artifacts { fmt.Println(awsutil.Prettify(artifact)) } */ } respJob, err := svc.ListJobs(jobReq) failOnErr(err, "error getting jobs") for _, job := range respJob.Jobs { fmt.Println("==========================================") time.Sleep(2 * time.Second) jobFriendlyName := fmt.Sprintf("%s - %s - %s", *job.Name, *job.Device.Model, *job.Device.Os) //fmt.Println(awsutil.Prettify(job)) suiteReq := &devicefarm.ListSuitesInput{ ARN: aws.String(*job.ARN), } suiteResp, err := svc.ListSuites(suiteReq) failOnErr(err, "error getting run info") for _, suite := range suiteResp.Suites { message := "" if suite.Message != nil { message = *suite.Message } fmt.Printf("%s -> %s : %s \n----> %s\n", jobFriendlyName, *suite.Name, message, *suite.ARN) dirPrefix := fmt.Sprintf("report/%s/%s/", jobFriendlyName, *suite.Name) downloadArtifactsForSuite(dirPrefix, artifacts, *suite) } //fmt.Println(awsutil.Prettify(suiteResp)) } }