1. Docs
  2. Use cases
  3. Use cases
  4. How do I turn a UI test into API tests?

How do I turn a UI test into API tests?

In SmartestQA a web test case with a Network step in List mode records the calls the browser makes during a pipeline run. In Maintenance, on the Network Calls tab, Make API test turns the calls you pick into API Request steps in a new test case, with the login token extracted and secrets replaced by variables.

10 min read Updated CustomersAdmins

In short

On this page you can

  • Capture the API calls behind a web UI flow during a normal run.
  • Turn the captured calls into API Request steps in a new test case.
  • Keep the login: the token is extracted and sent by the later requests.
  • Replace the host with a {{baseUrl}} variable for every environment.
  • Generate a JMeter test from the new API test case.

How to use it

  1. Add a Network step in List mode at the end of the web test case.
  2. Run the test case in a pipeline.
  3. Open Maintenance, tab Network Calls, and click Make API test.
  4. Pick the requests, set the two options and click Create with n steps.
  5. Define the listed variables, add assertions and run the new test case.

The short answer#

You do not rebuild the requests by hand. A Network step in List mode writes the calls of the browser session, with their requests and responses, to the report. After the test case has run in a pipeline, Maintenance lists it on the Network Calls tab. Click Make API test, pick the requests, and SmartestQA creates a new test case in the same folder with one API Request step per request, in capture order.

Network steps exist only in WEB projects, so this path starts from a web test.

The problem this solves#

Many teams have UI tests for their main flows and few or no API tests. To add them, someone has to find out which calls a screen makes. Often that means opening the browser’s developer tools, clicking through the flow and copying the calls one by one into a client or a script.

That takes patience, and it has traps. The copied calls carry a token that soon expires, and sometimes a password. The login has to be rebuilt so later calls get a fresh token. When the flow changes, the copying starts again. So the API tests are often put off, although the UI test already makes every call that is needed.

An example#

This is an illustration, not a customer story. A team tests an HR portal and has a web test case named “Submit leave request” that logs in, fills the form and checks the confirmation.

  1. A tester opens the test case in Automate, clicks Network, picks List and Set it up myself, leaves the URL empty and adds the step at the end. It shows the chip Net List.
  2. The test case runs in the nightly pipeline, as it did before.
  3. The next morning the tester opens Maintenance and the Network Calls tab. Under Pending there is one row for the test case, and the tester clicks Make API test.
  4. The dialog Network → API steps opens on the filter API calls. The request marked Login and the portal’s own calls are pre-selected, and the counter says “6 requests selected”. The tester turns on Replace the host with a {{baseUrl}} variable (update it in one place per environment).
  5. The name is pre-filled as “Submit leave request - API”. A click on Create with 6 steps answers “Submit leave request - API created (6 API steps)”. The new test case opens in Automate and the row moves to Converted.
  6. The tester defines the listed variables, among them baseUrl and the password that was masked, adds an Assertion on the status of each response and runs the test case.

The team now has an API test for the flow without having copied a single call.

Copied by hand, with your own scripts, and with SmartestQA#

QuestionCalls copied by hand from the browserYour own API test scriptsSmartestQA
How do you find the calls a screen makes?Click through the flow with the developer tools openRead the API documentation or ask the developersA Network step in List mode writes them to the report during a pipeline run
Who builds the requests?A person, one by oneSomeone who writes codeMake API test creates one API Request step per selected request, in capture order
What happens to the login?The copied token works until it expiresYou write the login call and pass the token onThe token of the login request is stored in {{authToken}} and later requests send it
What happens to passwords and tokens?They are in the copied call unless you remove themIn configuration you manageThe report masks them as ***; the conversion turns them into variables that you fill in
What is left for you to do?Everything after the copy, including the checksEverythingDefine the listed variables, add custom headers your API needs, and add assertions: an API step passes for every HTTP status
Where does it work?Any application you can open in a browserAny APIWEB projects only, for test cases that have run in a pipeline or scheduled run

Steps#

  1. Add a Network step in List mode

    Open the web test case in Automate and click Network on the step toolbar. In the dialog Add Network step pick List and Set it up myself. The URL is optional (“Leave empty to list every call.”). Fill Test Step Name and click Add. Put the step at the end of the flow: by default List uses the Scope “Whole session”. See List.

    The step appears with the chip Net List.

  2. Run the test case in a pipeline

    The Network Calls tab lists a test case only after it has run in a pipeline or scheduled run. New runs update the row; they do not add rows.

  3. Open Network Calls

    Open Maintenance and the Network Calls tab. It opens on Pending, with one row per test case: “s Network steps · c calls”, the date of the latest run and the number of runs. Click Make API test. From a report, Convert to API steps brings you to the same dialog.

  4. Pick the requests

    The dialog Network → API steps opens on the filter API calls. Tick or untick rows, or use Select All for the visible filter. The counter says “n requests selected”. Keep the request marked Login selected whenever later calls need a token.

  5. Choose the two options

    Add Bearer {{authToken}} to requests after login is on by default: requests after the login request send its token. Replace the host with a {{baseUrl}} variable (update it in one place per environment) is off by default; turn it on when the same API runs on several environments.

  6. Read the warnings, name and create

    The dialog lists what you must fill in afterwards, for example “You need to define values for these variables: …”. New test case name is pre-filled as “<test case> - API”. Click Create with n steps.

    “<name> created (n API steps)”. The new test case opens in Automate, and the row moves to Converted.

  7. Finish the API test case

    Define the listed variables, add any custom headers your API needs, add assertions on the responses, and run it. An API step passes for every HTTP status, so the assertions are what make the test fail. See Check the status code.

What the conversion does with the capture#

In the captureIn the new API test case
Each selected requestOne API Request step, in capture order, named by method and path, for example POST /api/orders. Query parameters are kept.
The login request (its response contains a session token)A JSON extractor stores the token in {{authToken}}, and a refresh token in {{refreshToken}}.
A masked Authorization headerBearer {{authToken}}
A masked header or body field, such as a passwordA {{name}} variable; you fill in the value.
Browser headers: Host, Cookie, User-Agent, Referer, Origin, caching and similarNot copied
A body that is truncated in the reportMarked “truncated”: “The body is truncated in the report. Complete it after saving.”
The new test caseCreated in the folder of the source test case, with its environment, and the description “Generated from the Network capture of the "<name>" run.”

Which requests are pre-selected#

RequestPre-selected
Your app’s own API calls that did not fail, each method and path onceYes
The login request, marked LoginYes, unless it goes to a third-party site
The same method and path again, marked “duplicate”No, only the first
Requests to other sites, analytics and tracking servicesNo
Static files: scripts, styles, images, fontsNo
WebSocket and event streamsNo
OPTIONS and HEAD requestsNo

The filters Pages, Static, Third party, Other and All appear when there are such requests, so you can still tick them. See Make an API test, step by step.

What you get#

  • An API test from a run you already have. One API Request step per selected request, in the order the browser made the calls.
  • A working login. The token of the login request is stored in {{authToken}} and the later requests send it.
  • No secrets copied. The report masks Authorization, Cookie, Set-Cookie and X-API-Key headers and body fields such as password, token, secret or otp as ***; the conversion turns them into variables.
  • One switch per environment. With the {{baseUrl}} option the host is a variable; set baseUrl as a suite parameter.
  • A clear status. The test case stays under Converted with a link to the API test case, even after later runs.
  • A path to load tests. A JMeter test can be generated from the new test case in Automate.

Questions and answers#

Which test cases can I convert to API tests?Customers

Test cases that have a Network step and have run in a pipeline or scheduled run. SmartestQA lists them in Maintenance on the Network Calls tab, one row per test case; the latest run of each Network step is used and all Network steps of the test case are combined in one list. See What the tab lists.

Why is my test case not on the Network Calls tab?Customers

The tab lists a test case only when it has a Network step and has run in a pipeline or scheduled run. It opens on Pending; a test case that was already converted is under Converted. See My test case is not listed.

Does this work for mobile or desktop tests?Customers

No. Network steps exist only in WEB projects and are not offered in mobile and desktop projects. In those projects you can still add API steps from the API Requests library. See Network step limits.

Which Network step mode should I use for the capture?Customers

List, for the whole session. Check and Get value capture a single request. List hides static files such as CSS, scripts and images and reports API calls, page loads and errors. See The three modes.

Does the capture see every call with Selenium and with Playwright?Customers

Playwright sees all calls. Selenium sees fetch and XHR calls, and the first page load only in Chrome and Edge; iframes, service workers, sendBeacon, form posts and static files are not seen. See Limits.

What happens to passwords and tokens in the captured calls?Customers

They are not copied. The report shows them as ***, and the conversion adds them as variables: a masked Authorization header becomes Bearer {{authToken}}, a masked header or body field becomes a {{name}} variable that you fill in. See What gets created.

What does “Requests use {{authToken}}, but no selected request produces a token.” mean?Customers

The requests you picked send a token, but the login request is not among them. Select the request marked Login whenever later calls need a token. Each warning of the dialog is explained in Troubleshooting.

Can the API test run on DEV, TEST and PRP?Customers

Yes. Turn on Replace the host with a {{baseUrl}} variable (update it in one place per environment) in the dialog and define baseUrl, for example as a suite parameter in the pipeline. See “{{baseUrl}} must be defined at run time”.

My API needs a tenant or language header. Is it copied?Customers

No. A List capture has no request headers, so add such a header to the API steps after the conversion. See The request.

Can I convert the same test case again?Customers

The test case stays under Converted, even after later runs. If you delete the API test case that was created, the row returns to Pending and you can convert it again. See After the conversion.

Can I load test the calls I captured?Customers

Yes, in two steps: make the API test in Maintenance, then generate a JMeter test from that test case in Automate. See Generate with AI from API steps.

Read more#

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

info@smartestqa.ai