We're here to help

Creating custom APIs

Custom test steps are a way to extend the standard features of Provar by writing your own logic in the form of an API and invoke it easily across all test cases.  As an example, you can create a Custom API to trigger an External ANT Task from a test case.

Creating a custom API

To create a Custom API:

Step 1: Click the New Test button and select New Test API:

Step 2: Enter a Name, Title and Summary. (Name is the name of the Java class whereas Title is the display name of the API.) Then click the Finish button:

Step 3: Open the newly created .java file by navigating to the folder src/customapis in the Navigator view, then double-clicking on the file:

Step 4: Locate the following section in the file and add your own logic in Java:

Step 5: Click Save. To use the new Test API, locate it in the Test Palette and click and drag it into the Test Case:

Example 1: Trigger External ANT Tasks

This example shows how to create a Custom API for triggering an external ANT Task. A common use case for this is to trigger an ANT task to deploy a package in a Salesforce environment, followed by test data setup steps.

Step 1Download Apache ANT jar and ANT Launcher jar and import them to the Project using the steps described in importing and executing JAR files.

Step 2: Download the Custom API RunANTTask.java and add it into your Test Project under the folder src/customapis:

Step 3: Create a new Test Case, then locate the new Custom API in the Test Palette and click and drag it into the Test Case:

Step 4: Populate the following parameters:

  • Path: The absolute path to the ANT build file
  • Build File Name: Name of the ANT build file to be executed
  • Target Name: Name of the Target that you need to execute. Provar will pick up the default Target if this is left blank

After the ANT task is executed, it will give the result in a variable defined under Is Task Successful. This Custom API will respond with an output of TRUE if executed successfully, or FALSE if any error was encountered. The full ANT logs can be viewed in the Test Runner.