# Run UFT API Tests (Windows only)

In addition to using LeanFT to test your application's user interface, you can also run a UFT API test as part of your test. This enables you to test your application's service layer with the UI layer in a fully unified test of your application.

The results from the UFT API test are included as part of your LeanFT test results.

Note:

- It is not necessary to have UFT installed on your computer to run UFT API tests.
- Calling a parameterized UFT API test that gets its data from an Excel file data source, is not supported.

In this topic:

## Prerequisites

Before running UFT API tests in LeanFT, you must:

- Save and run the test in UFT at least once.
- If you installed LeanFT as part of UFT, enable HTML Report in UFT. For more details, see Set run result reporting options.
- Install the Microsoft Access Database Engine 2016 if you are running a UFT API test using Excel data sources.

- Add the appropriate `using` or `import` statements:

  - `using HP.LFT.SDK.APITesting.UFT`
  - `import com.hp.lft.sdk.apitesting.uft.APITestResult;`
    `import com.hp.lft.sdk.apitesting.uft.APITestRunner;`

## Run tests

You run UFT API tests using the APITestRunner.Run method which accesses and runs the API test:

C#

    APITestRunner.Run(@"C:\Users\default\Documents\Unified Functional Testing\APITest1");

Java

    APITestRunner.run("C:\\Users\default\\Documents\\Unified Functional Testing\\APITest1");

In the Run method arguments, you can also pass input parameters for the UFT API test as shown below.

This method returns an APITestResult object containing the results of the test - both the status of the test run and the test output parameters (if relevant).

The results for the API test run are displayed in the LeanFT report, with a link to open the results of the entire UFT API test. These results can also be found in the test's results folder (RunResults/ApiTestReport).

For more details on these classes and methods, see the .NET SDK Reference or Java SDK Reference.

Back to top

## Use the results of the API test run in other steps

C#:

    var result = APITestRunner.Run(@"C:\API Tests\APITest1", inParams);
                var outParams = result.OutParams;
                var status = result.Status;

Java:

    APITestResult result = APITestRunner.run("C:\\API Tests\\APITest1", inParams);
    	outParams = result.getOutParams();
    	boolean status = result.getStatus();

Back to top

## Assign values for the input parameters of your UFT API test

While each input parameter for your API test contains a default value (as set in UFT), you can set the values to use for the input parameters as an argument of the APITestRunner.Run method.

Note: If you define the parameters manually, you must define values for all input parameters in the UFT API test (even if the test has default values for the parameters).

C#

    var inParams = new Dictionary<string, object>
                {
                    {"FirstParam", "c"},
                    {"SecondParam", "d"}
                };

                var result = APITestRunner.Run(@"C:\API Tests\APITest1", inParams);

Java

    Map<String, Object> inParams = new HashMap<String, Object>();
    	inParams.put("FirstParam", "c");
    	inParams.put("SecondParam", "d");

    	APITestResult result = APITestRunner.run("C:\\API Tests\\APITest1", inParams);

Back to top

## Select a specific profile for your UFT API test

In UFT, you can specify multiple profiles for each API test. You can select one of these profiles to use as an argument of the APITestRunner.Run method:

C#

    APITestRunner.Run(@"C:\API Tests\APITest1", "Profile1");

Java

    APITestRunner.run("C:\\API Tests\\APITest1", "Profile1");

Back to top

## Pass the value of your test's output parameters to other steps

If you add an output parameter to your UFT API test, the value of this parameter is available with the APITestResult class in LeanFT. The APITestResult class returns this value and you can assign for use in other parts of the test:

C#

            [Test]
            public void LeanFTTestWithApi()
            {

                IBrowser browser;
                IEditField name;
                //Describe and instantiate the LeanFT TOs
                browser = BrowserFactory.Launch(BrowserType.Chrome);
                name = browser.Describe<IEditField>(new EditFieldDescription { TagName = "INPUT", Name = "WebEdit", Type = "text" });

                //Start the test - navigate to the relevant page
                browser.Navigate("http://mystore.net:3000/#/store");

                //Run API test and verify the test passed successfully
                var result = APITestRunner.Run(TestsPath);
                Verify.AreEqual(true, result.Status, "The status of the APITestResult wasn't right");

                //Save the API test result into a variable
                var text = result.OutParams["OutPutParam1"];

                //Use this variable in our test - set the value in an edit field
               name.SetValue(text);

                //Validate the value in the edit field is as expected
                Verify.AreEqual(name.Value, "John doe");

            }

Java

    @Test
    public void LeanFTTestWithApi() throws GeneralLeanFtException {

         Browser browser;
         EditField name;

         //Describe and instantiate the LeanFT TOs
         browser = BrowserFactory.launch(BrowserType.CHROME);
         name = browser.describe(EditField.class, new EditFieldDescription.Builder().tagName("INPUT").name("WebEdit").type("text").build());

         //Start the test - navigate to the relevant page
         browser.navigate("http://mystore.net:3000/#/store");
         //Running API test and verifying the test passed successfully
         APITestResult result = APITestRunner.run("TestPath");
         assertEquals("The status of the API Test is wrong", true, result.getStatus() );

         //Save the API test result into a variable
         String text = result.getOutParams().get(1);

         System.out.println(text);
         //Use this variable in our test - setting the value in an edit field
         name.setValue(text);

         //Validate the value in the edit field is as expected
         Verify.areEqual(name.getValue(), "John doe");

    }

Back to top

See also:

- LeanFT reference for UFT experts
- Blog post: API Testing in LeanFT

https://admhelp.microfocus.com LeanFT 8942
Tips to improve your search results...TOC Lean Functional Testing Help Center LeanFT Help Center 14.50 - 14.53 All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version:(Undefined variable: _rscC_Basic_Variables.FloatingTocShow)