Workflow:MarketSquare Robotframework browser API Testing via Browser
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, API_Testing, Network |
| Last Updated | 2026-02-12 04:00 GMT |
Overview
End-to-end process for performing HTTP API testing and network request interception using the Browser library's network keywords.
Description
This workflow covers using the Browser library's network capabilities to make HTTP requests, intercept and mock network traffic, and wait for specific requests and responses. The HTTP keyword sends requests in the context of the current browser page (inheriting cookies and session state), while Route and Mock keywords allow intercepting and modifying network traffic for testing purposes. This enables combined UI and API testing within the same Robot Framework suite.
Usage
Execute this workflow when you need to test REST APIs in the context of a browser session (with shared cookies and authentication), intercept network traffic for mocking backend responses, or verify that specific HTTP requests are made during user interactions.
Execution Steps
Step 1: Establish Browser Context
Open a browser and create a context with the appropriate settings. If the API endpoints require authentication, first log in through the UI or restore a saved storage state to ensure the browser session has valid cookies and tokens.
Key considerations:
- API requests made via the HTTP keyword inherit the page's cookies and session
- Use Save Storage State and New Context with storage state for auth reuse
- Context-level proxy settings can route requests through a specific proxy
Step 2: Send HTTP Requests
Use the HTTP keyword to send GET, POST, PUT, DELETE, and other HTTP requests. The request is executed within the browser page context using Playwright's page.evaluate with fetch, so it inherits all cookies, headers, and CORS context of the current page.
Key considerations:
- The HTTP keyword returns a response object with status, headers, and body
- Request body can be provided as a JSON string or object
- Requests execute in the same origin context as the loaded page
- Response parsing supports JSON and text formats
Step 3: Intercept and Mock Network Requests
Use Route keywords to intercept outgoing network requests and modify them. This allows replacing backend responses with mock data, simulating error conditions, or delaying responses to test loading states.
Key considerations:
- Routes match requests by URL pattern or glob
- Intercepted requests can be fulfilled with custom response bodies and status codes
- Multiple routes can be stacked; the most recently added route takes priority
- Use Unroute to remove intercepts when no longer needed
Step 4: Wait For and Capture Network Traffic
Use Promise To Wait For Response and Promise To Wait For Request to capture specific network requests triggered by user interactions. This enables asserting that clicking a button sends the expected API call with the correct payload.
Key considerations:
- Use matcher patterns (URL string, glob, or regex) to identify target requests
- Promises must be created before the action that triggers the request
- Wait For resolves the promise and returns the captured request/response data
- Timeout can be configured per wait operation
Step 5: Validate API Responses
Parse and assert the captured HTTP response data, including status codes, response headers, and response body content. Combine with Robot Framework's built-in assertion keywords for comprehensive validation.
Key considerations:
- Response objects provide status, statusText, headers, body, and url properties
- JSON response bodies can be parsed and validated field by field
- Combine API assertions with UI assertions for full end-to-end verification