If you use the “Web API call” (Figure 1) command, you can run the Web API (REST API) in a test script. As API calls are performed from the user PC, it is simple to call API(s) provided by the in-company server.
The Web API calls support calls to the HTTP GET / POST / PUT / DELETE methods.
Figure 1 “Web API Call” command
On Cloud devices or external Clouds, the URLs that can call Web API are restricted, and you may see the error message “Currently the cloud test run does not support webApi command”. This problem can be resolved, so please contact MagicPod support with the information about the URL domain to which you are trying to connect. As it is necessary to use URLs including Japanese, etc., these can also be treated as query character strings.
As an example, let us try accessing the RANDOM USER GENERATOR, which enables you to acquire different user information at random in JSON format, as shown in Figure 2.
To simplify the explanation, we have removed a great deal of the information from the actual API response in Figure 2.
Figure 2 JSON response of RANDOM USER GENERATOR
First, click the “Edit” button in Figure 1 to open the Edit dialog box. Then, specify “GET” for the method and “https://randomuser.me/api?format=json” for the URL as shown in Figure 3.
Figure 3 HTTP GET method call
Values set as variables can be referenced with “$(variable name)” in subsequent commands in the same test case. As shown in Figure 3, we can set the user's last name in variable LN and their first name in variable FN, and this can then be used to set a random user name in the input area, as shown in Figure 4.
Figure 4 Using the variables for the HTTP response
- The saved variables are only valid within the same test case. They cannot be used in other test cases.
- If you want to specify an HTTP request header, specify the “Header” tab in the dialog box in Figure 3.
- The query parameter of the GET method can be specified with the format “?<key 1>=<value 1>&<key 2>=...” after the URL.
The method for specifying the method name, URL, header, and response are the same as for the GET method.
Additionally, in the case of the POST / PUT / DELETE methods, you can specify the body of the request on the “Body” tab, as shown in Figure 5. The body value can be either "form data format" (POST method only) or "raw data format" (text format).
Figure 5 HTTP POST method calls