Rest Assured with TestNG

  • Maven based Java project
  • BDD method used via Cucumber
  • Selenium for automating UI use cases
  • TestNG used to run tests
  • Integrating REST API related automation tests
  • Integrate Rest Assured Library and using it within the framework
@BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());

@Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {

public Object[][] features() {
return testNGCucumberRunner.provideFeatures();

@AfterClass(alwaysRun = true)
public void tearDownClass() {
Reporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));
RestAssured.baseURI = "";

//HTTP request
RequestSpecification httpRequest = RestAssured.given();
//Getting response
Response response = httpRequest.request(Method.GET);
//Response response = httpRequest.request(Method.GET, "/city");

//Getting response body to verify/assert
String responseBody = response.getBody().asString();
System.out.println("Response Body is => " + responseBody);




Techie | Traveler | Writer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dilshani Subasinghe

Dilshani Subasinghe

Techie | Traveler | Writer

More from Medium

How To Switch Between iFrames In Selenium Java [Tutorial]

How To Handle Multiple Windows In Selenium WebDriver Using Java?

How to Upload File using Selenium Webdriver

File Handling in Java