private static async Task UpdateJobStatusAsync(string sessionId, string jobName, bool success, Exception error) { if (!TestEnvironment.Current.IsRemote) { return; } // If we're using the remote driver, we need to update the Sauce Labs job status. var username = TestEnvironment.Current.SauceLabsRemoteUsername; var key = TestEnvironment.Current.SauceLabsRemoteKey; var update = new JobStatusUpdate { Name = jobName, Passed = success }; if (error != null) { update.Data = new Dictionary <string, string> { { "error", error.Message } }; } /* From SauceLabs API Reference, example request: * curl -X PUT https://YOUR_USERNAME:[email protected]/rest/v1/YOUR_USERNAME/jobs/YOUR_JOB_ID \ * -H "Content-Type: application/json" \ * -d '{"tags": ["test", "example", "taggable"], * "public": true, * "name": "changed-job-name", * "passed": false, * "custom-data": {"error": "step 17 failed"}}' */ var url = string.Format("https://{0}:{1}@saucelabs.com/rest/v1/{0}/jobs/{2}", username, key, sessionId); var parameter = Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + key)); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", parameter); try { var result = await client.PutAsJsonAsync(url, update); result.EnsureSuccessStatusCode(); } catch (Exception ex) { Console.WriteLine("[ERROR] TestResultReporter.UpdateJobStatus{0}{1}", Environment.NewLine, ex); } } }
private static async Task UpdateJobStatusAsync(string sessionId, string jobName, bool success, Exception error) { if (!TestEnvironment.Current.IsRemote) { return; } // If we're using the remote driver, we need to update the Sauce Labs job status. var username = TestEnvironment.Current.SauceLabsRemoteUsername; var key = TestEnvironment.Current.SauceLabsRemoteKey; var update = new JobStatusUpdate { Name = jobName, Passed = success }; if (error != null) { update.Data = new Dictionary<string, string> { { "error", error.Message } }; } /* From SauceLabs API Reference, example request: curl -X PUT https://YOUR_USERNAME:[email protected]/rest/v1/YOUR_USERNAME/jobs/YOUR_JOB_ID \ -H "Content-Type: application/json" \ -d '{"tags": ["test", "example", "taggable"], "public": true, "name": "changed-job-name", "passed": false, "custom-data": {"error": "step 17 failed"}}' */ var url = string.Format("https://{0}:{1}@saucelabs.com/rest/v1/{0}/jobs/{2}", username, key, sessionId); var parameter = Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + key)); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", parameter); try { var result = await client.PutAsJsonAsync(url, update); result.EnsureSuccessStatusCode(); } catch (Exception ex) { Console.WriteLine("[ERROR] TestResultReporter.UpdateJobStatus{0}{1}", Environment.NewLine, ex); } } }