Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Passing Body as String to POST Request in Rest Assured

Category: Rest Assured
                // There is no need to add escape character manually. Just paste string within double 
		// quotes. It will automatically add escape sequence as required. 
		String jsonString = "{\"username\" : \"admin\",\"password\" : \"password123\"}";
		
		
		//GIVEN
		RestAssured
		.given()
			.baseUri("https://hireqa.co.in/register")
			.contentType(ContentType.JSON)
			.body(jsonString)
		// WHEN
		.when()
			.post()
		// THEN
		.then()
			.assertThat()
			.statusCode(200)
			.body("token", Matchers.notNullValue())
			.body("token.length()", Matchers.is(15))
			.body("token", Matchers.matchesRegex("^[a-z0-9]+$"));

Leave a Reply

Your email address will not be published. Required fields are marked *