Adding API Step to your Test
Test cases are not just a set of steps performed on your screen. Today, test cases require creating runtime test data from API responses and using that data in subsequent steps (or deleting data after the test has completed execution). This makes automated tests reusable and resilient.
To add an API Step to Test, complete the following steps:
- Click the API Step Icon present towards the bottom end of the Action Bar:
- This will result in the API Step Modal to appear:
- API Step Configuration: Next, specify the Request URL and select the type of Request. Sofy currently supports the following:
- API Step Variable: You can save the API response in a variable and use it inside the API Step Dialog box in the body, as well as in headers, query parameters, and path variables.
- Add the URL, choose a request type, and click "send". As an example, here, we send a GET request to https://simple-books-api.glitch.me/books and obtain the following response:
- Once a response is obtained, by clicking on the path or value of the response, the user can store the path in a user-created variable. This variable is assigned a value later during the lab run.
- In this example, when you click on "id", you will see a '+' symbol next to it, clicking on which will add a test variable towards the bottom of the modal
- We can also define multiple test variables at once (upto 10 at a time). You can easily add more test variables by clicking on the '+' symbol next to any given parameter in the API response. For example, here we can define test variable for both "id" as well as "name":
- Based on our use case, you can also define regular expressions (REGEX) on the response to save only the relevant part as a variable. For example, you may want to store a only the second word of any given string and therefore may want to use a regex in this case as shown here:
- Finally, click Add API Step to successfully save the variable: