Simulating API Calls & Using REST Assured
What Is REST Assured?
REST Assured is a popular Java library specifically designed for testing REST APIs. It provides a readable, fluent syntax for sending requests and validating responses, making API tests easy to write and maintain.
Writing a Basic REST Assured Test
A typical REST Assured test follows a clear given-when-then structure: specify request details, perform the call, then validate the response - all in a single readable chain.
- given() - sets up request details like headers or parameters
- when() - specifies the HTTP method and endpoint to call
- then() - validates the response, such as status code or body content
Common Validations
| Validation | Purpose |
|---|---|
| statusCode(200) | Confirms the request succeeded |
| body("field", equalTo(value)) | Validates specific fields in the response body |
| time(lessThan(2000L)) | Confirms the response returned within an acceptable time |
Combining API and UI Tests
A common pattern is using REST Assured to quickly set up test data via API calls - like creating a user account - before running a Selenium UI test against that data, saving significant setup time.
With both UI and API testing covered, the next step is understanding how these tests fit into a broader CI/CD pipeline.
Ready to master Selenium Training Course?
Join Uncodemy's hands-on training and build real automation skills with expert mentors.
← Back to Course