Verify that the API correctly handles large payloads and returns the correct HTTP status code and error message.
Language: Java
Framework: Rest assured
1import static io.restassured.RestAssured.*;23import io.restassured.http.ContentType;4import io.restassured.response.Response;5import org.junit.jupiter.api.Assertions;6import org.junit.jupiter.api.Test;78public class APITesting {910 @Test11 public void testLargePayloads() {1213 String largePayload = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lobortis nulla non lectus accumsan ultricies. Integer convallis purus et velit blandit consequat. Sed eget lectus ut risus mattis euismod.";14 Response response = given().contentType(ContentType.JSON).body(largePayload).when().post("/api/largePayload");1516 //Assert HTTP status code17 Assertions.assertEquals(400, response.getStatusCode());1819 //Assert error message20 Assertions.assertEquals("Payload too large", response.getBody().asString());21 }2223 private void addDesiredCapabilities() {24 //Code to connect to remote client with desired capabilities25 }26}2728//Assumptions: The API endpoint for large payloads is /api/largePayload29//Local Rest Assured API is available30//Remote client connection will be added as desired capabilities to support parallel execution
Language: Javascript
1// Mocha and Chai.23//Assuming the following details:4//Endpoint URL: https://example.com/api5//Maximum Payload Size: 10MB6//Expected HTTP status code for successful response: 2007//Expected error message for large payload: "Payload too large."89const chai = require('chai');10const chaiHttp = require('chai-http');11const expect = chai.expect;1213chai.use(chaiHttp);1415describe('API Testing - Check Large Payloads', function() {16 it('should handle large payloads and return the correct HTTP status code and error message', function(done) {17 const payloadSize = 11 * 1024 * 1024; // 11MB payload size1819 chai.request('https://example.com/api')20 .post('/')21 .send('x'.repeat(payloadSize))22 .end(function(err, res) {23 expect(err).to.be.null;24 expect(res).to.have.status(413); //HTTP status code for payload too large25 expect(res.body).to.have.property('message').eql('Payload too large.'); //Error message for large payload2627 // Uncomment the below code to connect to remote client with desired capabilities28 // const webdriver = require('selenium-webdriver');29 // const remote = require('selenium-webdriver/remote');30 // const capabilities = webdriver.Capabilities.chrome();31 // capabilities.set('customNetworkProtocol', true);32 // capabilities.set('acceptInsecureCerts', true);33 // const driver = new webdriver.Builder()34 // .usingServer('http://localhost:4444/wd/hub')35 // .withCapabilities(capabilities)36 // .build();37 // driver.get('https://example.com');38 // driver.quit();3940 done();41 });42 });43});
Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.
Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.
Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.
Start Free Testing