How to do API testing with UFT API tests

by Yevgeny Efter

Functional testing is simply the simulation of application usage flows (scenarios) and the verification of expected application behavior based on its functional design and specification. You can achieve this by interacting with the application's user interface (UI) layer, either manually or automatically, by automating the application’s UI.

API testing is an equally important method of functional testing that addresses your application’s business logic layer. The example of API testing below calls tests from the Unified Functional Test (UFT) framework directly from within tests written in the LeanFT testing framework. You can follow along, or try the example yourself by downloading the free trial version of the LeanFT.

API testing in LeanFT

Because LeanFT tests are created in the context of standard development environments, it's possible to leverage third-party frameworks and libraries to handle API testing. You can also combine UI and API tests within a single script. I used the LeanFT SDK for UI testing, and various third-party frameworks and libraries for API testing.

Testing an API by running UFT API Tests:

Let’s say you have a UFT API test, called VerifyFlightOrder, that verifies the business logic of a flight-ordering transaction, and you want to run this test from a LeanFT Test.

Here's how you can do it using the LeanFT Java SDK (this functionality is supported by the .NET SDK as well).

First, you create a LeanFT JUnit project:

To run UFT API Tests, the LeanFT SDK includes an APITestRunner class that resides in the com.hp.lft.sdk.apitesting.uft package. The class has a few run method overloads, and in addition to the UFT API test’s path parameter, you can pass a dictionary with input parameters and/or the UFT API test’s profile name.

Be sure to include the following import statements:

Now let’s see how you actually call the existing UFT API test.

The APITestRunner class has the following run method overloads:

  • run(String testPath).
  • run(String testPath, String profileName).
  • run(String testPath, Map<String, Object> inParams).
  • run(String testPath, Map<String, Object> inParams, String profileName).

If you are familiar with API testing in UFT, the parameters for the run methods are self-explanatory.

The type for the return value of the run method is APITestResult, which contains the status of the test (true means passed, and false means failed), and a dictionary of output parameters.

For this example, I use the third overload that gets the path of the test (the directory containing the “.st” file) and input parameters.

The API test I am running receives two input parameters: “From” and “To”.

Let’s see how you run it using the provided API:

The UFT API call is reflected in the LeanFT run report:

The report contains a step named UFTAPITestRunner.Run, which represents the call to the UFT API test. You can also see the details of the call, including:

  • The path of the UFT API test
  • The parameters I sent it
  • The output parameters returned by the UFT API test

In addition, a link to the report created by the UFT API test is also provided so you can view the internal details of the UFT API test itself:

The same functionality is available in both LeanFT’s Java and .NET SDKs. Here is an example of how it looks in .NET:

Lastly, running UFT API tests from LeanFT tests does not require that you install UFT on the machine. All you need is a folder containing the assets of the UFT API test itself.

To learn more about API testing compared to other testing types, read 3 types of automated tests.

Test in the cloud with StormRunner Functional