Skip to main content

API testing

Start here when you want one REST call, one assertion, and request/response evidence in the same report as your browser and mobile tests.

import com.shaft.driver.SHAFT;
import org.testng.annotations.Test;

public class CountryApiTest {
@Test
public void getCountryByCapital() {
SHAFT.API api = new SHAFT.API("https://restcountries.com/v3.1/");

api.get("capital/Cairo").perform();
api.assertThatResponse()
.extractedJsonValue("[0].name.common")
.isEqualTo("Egypt");
}
}

Continue with request building, authentication, and response assertions. When the API is part of a browser journey, use UI and API contract replay to record the exchanged traffic once and assert or replay it later.

Run and inspect evidence

Run the test from the project root:

mvn test

SHAFT attaches request, response, status, headers, body, and assertion evidence under allure-results and the generated Allure report under the project target output. If the request fails before assertions, check the base URI, proxy settings, authentication, and whether automatic 2xx status assertion is appropriate for the scenario.

First useful next steps

NeedStart with
Add headers, query parameters, or bodyRequest Builder
Reuse tokens or basic authAPI Authentication
Validate JSON fields or schemasResponse Validations
Record and replay UI/API trafficUI and API contract replay
Track OpenAPI coverageAPI configuration