Ranorex Logo

Support Corner: API Testing and Simple POST Requests

|
|||

Ranorex Studio is renowned for its robust no-code capabilities, which allow tests to be automated seamlessly across web, mobile, and desktop applications. Beyond its intuitive recording features, Ranorex Studio allows custom code module creation using C# or VB.NET, enhancing the versatility and depth of your test suites.

In part two of this Support Corner series on API testing, we explored how to create a function to deserialize the response for more robust testing. In part 3, we explore testing a POST request.

How It’s Done

To start, we already have the necessary packages from the previous blog posts, so we can go straight to writing the method for the POST request into the same user code collection from the previous API blog posts.

As a reminder, you can easily add methods to a user code collection by right-clicking inside the main class and selecting “Insert new user code method…”:

The following method takes in one parameter — the URL of the POST request we want to perform. Since this is a relatively simple example, the URL will be the only parameter. The data we send in the POST request can be included in the parameters, but for this example, the data will be hard coded using the method. It also returns the response as a string. If the POST request returns an exception, we handle it and log it in the report. If we wanted, we could use the Report.Failure method to have it show up as failure.

     public static string PostRequest(string url)

        {

            var stringResponse = "";

              using (var client = new WebClient())

              {

                 byte[] response = Array.Empty<byte>();    

                 var data = new NameValueCollection();

                 data["thing1"] = "hello";

                 data["thing2"] = "world";

                try {

                      response = client.UploadValues(url, data);

                  } 

                  catch (WebException ex)

                    {

                        if (ex.Response != null)

                        {

                            stringResponse = "The POST Request has returned an exception with the status: " +ex.Status + " - " + ex.Message;

                            Report.Info(stringResponse);

                            //Report.Failure(stringResponse

                    }

                }

                       stringResponse = Encoding.ASCII.GetString(response);

              }

              return stringResponse;

        }

      

To use the method we created in the user code collection, we can go to a recording module and Add New Action -> User Code -> Select from library. You should see the PostRequest method we just added.

You can use that method to send a simple POST request and save the request’s response. In this case, we save the response to a variable and then log the variable to the Ranorex report. Another quick test is to validate that the response is what we expect using the Ranorex validation action. In this case, we are using a sample URL from https://httpbin.org/. It will echo back the request to ensure it does what we expect.

Using RestSharp

This blog covered how to create a simple POST request in C# with Ranorex. As an alternative to system.Net, we can use the RestSharp library package to create the GET and POST requests. 

As a reminder to add a package to your Ranorex solution, the first step e is Right-Clicking the solution in the project panel and selecting “Manage Packages”:

In the package manager window, search for RestSharp and select the Add button. After adding the package, you can verify that it was added properly by checking if it shows under references in the project panel. Then, to use the library, you can import the following into the user code:

using RestSharp

Next Steps

The Ranorex API allows you to create powerful scripts to complement the no-code recording tools of Ranorex Studio. Using C#, we can utilize system libraries or third-party libraries to create simple methods for API testing. 

If you want to try API testing with Ranorex Studio, request a free trial of our robust QA testing automation tools — including the Ranorex API.

In This Article

Sign up for our newsletter

Share this article

Related Articles

Selenium-Test-Management-Tools-Workflows-and-Best-Practices-blog-image

Selenium Test Management: Tools, Workflows, and Best Practices

July 16, 2026
Selenium is one of the most widely used tools for browser automation. It gives QA teams a flexible, open-source way to automate web application testing across browsers and programming languages. Selenium’s own documentation describes it as an umbrella project for tools and librar...
Test-Automation-ROI-How-to-Calculate-and-Maximize-Results-blog-image

Test Automation ROI: How to Calculate and Maximize Results

July 9, 2026
Most teams that invest in test automation see early gains, only to watch those returns erode as the suite grows. The typical conclusion is that automation was a bad investment. The actual problem is often architectural. Test automation ROI measures the financial return from repla...
Generative-AI-in-Software-Testing-A-Complete-Guide-blog-image

Generative AI in Software Testing: A Complete Guide

July 2, 2026
AI-assisted development is increasing the volume and speed of software change, which puts more pressure on QA teams to keep coverage current without adding equivalent headcount. That is one reason AI has moved from an experimental topic to a practical one in software testing. Gen...