How to auto-generate API tests from UI tests

Tips & Tricks, New Features

How to auto-generate API tests from UI tests

In this example, we look at how we can auto-generate API tests from UI tests in Boozang using “Generate API” play mode.

There are many test automation tools to do API testing. As Boozang can be used for both End-2-End/UI tests and API tests it’s possible to mix them in the same test, using the same test data. We have also launched the feature “Generate API” that records an API test based on a UI test. This way you can generate API tests really fast without the need for deep developer knowledge of the application.

The Shop

We will use the test application “The Shop” to illustrate this functionality

provided by itswadesh.

In this application you can add a number of items to cart, and place and order for the items. When adding things to the cart, the cart is stored on the client side, so no API calls are being done. It’s not until the user placed the order,  the server-side is engaged via an API call.

See screenshot from the Shop application below

Making UI test in Boozang

Start by creating a module in Boozang called “Cart” and create a test called “Checkout item from Cart”. In order to make this test dynamic, use parameter for the form data to make the test dynamic

  "phone": "1112223333",
  "name": "John Doe",
  "address": "69 Love Street",
  "city": "Montreal",
  "state": "QC",
  "zip_code_for_delivery": "N6R 4O9"

The steps you want to record in this test is

  1. Add an item to cart
  2. Click on the Shopping Cart
  3. Click proceed to checkout
  4. Fill out checkout form (using parameter data bind)
  5. Click make payment (triggers API call)

Simply press the record button and do the steps described above, recording the End-2-end test. Make sure to check the data bind box when filling the out the  checkout form, so you can use the data you defined in the parameter section, as seen in the image below

After you have clicked the “Payment” button you can stop recording.

The resulting test should look something like the screenshot below, where the form values have been parameterized.

You should be able to repeat the end-to-end test by pressing “Play” in the test above. Experiment by changing the parameter value in the parameter tab, and make sure the new data is reflected in the test.

Auto-generate API tests in Boozang

In order to auto-generate an API test, make sure you use the Play-button dropdown to run the test with “Generate API’ play mode. The test will run and all API calls will be automatically captured.

When the test has completed, you should see the following dialog

Make sure to remove the “Click Cart” using the “x” button and keep the “Make Payment” button. Click “New API test” and the API test to place the order and make the payment will be automatically generated.

It will look something like

As you can see, the API call has automatically replaced all the calls using dynamic data with the corresponding parameters. Try running this test (in regular play mode) and see how orders are being placed lightning fast using the API.

By using this functionality you can create a data-driven API test without doing any development. There will still be a need of more in-depth knowledge of the API to do more sophisticated stuff. Nevertheless, we still believe that this will enable less technical users to create API tests and speed up API test creation for more advanced users.

For any questions check out our API testing topic in our forum.


Try Boozang today

Codeless testing that works. No credit card or commitment required.