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
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>3.3.0</version>
</dependency>
@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) {
testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}

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

@AfterClass(alwaysRun = true)
public void tearDownClass() {
testNGCucumberRunner.finish();
Reporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));
}
}
//API URL
RestAssured.baseURI = "http://www.mocky.io/v2/5c78ed70300000a42d49b04d";

//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);
System.out.println(response.getStatusCode());

--

--

--

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 make a test using Selenium Core?

How To Switch Between iFrames In Selenium Java [Tutorial]

Handling iFrames in Selenium Based Test Automation

How to implement POM in Selenium Java