1. Docs
  2. Use cases
  3. Use cases
  4. How do I test a REST API without writing code?

How do I test a REST API without writing code?

In SmartestQA you save requests in API Requests, by hand or from a Postman collection, a Swagger / OpenAPI spec or a curl command, and add them to a test case in Automate as API steps. Each step saves values from the response under JSON Paths, and Assertion steps check them, so no code is written and API steps can sit next to UI steps in the same scenario.

12 min read Updated CustomersAdmins

In short

On this page you can

  • Build a library of requests from Postman, Swagger / OpenAPI or curl.
  • Try a request with Send and read status, time and size.
  • Use requests as API steps next to UI steps in one scenario.
  • Save a token, an id or the status code from a response and reuse it.
  • Fail the test on a wrong status code with an Assertion step.

How to use it

  1. Open API Requests and click New Request, or import with More.
  2. Set method, URL, body and Bearer Token, click Send, then Save.
  3. In Automate click API, find the request and click Add Step.
  4. Under JSON Paths save @status and the fields you need.
  5. Add an Assertion step on {{tc:status}} and run the test case.

The short answer#

You do not write code. A request is a saved form: method, URL, headers, query parameters, body and authorization. You keep requests in the API Requests library of the project, try them with Send, and add them to a test case in Automate as API steps. In the step you click a value in the response to save it as a variable, and an Assertion step compares it with what you expect.

One thing to know before you start: an API step passes for every HTTP status, including 400, 401, 404 and 500. The test fails on a wrong status only when you save @status and assert on it.

The problem this solves#

Many teams check their API by hand. A tester keeps a set of requests in an API client, sends them one by one before a release and reads each response. That works for a first look, but nothing fails when a status code or a field is wrong: a person has to notice it, every time.

The usual next step is a set of test scripts. They run on their own, but someone has to write and maintain them, so the testers who know the application best often cannot add a check themselves. And the API tests live apart from the UI tests, although one user journey touches both.

An example#

This is an illustration, not a customer story. A team runs a hotel booking site, and a tester who does not write code has to cover its booking API.

  1. The tester opens API Requests and uses More › Import Swagger / OpenAPI with the spec file. The message reads “Imported 12/12 endpoints successfully!” and a new collection appears in the tree.
  2. In the request that creates a booking, the tester sets the Request URL to {{ds:apiBase}}/bookings, chooses Bearer Token with {{ds:apiToken}} and clicks Send. The response shows “201 Created”. Save answers “API data saved”.
  3. In Automate the tester clicks API, finds the request in Select API Request and clicks Add Step. The step shows the chip API.
  4. In the step the tester clicks Send, clicks the booking id in the response to add it under JSON Paths with the key bookingId, and adds a row with the path @status and the key status.
  5. Two Assertion steps follow: {{tc:status}} Equals 201, and {{tc:bookingId}} Is Not Empty.
  6. The test case runs in a pipeline. One night the API answers 500. The API step itself still passes, the Assertion on {{tc:status}} fails, and the report keeps the request and the response of the step.

The check that a person used to make by reading the response is now a step that fails the test.

By hand, with your own scripts, and with SmartestQA#

QuestionBy hand in an API clientYour own test scriptsSmartestQA
Who can build a test?Anyone who can fill in a requestSomeone who writes codeAnyone who can fill in a request: it is a saved form, and values are saved by clicking them in the response
Where do the requests come from?Typed or imported into the clientWritten in codeNew Request, a Postman collection, a Swagger / OpenAPI spec or a curl command
What fails on a wrong status code?Nothing; a person reads the responseAn assertion in the scriptAn Assertion step on {{tc:status}}. Without it, an API step passes for every HTTP status
Can the same test use the screen too?NoYes, if you also write the browser partYes: API steps sit next to UI steps in one scenario
How does it run on another environment?You switch the address in the clientConfiguration you maintain{{ds:apiBase}} with variants such as apiBase_TEST; a run picks the variant of its environment
What evidence is kept?What the person writes downWhat the script logsThe report keeps the request and the response of each API step, the response shortened to 5,000 characters

Steps#

  1. Fill the library

    Open API Requests from the main menu. Click New Request for a single request. For a whole API, use More › Import Postman or More › Import Swagger / OpenAPI. A curl command pasted into Request URL fills the request: “Curl imported.” See The API library.

    “n/total requests imported successfully!” for Postman, “Imported n/total endpoints successfully!” for Swagger / OpenAPI. A new collection appears in the tree.

  2. Set the request

    Choose the HTTP method and enter the Request URL. Start the URL with a Data Source key, for example {{ds:apiBase}}/orders, so one request works on every environment. Under Body choose raw: a test run sends the raw body. In Request settingsAuthorization choose Bearer Token with {{ds:apiToken}}, a reference to an encrypted key. See Edit and send.

  3. Try it and save it

    Click Send. The response shows a status chip such as “201 Created”, the time in ms and the size. Then click Save.

    “API data saved”. The tree shows the request with its method chip.

  4. Add the request to a test case

    Open the test case in Automate and click API in the step toolbar. The dialog Select API Request lists the library; search with “Search by name, URL or method...”. Click Add Step on the request. Or click Create from curl, paste a curl command and click Create & Add. See Add an API step.

    The step shows the chip API. It gets its own copy of the request.

  5. Save values from the response

    Select the step and click Send. Click a value in the response to add it under JSON Paths, and give it a key. Add a row with the path @status and the key status. After the step runs, each value is available as {{tc:key}}. See Save values from the response.

  6. Check the result

    Add an Assertion after the step: actual {{tc:status}}, Equals, expected 201. Add a second one for a field, for example {{tc:orderId}} Is Not Empty. For a negative test, assert that {{tc:status}} Equals 403. See Check the status code.

  7. Run it

    Check the test case with a Dry Run, then add it to a pipeline in Schedule. In a run the request goes out from the machine that runs the test, the server or your agent, with a fixed timeout of 30 seconds. The report keeps the request and the response of each API step; the response is shortened to 5,000 characters.

What Send does and what a test run does#

Send on the API Requests page is a quick preview. A test run is the real thing, and it differs in these points.

Send on the API Requests pageTest run
Sent fromThe SmartestQA serverThe machine that runs the test: server, agent or self-hosted runner
MethodsPOST, PUT and DELETE as such; GET, PATCH, HEAD and OPTIONS go out as GETGET, POST, PUT, PATCH, DELETE. HEAD and OPTIONS fail with “Unsupported HTTP method”.
ReferencesData Source keys in the URL only, with their default valueEverywhere: URL, headers, params, body, Bearer token; environment variants apply
ParamsNot added; only the query already in the URL is sentAdded to the URL; a parameter already in the URL is not sent twice
Bodyraw as typed; form-data as a JSON objectThe raw body, sent as JSON. form-data rows are not sent.
AuthorizationBearer Token, Basic Auth, Inherit from parentBearer Token only
Time limit30 seconds30 seconds
ResultThe response is shown; any status is a successful SendAny HTTP status passes the step. A timeout, an SSL error or a refused connection ends it as ERROR, and the test case continues.

Details: What a run does differently.

What you can save from a response#

PathReadsExample result
data.token or $.data.tokenA JSON fieldeyJhbGciOi…
items.0.id or items[0].idA field of the first array item, counting from 01042
/order/statusAn XML node; paths starting with / are XPathSHIPPED
@statusThe HTTP status code201
@header:LocationA response header/orders/1042

If a path finds several matches, the first one is used. If it finds nothing at run time, the log notes that the key was not found and the variable is not set.

Watch it#

The video shows the API Requests page: the library with one folder per module, a request opened in the editor, the URL and body, Send with the response underneath, Save, the request settings on the right, and New Request and More. It does not show adding a request to a test case or asserting on the response.

Video transcript

API Requests is the request library of the project, with one folder per module. Each request carries its method: GET, POST, PUT or DELETE. A folder can hold requests for one flow, such as login with good and bad credentials. Select a request to open it in the editor. Set the URL and the body. Values can come from Data Center keys and datasets. Send tries the request and shows the response underneath. Save keeps it for your tests. Authorization, parameters and headers are on the right. A request can inherit them from its folder. New Request adds one by hand; More imports a whole API description.

A library of requests that your tests can reuse.

What you get#

  • Three ways in. Postman collection JSON, Swagger / OpenAPI as JSON or YAML file or as a JSON URL, and curl commands, for example copied from the browser’s developer tools.
  • UI and API in one scenario. Create an order through the API and check it in the browser, or the other way round. API Requests is the same in WEB, MOBILE and DESKTOP projects.
  • Values that flow. A token or an id saved under JSON Paths is used by later steps as {{tc:key}} in URLs, headers, bodies and the Bearer token.
  • One request for every environment. {{ds:apiBase}} with variants such as apiBase_TEST: a run picks the variant of its environment.
  • Secrets kept out of logs. The run masks Authorization, token and API key headers in its logs.
  • Evidence per step. The report keeps the request and the response of each API step.
  • Clear limits. URL up to 2,048 characters, 30 seconds per request, methods in runs GET, POST, PUT, PATCH and DELETE.

Questions and answers#

Do I need to write code or scripts to test an API in SmartestQA?Customers

No. You fill in the request on the API Requests page, add it to a test case as an API step, click values in the response to save them, and compare them in Assertion steps. See API Request step.

Can I import my Postman collection or my OpenAPI spec?Customers

Yes. In API Requests, More › Import Postman takes a collection exported as JSON, and More › Import Swagger / OpenAPI takes a JSON URL or a JSON or YAML file. Postman variables are kept as text and security schemes of a spec are not imported, so set base URL and authorization afterwards. See Import a Swagger / OpenAPI spec.

Can I mix API calls and UI steps in the same test?Customers

Yes. In SmartestQA API steps can sit next to UI steps in any scenario, in WEB, MOBILE and DESKTOP projects. A value saved by an API step, such as an order id, is typed or checked in the UI as {{tc:orderId}}. See Pass a value from one step to another.

Why does my API step pass although the API returned 404 or 500?Customers

An API step in SmartestQA ends as SUCCESS for every HTTP status. Only a timeout, an SSL error or a refused connection ends it as ERROR. Save the status with the path @status under JSON Paths and add an Assertion step on it. See Check the status code.

How do I send a token, and where do I store it?Customers

Store it in an encrypted Data Source key, for example apiToken, and set Bearer Token to {{ds:apiToken}} in the request. If the token comes from a login call in the same test, save it there under JSON Paths and use {{tc:accessToken}}. See Authorization in runs.

Does Basic Auth work in a test run?Customers

Not through the Basic Auth type: a run applies only Bearer Token, and Inherit from parent is ignored too. Add a header Authorization with the value Basic {{ds:apiBasicAuth}}, where an encrypted key holds the Base64 of user:password. See Can I use Basic Auth in tests?

Can I test an API that is only reachable inside our network?Customers

Yes, in runs on an agent or self-hosted runner inside the network. Send and Swagger URL imports go out from the SmartestQA server and cannot reach it, so import the spec as a file and check requests with a Dry Run on the agent. See Our API is only reachable inside our network.

Which HTTP methods can I test?Customers

You can save GET, POST, PUT, DELETE, PATCH, HEAD and OPTIONS. Test runs send GET, POST, PUT, PATCH and DELETE; HEAD and OPTIONS fail at run time with “Unsupported HTTP method”. See Limits.

Does it work with SOAP or XML APIs?Customers

You can store and send XML bodies from the API Requests page, and a path starting with / reads an XML response as XPath. In a run the body is sent as JSON, and a body that is not JSON goes out as one JSON text in quotes, so check an XML request with a Dry Run before you rely on it. See Bodies in runs.

If I change a request in the library, do my tests change too?Customers

No. Each API step keeps its own copy of the request, and steps keep working even after the saved request is deleted. To change many tests at once, keep what changes in references such as {{ds:apiBase}} and {{ds:apiToken}}. See Each step keeps its own copy.

Read more#

Didn’t find your answer?Write to support with your project name and what you see on screen.

info@smartestqa.ai