Last updated: Sep 30, 2019 14:08
Failure reasons in C# can be implemented by using the Start test and End test REST APIs.
Here is a code sample on how to use them:
Start Test Implementation
private static void StartTest(RemoteWebDriver driver) { string URL = "https://yourCloud.perfectomobile.com/services/executions/" + driver.Capabilities.GetCapability("executionId"); string urlParameters = "?operation=command&user=username&password=userpassword&command=test&subcommand=start¶m.name=Perfecto Demo Test"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); HttpResponseMessage response = client.GetAsync(urlParameters).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.ToString()); Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } else { Console.WriteLine(response.ToString()); Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } client.Dispose(); }
End Test Implementation
private static void EndTest(RemoteWebDriver driver, string result, string failureReason) { string URL = "https://yourCloud.perfectomobile.com/services/executions/"+driver.Capabilities.GetCapability("executionId"); string urlParameters = ""; if (result.Equals("success")) urlParameters = "?operation=command&user=username&password=userpassword&command=test&subcommand=end¶m.success=true"; else urlParameters = "?operation=command&user=username&password=userpassword&command=test&subcommand=end¶m.success=false¶m.failureReason=DemoFailureReason¶m.failureDescription=DemoFailure"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); HttpResponseMessage response = client.GetAsync(urlParameters).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.ToString()); Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } else { Console.WriteLine(response.ToString()); Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } client.Dispose(); }
For more information about these REST APIs and their parameters please refer to their documentation (click on the links below):
Related articles