πŸ“‘Network Calls

There are two ways of making network calls as part of a test:

  1. Simple GET requests as part of the test prompt.

  2. CURL network requests before the test prompt execution.

Simple GET Requests as Part of the Test Prompt

Scenario

A typical scenario is to retrieve an OTP code to authenticate a user during a test.

  • Assuming there is an endpoint to retrieve an OTP code:

https://customer-api.com/fetch-otp?customer=...&apiKey=...
  • Assuming the response format is a simple JSON object:

{
  "otp_code": "123456"
}

How to Make the Network Request as Part of the Test Prompt

The first step will prompt GPT Driver to initiate a network request and remember the 'otp_code' from the response. As demonstrated in the example below, you can utilize env variables (found in Settings) as part of the URL, for example, for API tokens.

1. Perform a network request to https://customer-api.com/fetch-otp?customer={{env.username}}&apiKey={{env.api-token}} with the json selector β€˜otp_code’
2. Enter the remembered otp_code in the password field

In Step 2, you'll learn how to use the extracted data from Step 1 by simply referring to it as 'remembered'.

If you require the capability to make more complex network requests, such as POST or DELETE requests with payloads, please refer to the next section where we explain how to leverage the so-called 'pre-request' feature.

CURL Network Requests Before the Test Prompt Execution

If you require greater flexibility, our system enables you to execute CURL commands before the test prompt execution, allowing you to remember values from the responses for use in your test prompt.

To utilize this option, follow these steps:

Step 1: Define the CURL command

  1. Navigate to the 'Settings' tab within your test.

  2. In the 'Pre-requests' section, you have the option to define multiple CURL commands that will be executed sequentially.

  3. Examples of typical CURL commands might include the following:

    • Perform a DELETE request to clean a user account before initiating a test.

    • Create a new user account and retrieve credentials to be used in the test prompt.

curl -X DELETE "https://api.example.com/users/123/order-history" -H "Authorization: Bearer {{env.apitoken}}"
curl -X POST "https://api.example.com/users/create" \
     -H "Content-Type: application/json" \
     -d '{"userType": "premium"}'

Step 2: Use the dot syntax to specify which values to remember

  1. If your request returns values that you want to use within the test prompt, you can simply define them using a dot selector syntax.

  2. Example response:

{
	"username": "generated_user_123",
	"password": "123456"
}
  1. Define the values to remember for the test prompt.

Step 3: Incorporate the remembered value into the test prompt.

  1. Values defined in the pre-request settings can be easily referenced in the test prompt using the 'remembered' keyword.

  2. Example:

1. Tap on the username input field
2. Type the remembered username

Last updated