Page tree
Skip to end of metadata
Go to start of metadata

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&param.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&param.success=true";
            else
                urlParameters = "?operation=command&user=username&password=userpassword&command=test&subcommand=end&param.success=false&param.failureReason=DemoFailureReason&param.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):