Hello...
I would like to share my idea of automating RESTful API testing without using an automation tool.
This is quite interesting and challenging and has a very steep learning curve if took seriously, you can save thousands of Dollars to your organisations by developing your own Test-Automation framework for RESTful API testing.
The beautiful thing of this framework is, it is easy to maintain and can be integrated with all your continuous integration servers like Jenkins. The tests can be run on a nightly build and the TestNG report can be emailed to the concerned group of IDs.
There are many free API test libraries that would help you to automate your tests, but over a time the limitations stops your automation and you have to go for an alternative.
-----------------------------------------------------------------------------------------------------------
Things required to start:
1) Your favourite Java IDE, (I use Eclipse).
2) Apache Http Library (click here to download).
3) Apache Excel POI (click here to download).
4) TestNG (click here to download), please download 'Ant/Maven', version of TestNG not the eclipse version.
5) ANT ( click here to download), this is for build+run of your Java classes.
6) Gson (click here to download), to handle/manipulate JSON response.
People who are good with Junit can replace TestNG with it. But I prefer TestNG because of its features.
It generates a beautiful HTML report at the end which gives an detailed info of tests passes/failed and skipped.
Below are the different Java classes each performing a unique task in automation.
1) BaseTasking.java : This class does the following,
2) DataReader.java : This is class reads the input parameters from a spread sheet and passes it to the data provider in the 'BaseTasking.java' class.
3) TestCollection.java : This class has a collection of tests.
4) RestulValidator.java : This class contains the logic for validating the results from an API call.
5) Testng.xml : This xml file will have the collection of test classes that are to be executed.
6) Build.xml : This xml file is used to compile and run the test-suite using Ant.
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
1) BaseTasking.java
package myTest;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.util.Properties;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.testng.Reporter;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
public class BaseTestFactors {
static DefaultHttpClient httpClient;
BufferedReader br=null;
HttpResponse response=null;
String URL=null;
String AuthenticationKey=null;
String TCNUM=null;
String Environment=null;
String MethodName=null;
String Stores=null;
String Products=null;
String Parameters=null;
String ExpectedJson=null;
public static String Execute=null;
public static String TestDescription="No description available for this test case now.. will be added soon";
@BeforeClass
public static void SetUpSuite(){
}
// every @Test method will call this data provider, and based on the Test method name they'll get their data.
@DataProvider(name = "MyData")
public static Object[][] dataProvider(Method meth) throws IOException {
System.out.println("inside the dataprovider class");
Properties prop = new Properties();
InputStream input = null;
int SheetNumber=0, TestNumber=0;
DataRead E=new DataRead();
try {
input = new FileInputStream("ReferenceFiles/TestDescription.properties");
prop.load(input);
TestDescription=(prop.getProperty(meth.getName().toString().trim()));
input = new FileInputStream("ReferenceFiles/Environment.properties");
prop.load(input);
String TestGroup=(prop.getProperty((meth.getName().toString()).substring(0,4)).trim());
String TestNumberString=((meth.getName().toString()).substring(5,7)).trim();
System.out.println("TCNUM "+TestNumberString);
TestNumber=Integer.parseInt(TestNumberString);
System.out.println(TestNumber);
SheetNumber=Integer.parseInt(TestGroup);
} catch (IOException ex) {
ex.printStackTrace();
}
catch (NullPointerException e) {
System.out.println("caught an exception while reading properties file");
}
String[][] StrData=E.ReadEXCEL(SheetNumber);
int Row=Excelread.RowSize;
int Col=Excelread.ColumSize;
Object[][] TempData = new Object[Row][Col];
Object[][] data= new Object[1][Col];
for(int x=0;x<Row;x++){
for(int y=0;y<Col;y++){
TempData[x][y]=StrData[x][y];
}
}
data[0]= TempData[(TestNumber-1)];
return data;
}
public void ExecutionCheck(){
if(Execute.equalsIgnoreCase("N"))
throw new SkipException("Skipping - This Test case was aksed to be SKIPPED ");
}
@SuppressWarnings("deprecation")
public String[] MyTestGerneral() throws JSONException{
System.out.println("InsideTest-"+TCNUM);
Reporter.log(TCNUM+":- "+TestDescription);
String CompleteURL=null;
String ValidationResults[]= new String[2];
Properties prop = new Properties();
InputStream input = null;
try {// Setter for TestEnvironment IP/FQDN
input = new FileInputStream("ReferenceFiles/Environment.properties");
prop.load(input);
String PropRead[]=(prop.getProperty(Environment).split(","));
System.out.println("property read"+PropRead[0]+" "+PropRead[1]);
URL=PropRead[0].toString();
AuthenticationKey=PropRead[1].toString();
CompleteURL=getURL();
System.out.println(CompleteURL);
} catch (IOException ex) {
ex.printStackTrace();
}
try {// Make HTTP Call
org.apache.http.Header[] headers=null;
String headerMessage= null;
String JExpected= ExpectedJson;
String JActual="[{\"NoJSON\":\"No\"}]";
System.out.println("before http call");
HttpResponse Temp_response=RESTCall(CompleteURL);
System.out.println(Temp_response.toString());
if (Temp_response != null){
System.out.println("after http call");
br = new BufferedReader(new InputStreamReader(Temp_response.getEntity().getContent()));
int actualRespCode=Temp_response.getStatusLine().getStatusCode();
if(actualRespCode != 200){
try{
headers = Temp_response.getHeaders("CustomMessage");
headerMessage= headers[0].toString();
}
catch(ArrayIndexOutOfBoundsException e)
{
headerMessage="NO Error Message in the response";
}
}
if(actualRespCode == 200){
JActual =GETJSONRESULT(br);
}
ResultValidator ResVal= new ResultValidator();
System.out.println("before validation");
ValidationResults=ResVal.Validate(TCNUM,JExpected.toString(),JActual.toString(),headerMessage,actualRespCode);
httpClient.getConnectionManager().shutdown();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ValidationResults;
}// end of myTestGeneral method
/*Method to the get the URL*/
public String getURL(){
int option=0;
String CompleteURL=null;
if(MethodName.equalsIgnoreCase("SS1-V1")) option=1;
else if(MethodName.equalsIgnoreCase("SS2-V1")) option=2;
else if(MethodName.equalsIgnoreCase("SS3-V1")) option=3;
else if(MethodName.equalsIgnoreCase("SS4-V1")) option=4;
else if(MethodName.equalsIgnoreCase("SS5-V1")) option=5;
else if(MethodName.equalsIgnoreCase("SS6-V1")) option=6;
else if(MethodName.equalsIgnoreCase("SS7-V1")) option=7;
else if(MethodName.equalsIgnoreCase("SS8-V1")) option=8;
else if(MethodName.equalsIgnoreCase("SS1-V2")) option=9;
else if(MethodName.equalsIgnoreCase("SS2-V2")) option=10;
else if(MethodName.equalsIgnoreCase("CRACK")) option=11;
else if(MethodName.equalsIgnoreCase("ROOT")) option=12;
else if(MethodName.equalsIgnoreCase("ACURCY")) option=13;
else if(MethodName.equalsIgnoreCase("ADJOIN")) option=14;
switch(option){
case 1:
CompleteURL="http://"+URL+"/v1/Stock/method1/"+Stores+"?"+"productIds="+Products+"&"+Parameters;
break;
case 2:
CompleteURL="http://"+URL+"/v1/stock/"+"method2/"+Products+"?"+"locationids="+Stores+"&"+Parameters;
break;
case 3:
CompleteURL="http://"+URL+"/v1/stock/"+"method3/"+Stores+"?"+"productIds="+Products+"&"+Parameters;
break;
case 4:
CompleteURL="http://"+URL+"/v1/Stock/"+"method4/"+Stores+"?"+"productIds="+Products+"&"+Parameters;
break;
case 5:
CompleteURL="http://"+URL+"/v1/stock/"+"method5/"+Products+"?"+"locationids="+Stores+"&"+Parameters;
break;
case 6:
CompleteURL="http://"+URL+"/v1/method6/all/"+Products+"/"+Stores+"?business=Group";
break;
case 7:
CompleteURL="http://"+URL+"/v1/stockcr/method7/"+Stores+"?productId="+Products+"&business=Group";
break;
case 8:
CompleteURL="http://"+URL+"/v1/stockcr/method8/"+Products+"?locationId="+Stores+"&business=Group";
break;
case 9:
CompleteURL="http://"+URL+"/v2/stock/method9?productIds="+Products+"&locationIds="+Stores;
break;
case 10:
CompleteURL="http://"+URL+"/v2/stock/method10?productIds="+Products+"&locationIds="+Stores;
break;
case 11:
CompleteURL="http://"+URL+"/v2/stock/method11?productIds="+Products+"&locationIds="+Stores+"&business=Group";
break;
case 12:
CompleteURL="http://"+URL+"/v2/stock/method12/"+Stores+"productIds="+Products;
break;
case 13:
CompleteURL="http://"+URL+"/v2/stock/method13?productIds="+Products+"&locationIds="+Stores;
break;
case 14:
CompleteURL="http://"+URL+"/v1/stockcr/method14/"+Stores+"?business=Group";
break;
case 0:
CompleteURL=null;
break;
}
return CompleteURL;
}
/*Method to call the rest method*/
public HttpResponse RESTCall(String URLData) throws IOException{
HttpGet getRequest = new HttpGet(URLData);
getRequest.addHeader("accept", "application/json");
getRequest.addHeader("Authorization", AuthenticationKey);
httpClient = new DefaultHttpClient();
response = httpClient.execute(getRequest);
return response;
}
/*Method to return the JSON Array result*/
public String GETJSONRESULT(BufferedReader Buff) throws IOException, JSONException{
String output=null;
String JasonResponse="";
System.out.println("Output from Server .... \n");
while ((output = Buff.readLine()) != null) {
System.out.println(output);
JasonResponse=JasonResponse+output.toString();
}
System.out.println(JasonResponse);
//JSONArray temp1 = new JSONArray(JasonResponse);
return JasonResponse;
}
public String[] MyPOSTModule() throws JSONException{// Method for POSTing the JSON data.
System.out.println("InsideTest-"+TCNUM);
Reporter.log(TCNUM+":- "+TestDescription);
String CompleteURL=null;
String ValidationResults[]= new String[2];
ValidationResults[0]="PASS";ValidationResults[1]="Looks SUccessfull";
Properties prop = new Properties();
InputStream input = null;
try {// Setter for Environment Variable
input = new FileInputStream("ReferenceFiles/Environment.properties");
prop.load(input);
String PropRead[]=(prop.getProperty(Environment).split(","));
System.out.println("property read"+PropRead[0]+" "+PropRead[1]);
URL=PropRead[0].toString();
AuthenticationKey=PropRead[1].toString();
CompleteURL=getURL();
System.out.println(CompleteURL);
} catch (IOException ex) {
ex.printStackTrace();
}
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
FileInputStream inStrm = new FileInputStream("ReferenceFiles\\PostMethodJSON\\"+TCNUM+".txt");
byte[] fileData = new byte[input.available()];
inStrm.read(fileData);
inStrm.close();
String JSONData= new String(fileData, "UTF-8");
HttpPost postRequest = new HttpPost(CompleteURL);
postRequest.addHeader("Authorization", AuthenticationKey);
StringEntity StockJSON = new StringEntity(JSONData);
StockJSON.setContentType("application/json");
postRequest.setEntity(StockJSON);
HttpResponse response = httpClient.execute(postRequest);
if (response.getStatusLine().getStatusCode() != 200) {
ValidationResults[0]="FAIL";
//throw new RuntimeException("Failed : HTTP error code : "+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
String output="", TempOutput="";
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
TempOutput=TempOutput+output;
}
System.out.println(output);
ValidationResults[1]="Could not post the message - Please check manually: "+TempOutput;
httpClient.getConnectionManager().shutdown();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ValidationResults;
}
}
package myTest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.*;
public class DataRead{
public static int RowSize,ColumSize;
public String[][]ReadEXCEL(int sheetNum) throws IOException{
String fileName = "ReferenceFiles\\DataSheet.xls";
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(sheetNum);
RowSize= (mySheet.getLastRowNum());
HSSFRow myRow = mySheet.getRow(0);
ColumSize=(myRow.getLastCellNum());
String ExcelData[][]=new String[RowSize][ColumSize];
try{
for(int i=1;i<=RowSize;i++){
myRow= mySheet.getRow(i);
for(int j=0;j<ColumSize;j++){
HSSFCell C2 = myRow.getCell(j);
if(C2 !=null)
ExcelData[i-1][j]=C2.toString();
else
ExcelData[i-1][j]="";
}
}
}catch(NullPointerException e){
e.printStackTrace();
}
myInput.close();
return ExcelData;
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
3) TestCollection.java
package myTest;
import java.io.IOException;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.json.JSONException;
public class TestCollection extends BaseTasking {
@BeforeMethod
public void SetUpTest(){
}
@Test(dataProvider="MyData",enabled=true)//Test-001
public void TC01_01(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@Test(dataProvider="MyData",enabled=true)//Test-002
public void TC01_02(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@Test(dataProvider="MyData",enabled=true)//Test-003
public void TC01_03(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@Test(dataProvider="MyData",enabled=true)//Test-004
public void TC01_04(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@AfterMethod
public void TearDown() {
System.out.println("************************************End of Test"+TCNUM+"************************************\n\n");
}
@AfterClass
public static void TearDownTest(){
System.out.println("Test Complete");
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
4) RestulValidator.java
package myTest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ResultValidator {
public String[] Validate(String testcaseNum, String ExpectedJson,String ActualJson,
String HeaderMessage, int ActualRespCode ) throws JSONException{
String Flag="Fail";
String ReportMessage="";
switch(testcaseNum){
case TC01_01:
{
/*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}
case 2:
{
/*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}
case 3:
{ /*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}
case 4:
{/*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}// End of Group-4
default:
{
System.out.println("invalid Test case Number");
}
}//End of Switch
Flags[0]=Flag;
Flags[1]=ReportMessage;
return Flags;
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
4) Testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="StockRegression" parallel="none">
<test name="Test">
<classes>
<class name="myTest.TestCollection"/>
</classes>
</test>
</suite>
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Run this 'Testng.xml' using the TestNG run command via command-line.
you'll get an html report once all the tests are run.
I would like to share my idea of automating RESTful API testing without using an automation tool.
This is quite interesting and challenging and has a very steep learning curve if took seriously, you can save thousands of Dollars to your organisations by developing your own Test-Automation framework for RESTful API testing.
The beautiful thing of this framework is, it is easy to maintain and can be integrated with all your continuous integration servers like Jenkins. The tests can be run on a nightly build and the TestNG report can be emailed to the concerned group of IDs.
There are many free API test libraries that would help you to automate your tests, but over a time the limitations stops your automation and you have to go for an alternative.
-----------------------------------------------------------------------------------------------------------
Things required to start:
1) Your favourite Java IDE, (I use Eclipse).
2) Apache Http Library (click here to download).
3) Apache Excel POI (click here to download).
4) TestNG (click here to download), please download 'Ant/Maven', version of TestNG not the eclipse version.
5) ANT ( click here to download), this is for build+run of your Java classes.
6) Gson (click here to download), to handle/manipulate JSON response.
People who are good with Junit can replace TestNG with it. But I prefer TestNG because of its features.
It generates a beautiful HTML report at the end which gives an detailed info of tests passes/failed and skipped.
Below are the different Java classes each performing a unique task in automation.
1) BaseTasking.java : This class does the following,
- Data supply.
- Test Control.
- API Url creation dynamically.
- REST API calling.
- Response reading and formatting.
- Http connection managing.
2) DataReader.java : This is class reads the input parameters from a spread sheet and passes it to the data provider in the 'BaseTasking.java' class.
3) TestCollection.java : This class has a collection of tests.
4) RestulValidator.java : This class contains the logic for validating the results from an API call.
5) Testng.xml : This xml file will have the collection of test classes that are to be executed.
6) Build.xml : This xml file is used to compile and run the test-suite using Ant.
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
1) BaseTasking.java
package myTest;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.util.Properties;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.testng.Reporter;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
public class BaseTestFactors {
static DefaultHttpClient httpClient;
BufferedReader br=null;
HttpResponse response=null;
String URL=null;
String AuthenticationKey=null;
String TCNUM=null;
String Environment=null;
String MethodName=null;
String Stores=null;
String Products=null;
String Parameters=null;
String ExpectedJson=null;
public static String Execute=null;
public static String TestDescription="No description available for this test case now.. will be added soon";
@BeforeClass
public static void SetUpSuite(){
}
// every @Test method will call this data provider, and based on the Test method name they'll get their data.
@DataProvider(name = "MyData")
public static Object[][] dataProvider(Method meth) throws IOException {
System.out.println("inside the dataprovider class");
Properties prop = new Properties();
InputStream input = null;
int SheetNumber=0, TestNumber=0;
DataRead E=new DataRead();
try {
input = new FileInputStream("ReferenceFiles/TestDescription.properties");
prop.load(input);
TestDescription=(prop.getProperty(meth.getName().toString().trim()));
input = new FileInputStream("ReferenceFiles/Environment.properties");
prop.load(input);
String TestGroup=(prop.getProperty((meth.getName().toString()).substring(0,4)).trim());
String TestNumberString=((meth.getName().toString()).substring(5,7)).trim();
System.out.println("TCNUM "+TestNumberString);
TestNumber=Integer.parseInt(TestNumberString);
System.out.println(TestNumber);
SheetNumber=Integer.parseInt(TestGroup);
} catch (IOException ex) {
ex.printStackTrace();
}
catch (NullPointerException e) {
System.out.println("caught an exception while reading properties file");
}
String[][] StrData=E.ReadEXCEL(SheetNumber);
int Row=Excelread.RowSize;
int Col=Excelread.ColumSize;
Object[][] TempData = new Object[Row][Col];
Object[][] data= new Object[1][Col];
for(int x=0;x<Row;x++){
for(int y=0;y<Col;y++){
TempData[x][y]=StrData[x][y];
}
}
data[0]= TempData[(TestNumber-1)];
return data;
}
public void ExecutionCheck(){
if(Execute.equalsIgnoreCase("N"))
throw new SkipException("Skipping - This Test case was aksed to be SKIPPED ");
}
@SuppressWarnings("deprecation")
public String[] MyTestGerneral() throws JSONException{
System.out.println("InsideTest-"+TCNUM);
Reporter.log(TCNUM+":- "+TestDescription);
String CompleteURL=null;
String ValidationResults[]= new String[2];
Properties prop = new Properties();
InputStream input = null;
try {// Setter for TestEnvironment IP/FQDN
input = new FileInputStream("ReferenceFiles/Environment.properties");
prop.load(input);
String PropRead[]=(prop.getProperty(Environment).split(","));
System.out.println("property read"+PropRead[0]+" "+PropRead[1]);
URL=PropRead[0].toString();
AuthenticationKey=PropRead[1].toString();
CompleteURL=getURL();
System.out.println(CompleteURL);
} catch (IOException ex) {
ex.printStackTrace();
}
try {// Make HTTP Call
org.apache.http.Header[] headers=null;
String headerMessage= null;
String JExpected= ExpectedJson;
String JActual="[{\"NoJSON\":\"No\"}]";
System.out.println("before http call");
HttpResponse Temp_response=RESTCall(CompleteURL);
System.out.println(Temp_response.toString());
if (Temp_response != null){
System.out.println("after http call");
br = new BufferedReader(new InputStreamReader(Temp_response.getEntity().getContent()));
int actualRespCode=Temp_response.getStatusLine().getStatusCode();
if(actualRespCode != 200){
try{
headers = Temp_response.getHeaders("CustomMessage");
headerMessage= headers[0].toString();
}
catch(ArrayIndexOutOfBoundsException e)
{
headerMessage="NO Error Message in the response";
}
}
if(actualRespCode == 200){
JActual =GETJSONRESULT(br);
}
ResultValidator ResVal= new ResultValidator();
System.out.println("before validation");
ValidationResults=ResVal.Validate(TCNUM,JExpected.toString(),JActual.toString(),headerMessage,actualRespCode);
httpClient.getConnectionManager().shutdown();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ValidationResults;
}// end of myTestGeneral method
/*Method to the get the URL*/
public String getURL(){
int option=0;
String CompleteURL=null;
if(MethodName.equalsIgnoreCase("SS1-V1")) option=1;
else if(MethodName.equalsIgnoreCase("SS2-V1")) option=2;
else if(MethodName.equalsIgnoreCase("SS3-V1")) option=3;
else if(MethodName.equalsIgnoreCase("SS4-V1")) option=4;
else if(MethodName.equalsIgnoreCase("SS5-V1")) option=5;
else if(MethodName.equalsIgnoreCase("SS6-V1")) option=6;
else if(MethodName.equalsIgnoreCase("SS7-V1")) option=7;
else if(MethodName.equalsIgnoreCase("SS8-V1")) option=8;
else if(MethodName.equalsIgnoreCase("SS1-V2")) option=9;
else if(MethodName.equalsIgnoreCase("SS2-V2")) option=10;
else if(MethodName.equalsIgnoreCase("CRACK")) option=11;
else if(MethodName.equalsIgnoreCase("ROOT")) option=12;
else if(MethodName.equalsIgnoreCase("ACURCY")) option=13;
else if(MethodName.equalsIgnoreCase("ADJOIN")) option=14;
switch(option){
case 1:
CompleteURL="http://"+URL+"/v1/Stock/method1/"+Stores+"?"+"productIds="+Products+"&"+Parameters;
break;
case 2:
CompleteURL="http://"+URL+"/v1/stock/"+"method2/"+Products+"?"+"locationids="+Stores+"&"+Parameters;
break;
case 3:
CompleteURL="http://"+URL+"/v1/stock/"+"method3/"+Stores+"?"+"productIds="+Products+"&"+Parameters;
break;
case 4:
CompleteURL="http://"+URL+"/v1/Stock/"+"method4/"+Stores+"?"+"productIds="+Products+"&"+Parameters;
break;
case 5:
CompleteURL="http://"+URL+"/v1/stock/"+"method5/"+Products+"?"+"locationids="+Stores+"&"+Parameters;
break;
case 6:
CompleteURL="http://"+URL+"/v1/method6/all/"+Products+"/"+Stores+"?business=Group";
break;
case 7:
CompleteURL="http://"+URL+"/v1/stockcr/method7/"+Stores+"?productId="+Products+"&business=Group";
break;
case 8:
CompleteURL="http://"+URL+"/v1/stockcr/method8/"+Products+"?locationId="+Stores+"&business=Group";
break;
case 9:
CompleteURL="http://"+URL+"/v2/stock/method9?productIds="+Products+"&locationIds="+Stores;
break;
case 10:
CompleteURL="http://"+URL+"/v2/stock/method10?productIds="+Products+"&locationIds="+Stores;
break;
case 11:
CompleteURL="http://"+URL+"/v2/stock/method11?productIds="+Products+"&locationIds="+Stores+"&business=Group";
break;
case 12:
CompleteURL="http://"+URL+"/v2/stock/method12/"+Stores+"productIds="+Products;
break;
case 13:
CompleteURL="http://"+URL+"/v2/stock/method13?productIds="+Products+"&locationIds="+Stores;
break;
case 14:
CompleteURL="http://"+URL+"/v1/stockcr/method14/"+Stores+"?business=Group";
break;
case 0:
CompleteURL=null;
break;
}
return CompleteURL;
}
/*Method to call the rest method*/
public HttpResponse RESTCall(String URLData) throws IOException{
HttpGet getRequest = new HttpGet(URLData);
getRequest.addHeader("accept", "application/json");
getRequest.addHeader("Authorization", AuthenticationKey);
httpClient = new DefaultHttpClient();
response = httpClient.execute(getRequest);
return response;
}
/*Method to return the JSON Array result*/
public String GETJSONRESULT(BufferedReader Buff) throws IOException, JSONException{
String output=null;
String JasonResponse="";
System.out.println("Output from Server .... \n");
while ((output = Buff.readLine()) != null) {
System.out.println(output);
JasonResponse=JasonResponse+output.toString();
}
System.out.println(JasonResponse);
//JSONArray temp1 = new JSONArray(JasonResponse);
return JasonResponse;
}
public String[] MyPOSTModule() throws JSONException{// Method for POSTing the JSON data.
System.out.println("InsideTest-"+TCNUM);
Reporter.log(TCNUM+":- "+TestDescription);
String CompleteURL=null;
String ValidationResults[]= new String[2];
ValidationResults[0]="PASS";ValidationResults[1]="Looks SUccessfull";
Properties prop = new Properties();
InputStream input = null;
try {// Setter for Environment Variable
input = new FileInputStream("ReferenceFiles/Environment.properties");
prop.load(input);
String PropRead[]=(prop.getProperty(Environment).split(","));
System.out.println("property read"+PropRead[0]+" "+PropRead[1]);
URL=PropRead[0].toString();
AuthenticationKey=PropRead[1].toString();
CompleteURL=getURL();
System.out.println(CompleteURL);
} catch (IOException ex) {
ex.printStackTrace();
}
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
FileInputStream inStrm = new FileInputStream("ReferenceFiles\\PostMethodJSON\\"+TCNUM+".txt");
byte[] fileData = new byte[input.available()];
inStrm.read(fileData);
inStrm.close();
String JSONData= new String(fileData, "UTF-8");
HttpPost postRequest = new HttpPost(CompleteURL);
postRequest.addHeader("Authorization", AuthenticationKey);
StringEntity StockJSON = new StringEntity(JSONData);
StockJSON.setContentType("application/json");
postRequest.setEntity(StockJSON);
HttpResponse response = httpClient.execute(postRequest);
if (response.getStatusLine().getStatusCode() != 200) {
ValidationResults[0]="FAIL";
//throw new RuntimeException("Failed : HTTP error code : "+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
String output="", TempOutput="";
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
TempOutput=TempOutput+output;
}
System.out.println(output);
ValidationResults[1]="Could not post the message - Please check manually: "+TempOutput;
httpClient.getConnectionManager().shutdown();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ValidationResults;
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
2) DataReader.java
-----------------------------------------------------------------------------------------------------------
2) DataReader.java
package myTest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.*;
public class DataRead{
public static int RowSize,ColumSize;
public String[][]ReadEXCEL(int sheetNum) throws IOException{
String fileName = "ReferenceFiles\\DataSheet.xls";
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(sheetNum);
RowSize= (mySheet.getLastRowNum());
HSSFRow myRow = mySheet.getRow(0);
ColumSize=(myRow.getLastCellNum());
String ExcelData[][]=new String[RowSize][ColumSize];
try{
for(int i=1;i<=RowSize;i++){
myRow= mySheet.getRow(i);
for(int j=0;j<ColumSize;j++){
HSSFCell C2 = myRow.getCell(j);
if(C2 !=null)
ExcelData[i-1][j]=C2.toString();
else
ExcelData[i-1][j]="";
}
}
}catch(NullPointerException e){
e.printStackTrace();
}
myInput.close();
return ExcelData;
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
3) TestCollection.java
package myTest;
import java.io.IOException;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.json.JSONException;
public class TestCollection extends BaseTasking {
@BeforeMethod
public void SetUpTest(){
}
@Test(dataProvider="MyData",enabled=true)//Test-001
public void TC01_01(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@Test(dataProvider="MyData",enabled=true)//Test-002
public void TC01_02(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@Test(dataProvider="MyData",enabled=true)//Test-003
public void TC01_03(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@Test(dataProvider="MyData",enabled=true)//Test-004
public void TC01_04(String TcNumber,String Environment,String MethodName,String Parameter1,
String Parameter1, String OtherParameters,String Execute) throws JSONException, IOException{
super.TCNUM= TcNumber;super.Environment=Environment.trim();super.MethodName=MethodName.trim();super.Parameter1=parameter1.trim();super.Parameter2=Parameter2.trim();super.OtherParameters=OtherParameters.trim();super.Execute=Execute;
ExecutionCheck();
String Status[]=CallHttpMethod();
AssertJUnit.assertTrue(Status[1],Status[0].equalsIgnoreCase("PASS"));
}
@AfterMethod
public void TearDown() {
System.out.println("************************************End of Test"+TCNUM+"************************************\n\n");
}
@AfterClass
public static void TearDownTest(){
System.out.println("Test Complete");
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
4) RestulValidator.java
package myTest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ResultValidator {
public String[] Validate(String testcaseNum, String ExpectedJson,String ActualJson,
String HeaderMessage, int ActualRespCode ) throws JSONException{
String Flag="Fail";
String ReportMessage="";
switch(testcaseNum){
case TC01_01:
{
/*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}
case 2:
{
/*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}
case 3:
{ /*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}
case 4:
{/*
Logic for validating your Actual results against the expected results.
use GSON to extract JSON value and use it to compare against the expected values.
use flags and indicators to set the validation status to 'Pass' or 'Fail'
do not use assertions, instead use if-else to compare the results.
finally return a 1D string array with
Str[0] having the value 'Pass'/'Fail'--> Flag
Str[1] having the error message detailing why the validation failed--> ReportMessage
*/
break;
}// End of Group-4
default:
{
System.out.println("invalid Test case Number");
}
}//End of Switch
Flags[0]=Flag;
Flags[1]=ReportMessage;
return Flags;
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
4) Testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="StockRegression" parallel="none">
<test name="Test">
<classes>
<class name="myTest.TestCollection"/>
</classes>
</test>
</suite>
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Run this 'Testng.xml' using the TestNG run command via command-line.
you'll get an html report once all the tests are run.
Hi Karthik, thanks for the post.. Can you please provide instructions or sample project with all the above mentione items? I have download gson, apache excel etc components which you have listed. need some inputs on how to collage all these into Eclipse Testng project
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi Karthic! do you have any doc/faqs or steps to implement these, can you please share the code with some example at p.ashokbabu@gmail.com
DeleteHi Shiva, thanks for visiting my blog,
ReplyDeleteif you are very new to REST api automation, then I would suggest you to start with hard-coding strategy instead of trying immediately to implement this data-driven framework whole.
I'll email you some basic code related to this, share me your email address.
Thanks Karthic. I have used selenium+data driven framework in the past. I am looking for Test NG + selenium+Data driven framework for Json file handling. Please send the sample project with all the required details avadhshiva@gmail.com
DeleteThanks in adv
Shiva
Thanks Karthic. I have used selenium+data driven framework in the past. I am looking for Test NG + selenium+Data driven framework for Json file handling. Please send the sample project with all the required details avadhshiva@gmail.com
DeleteThanks in adv
Shiva
I've shared you the basics, start-off with that, rest is simple to re-use the code here.
DeleteHi Karthic kaliappa
Deletei had gone through this blog it is very nice ...
and i am also very much interested to learn new technologies like you
please provide me simple way to learn this API testing from the scratch..
Hope will get Email on meetkajanachari@gmail.com
Advance in thanks
Chari.
could you please share me the source code: mail theduyet (a) gmail.com
DeleteHi Karthic,
DeletePlease send me basic code. email id : sam4luv09@gmail.com
Hi Karthic,
DeletePlease send the simple project to rajibsaha28sept@gmail.com
Hi Karthic,
DeletePlease send me basic code. email id :shalakhasardana18@gmail.com
Can you please mail me the basic code related to this ? I too want to design automation framework to test REST APIs
ReplyDeletemailed : vishvas.trikutkar@gmail.com
Deletedone..
DeleteHi Karthic,
Deleteit is a very useful information.
can you please share with me as the basic code @ mamatha.tr@gmail.com.
it would be of great help.
Regards
Hi Karthik, Thanks a ton for publishing this . I am trying my hands of on restful api automation using this approach. Would you be kind enough to share a sample excel ? I am not able to visualize how to organise the tests in excel.
ReplyDeleteLooking forward to your response !!
my email address is himanshu5jan@gmail.com
Hi Himanshu, the excel is simple, each api method is assigned to a sheet in excel work book, every row is a test case, each row has a unique TC_NUM identifier same as the @Test methods, the @Dataprovider uses this identifier to send the data[][] (row) to the calling Test method.
Deleteif you look at the updated above code you would get that.
I've sent you the details...
DeleteCan you please share sample basic code to coolkishor81@gmail.com
ReplyDeleteDone..
DeleteHi Kirthic,
DeleteCould you send me the basic code to nsaypur@gmail.com
Thanks
Simha
Hey thanks for sharing such a useful information. I am also new to API automation and will have to implement this in my project.Was going through differnt blogs and found this.Can you please share the code at aastha.g02@gmail.com
ReplyDeleteI would need basic code to start off
DeleteI've sent you..
DeleteHey could pls let me know the dependency format to download through Maven for GSON jar?
Deletehttp://mvnrepository.com/artifact/com.google.code.gson/gson/2.6.2
Deleteget the dependency details from here.
Hi Karthic,
DeleteFirst of all hearful thanks for sharing such deep information..
I am a beginner in automation, so far could achieve testing, RESTful APIs using Groovy in Soap UI.
I need to test RESTful APIs using Java in Eclipse, the input data i have is:
http://192.xxx.xxx.xxx:9080/xxx/xxx
Headers:
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Payload:
{"xxxx":{ "xx": "x", "xxxx": "xxx" },"xxxx":{ "xxxx":xxxx }}\
Method:
PUT
Kindly help me out with setting up eclipse, and with a basic code to PUT the above payload as a string.
Kindly let me know if any other information required...
My mail ID : udaykrishna.cj@gmail.com
Hi Uday, I've sent you the details, you can use that.
DeleteHi karthic, i need basic code for get API and response i m expecting list of item combination of number and charactee like abcd1234. sinha.kanak@gmail.com
ReplyDeletedone..
DeleteThanks
DeleteHi karthic, Can you please share sample basic code for GET & POST methods.
ReplyDeleteMy eMail id : dheeraj.gummada@gmail.com
done... sent
DeleteThis comment has been removed by the author.
DeleteHi karthic, Can you please share sample basic code for GET & POST methods.
ReplyDeleteMy eMail id :forsiddhartha@gmail.com
done.. sent
ReplyDeleteHi Karthic,
ReplyDeleteExcellent Article.
Could you please share the code workspace to my mail id too? It would be really helpful.
Its automationraymond@gmail.com. Thanks in advance.
Hi Karthic,
ReplyDeleteNice Article, Could you please share the code work space by mail. gopimadan@gmail.com
Could you please provide the sample project, As I am working on the similar line.
DeleteHi Karthi ,
ReplyDeleteCan you share above sample workspace by mail thiru.m@gmail.com . Thanks in advance .
Hi Karthic,
ReplyDeleteCan you please share sample basic code to manju6080@gmail.com.
sent...
DeleteHi Karthic,
ReplyDeletecan you please share me sample code to deepa.reddy.1887@gmail.com
Hi Karthic,
ReplyDeleteAfter doing all of the "Things required to start", I am still getting error "The import frameWorks cannot be resolved" for the line
import frameWorks.Excelread;
in BaseTasking.java. Can you tell me more about how to get that library?
Benjamin
Benjamin, please remove that import statement, .. that's actually pointing to the DataReader class in the earlier version of my post.
Deleteremoving that statement should work for you..
thanks for pointing that out..!!
Hi Karthic,
DeleteI removed the import, but later there are lines of code trying to use it.
Excelread E=new Excelread();
int Row=Excelread.RowSize;
int Col=Excelread.ColumSize;
Also the following line is producing a compilation error, "The method Validate(String, String, String, int) in the type ResultValidator is not applicable for the arguments (String, String, String, String, int)".
ValidationResults=ResVal.Validate(TCNUM,JExpected.toString(),JActual.toString(),headerMessage,actualRespCode);
Thank you for your help,
Benjamin
thanks again, I've updated it... there were ClassName miss-match, this content is chopped and customized, as I should not share my workspace as it is..
DeleteBut I'm working on building these with open-APIs so that I can share the entire project without any modification.
Hi Karthik,
DeleteI hope your open-APIs should be ready by now.I would appreciate if you could share me on my email.
hs18.manish@gmail.com
Thanks
Manish
Hi Karthic,
ReplyDeletePlease can you share the sample code to atanu.ghosh1@gmail.com
Thanks.
sent..
DeleteHi Karthic,
ReplyDeleteThanks a lot for posting, could you please share the basic code to the email id anil04503@gmail.com
sent..
DeleteHi Karthik,
ReplyDeleteCan u please share the code to Rohith.vasudevan07@gmail.com
sent..
DeleteHi Karthic..Can u share basic code for rest API testing at sachinbilsi@gmail.com
ReplyDeleteThx in advance..
sent..
DeleteHi Karthic,
ReplyDeleteNice article, Thank you for sharing knowledge!
Can you please share sample code on Email ID : prabhune.prashant@gmail.com
sent..
Deletehi karthic, thanks for the nice article. Please share the sample code with me too on nagasekharm@gmail.com
ReplyDeletesent..
DeleteHi Karthik, Nice article, Please share the sample code with configuration details to me on Venkatesh.ramasamy2@gmail.com
ReplyDeletedone..
DeleteHey thanks for sharing such a useful information. I am also new to API automation and will have to implement this in my project.Was going through differnt blogs and found this.Can you please share the code at kapoorvishal23@gmail.com
ReplyDeletedone..
DeleteHi Karthik
ReplyDeleteI want to with API Automation, can you please share some sample code for GET,POST and PUT methods.
I will be waiting for your response.
your email ID pls
DeleteHi Karthi, It is an excellent post....Could you please share the above code with working result validator class to this email kalyan.jew45@gmail.com...THANKS.
ReplyDeletesent ...
DeleteHi Karthi,
ReplyDeleteReally nice post, can you please share the GET and POST methods code to neelsethi09@gmail.com
sent..
DeleteHi Karthic,
ReplyDeleteThanks a lot for publishing such a useful information.
I'm UI Automation Engineer and I use TestNG, Eclipse and Selenium WebDriver with Java. However I'm new in REST API Automation testing.
Can you please share the basics code to kubanych.mak@gmail.com
Thanks,
Kubanych
thanks.. I've sent you.
DeleteHi Karthic,
ReplyDeleteIt is a very excellent post. Could you please send me the sample code with configuration details to juanlhuang@gmail.com
Thank you very much!
Juan
Hi Karthic, Can you please share sample basic code to srini3463@gmail.com
ReplyDeleteThanks in advance!
hi karthick., how to validate two json response in api testing., nd tht json file content is not in the same order.
ReplyDelete& also can you share basic api testing code to gayathri_2591@yahoo.com
Hi Gayathri, there are multiple ways to compare two JSONs, but I have my self-experimented method, as below,
DeleteAny direct comparison of JSONs may not be worth, so I convert JSONs into MAPs and write a simple method to compare them,
public boolean compareMap(Map map1, Map map2) {
if (map1 == null || map2 == null)
return false;
for (String ch1 : map1.keySet()) {
if (!map1.get(ch1).equalsIgnoreCase(map2.get(ch1)))
return false;
}
return true;
}
in this way we can avoid comparing all the values in JSON (we can avoid dynamic timestamps). Also this approach depends on the Json size as well. Best suggestion is to write a simple frame work to covert JSONs into a dataStructures (no big deal) and use that directly to compare.
There is another way to do that using GSON, if none of your attribute has a dynamic value, as I was stating .. most Json reponses deal with 'currentTime' attribute.
DeleteJsonParser parser = new JsonParser();
JsonElement o1 = parser.parse("{\"name\":\"karthic\",\"Place\":\"Bangalore\"}");
JsonElement o2 = parser.parse("{\"name\":\"karthic\",\"Place\":\"Bangalore\"}");
System.out.println(o1.equals(o2));
Hi Karthic,
ReplyDeleteThanks a lot for publishing such a useful information. I'm new in REST API Automation testing
Can you please share sample basic code to vanithabp@gmail.com
Hi Karthic,
ReplyDeleteThanks a lot for publishing such a useful information. I'm new in REST API Automation testing
Can you please share sample basic code to vanithabp@gmail.com
Hi Kartthic,
ReplyDeleteI have done web application testing using data driven using page object model. Iam trying to get hands on with API testing and the above post is really good approach.
Could you please send me all the code , files including excel files that I need to set up a project in Eclipse.
My email id : raghuval45@gmail.com
Thanks.
Hi Karthic, I am planning to implement API automation. Could you please send me the sample code to prabhu.qtp@gmail.com.
ReplyDeleteThanks
Prabhu
Hi karthic, Can you please share sample basic code for GET & POST methods.
ReplyDeleteI am all new to this. I have list of API's which I want to automate. Please help me regarding this
My eMail id : saket1991@gmail.com
hi Karthic,
ReplyDeleteThanks for your post, it very helpful to understand. I am new in Rest API testing. I want to run the code and but I don't know the Data which you used in excel and .properties file.
Could you please share that so that i can try to run the code.
My mail id is : ankit.g0304@gmail.com
done..
DeleteHi Karthic,
ReplyDeleteThanks for your post, I am new to REST API testing. Can you please share me the basic code to get the response from REST APIs and to fetch values from request and response json Files.
Thanks in advance.
eMailID :- anudeepkota5@gmail.com
sent..
DeleteHi Karthic,
ReplyDeleteI am looking for some basic automation steps used for REST API Automation. Actually I need a step by step process of automating a Rest API & also SOAP Request which uses XML
could you please send me the basic code which will be helpful for me to Automate REST as well as SOAP requests, First I will start with basics Then I will go for Advance level using parameterization. Appreciate your help.
My Email Id is deogharkar@gmail.com
Thanks,
Devendra
Hi Karthic,
ReplyDeleteI am new to REST API Automation.Could you please send me the basic java code using which i can start practising??Thanks in advance for the help.
EmailId : ragothamkoppal@gmail.com
Regards,
Raghotham
done..
DeleteHI Karthick,
ReplyDeleteVery nice article.Can you please share the code base of the above project to the email iD:
venki.reddy143@gmail.com
This will be very helpful for me.
Hi Karthick,
ReplyDeleteWhen I try to Compile I am getting error(Multiple markers at this line
- Excelread cannot be resolved to a
variable) in
int Row=Excelread.RowSize;
int Col=Excelread.ColumSize;
Replace the 'Excelread' with the class name 'DataReader'..
DeleteThe code given in the blog is just my original idea but not the complete code (I'm not suppose to share my code base), may contain some minor name issue, kindly try to solve logically..
Hi Karthik
ReplyDeleteBalraj here. Can you share the sample code structure or sample project with the above items integrated.
email: jy.balraj5@gmail.com
Hi Karthik
ReplyDeleteBalraj here. Can you share the sample code structure or sample project with the above items integrated.
email: jy.balraj5@gmail.com
Hi Karthic
ReplyDeleteI am new to REST API Automation.Could you please send me the basic java code using which i can start practising??Could you tell me the prerequisites for developing above framework
Thanks in advance for the help
email id:mahekmerchant@gmail.com
Can you pls share the code to kadur.vijay@gmail.com as soon as possible.
ReplyDeleteHey Karthik,
ReplyDeletegreat work, can u pls share this cool and useful framework: vitalik-5k@yandex.ru
This comment has been removed by the author.
ReplyDeletehi Karthic,
ReplyDeleteThanks for your post. I am new in Rest API testing. I want to run the code and but I don't know the Data which you used in excel and .properties file.
Could you please share your complete framework that so that i can try to run the code.
My mail id is :jit6726@gmail.com
Hi Karthic, Could you send me the basic code as well to maryjanebarger@gmail.com
ReplyDeleteThanks!
Hi Karthic, Could you send me the basic code as well to maryjanebarger@gmail.com
ReplyDeleteThanks!
Hi Karthik, Please share the basic code of this automation application. MailID:naresh.e2001@gmail.com
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi Kartik,
ReplyDeleteNice article. Can you please share source code with test data which you are using..
My id is rsingh.iise@gmail.com
Thanks
Hi Karthic,
ReplyDeleteCan you please share the sample source code as i want to implement the same for many API's
My id: nitin.kukna@gmail.com
Regards,
Nitin
Hello Karthick,
ReplyDeleteCan you please share the sample code to my mail id, if you are okay to do so. Email id : nmmani37@gmail.com
Hi Karthick,
ReplyDeleteCould you please share the sample project along with excel sheet to my email id.
email id is :hs18.manish@gmail.com
Hello Karthick,
ReplyDeleteCould you share the data excel sheet to me (Subash_uc@yahoo.co.in)
Thanks , Your blog is really great help to me.
Thanks Karthick for great blog.
ReplyDeletePlease share sample code and data excel sheet. (mail2ngarg@gmail.com)
Can you pelase send the source code along with the excel data sheet to my email: viswanadhy@gmail.com
ReplyDeleteIt would be helpful if you could place your source code in github.
Hi Karthick,
ReplyDeleteCan you please share abouve project to medida.ravi1987@gmail.com
Thanks
Ravi
This comment has been removed by the author.
ReplyDeleteHi Karthic kaliappa
ReplyDeleteCan you please provide me simple way to learn this API testing from the scratch..
Can you please send it on aamenabhurawala@yahoo.co.in
Thanks in advance.
Cheers!
Hi Karthik,
ReplyDeleteVery informative article.Karthick,
Can you please share abouve project to sastry.dvsr@gmail.com
Thanks
sreeram.
Hi Karthick,
ReplyDeleteCan you please send it to nawasabdulsalam@yahoo.com
Thanks
Nawaz
Hi Karthick,
ReplyDeleteI want to automate put, get and post calls using java , can you please send sample code ..
Thanks
Srini J
Hi Karthick,
ReplyDeleteCan you please send me complete project of this one if you have already , I need to do same kind implementation in my project and that would be great help ? and one more about "Apache Http Library" is kind library file we need to put in "JRE Library" file system for project configuration?
Thanks
Srinivas
My Email id srinivasg.jooluri@gmail.com
DeleteHi Karthik
ReplyDeleteExcellent blog on API testing, Could you please share the code to get started with the API Automation. Also, if you have posted the prj in the public git please share the address i will download it from there. my email id is : mcgurkar@gmail.com
thanks
Mahesh
Hi Karthik,
ReplyDeleteCan you share the code on alexxm360@gmail.com
Hi Karthik
ReplyDeleteI am new to API automation
I have to test few get & post methods
Can u please share sample framework design/code so that i can satrt with it.
I have few headers & tokens to be passed in request.
Thanks in Advance
Akbar
Email:arushabt@gmail.com
hi Karthic,
ReplyDeleteThanks for your post, it very helpful to understand. I am new in Rest API testing. I want to run the code and but I don't know the Data which you used in excel and .properties file.
Could you please share that so that i can try to run the code.
My mail id is : sanjuaddy1@gmail.com
Hi Karthic,
ReplyDeleteThanks for the code and explanation. However I am running into deprecated code and compile issues while I build the code. Perhaps if you could share me the latest code to ashleygeorge4u@gmail.com, it would be of great help.
Thanks, Ashley
Hi Karthick,
ReplyDeleteVery good post. Thanks. I am new to API automation. Pls share the Excel sheet and sample code.
Thanks.
Regards,
Sivan
Hi Karthick,
ReplyDeleteVery good post. Thanks. I am new to API automation. Pls share the Excel sheet and sample code.
Thanks.
Regards,
Sivan
My email: sivanarumugam.mookiah@gmail.com
ReplyDeleteHi Karthic,
ReplyDeleteYour post is good to understand for Beginner.
Can you please mail me the source code with property file and excel sheet i.e actual running code.
Email: t.gutgutia@gmail.com
Thanks in Advance
Hi Karthic,
ReplyDeleteThanks for the code and explanation. However I am running into deprecated code and compile issues while I build the code. Perhaps if you could share me the latest code to sandeep.008d@gmail.com, it would be of great help. Thanks!
This comment has been removed by the author.
ReplyDeleteHI Karthic,
ReplyDeleteYour post is quite descriptive, but as a beginner can you please mail me the source code with property file and excel sheet. I would better like to go for hard-coding strategy instead of trying immediately, do you have any basic examples regarding this.. Thanks in advance.
hi send me basic code karthik8292@gmail.com
ReplyDeletesent..
DeleteHi Karthic, I m very new to api automation using java, can you please tell me which rest client i need to work, i checked many such as rest-assured, can you send me some basic code where can i start with, currently i m using intellij as Ide, added rest assured, json, testng dependencies.
ReplyDeleteRegards
Soumya
The choice is yours, either you can code using http clients(Apache-http) like I did here.
DeleteElse you can use libraries(RestAssured) created for testing REST apis.
you can visit my blog on RestAssured,
http://automationextra.blogspot.in/2016/03/rest-api-testing-using-restassured.html
I've shared basics of RestAssured.
Hi Karthic
ReplyDeleteCan you please share sample framework structure to me (amargvn@gmail.com)
Is this info helps me in API testing
ReplyDeleteHi Karthic,
ReplyDeleteHelpful Blog!!!
can you please share me the source code with property file and excel sheet. It would be a great help.
email: aruman.khadka@gmail.com
Thanks
Manoj
I'll send the Excel and property files..
DeleteCan you please clarify me that how i can use this code for doing API testing automation?
ReplyDeleteThis will be a cloud based API testing tool, using tools will avoid you coding so deep as the tools take care of most things at back-end. You'll get lots of drag-and-drop kind of options to perform most validations on the response.
DeleteHi Karthik,
ReplyDeleteIts a very usefull information, can i suggest you to create git repository with pom.xml and share across.
Or please anyone email me the code at balu.api.testing@gmail.com.
i will share it on github so that other users can fork into their own git repo.
thank you
hi karthik,
ReplyDeletecould you please email pom.xml for the dependencies of this framework.. or email me to
balu.api.testing@gmail.com.
thank you
Hi Karthik, Can u share basic code for rest API testing at nedeli_nk@hotmail.com
ReplyDeleteHi Karthic,
ReplyDeleteNice Blog!!
can you please share me the source code with property file and excel sheet. It would be a great help.
email: sanjuaddy1@gmail.com
Thanks
Sanjay
Hi Karthik,
ReplyDeleteI like your blog and the details you have here
I am looking to build a framework for API testing but I am not sure where to start.
While building this kind of project which are the classes you build first and which ones after that.can you please send me some assignements that I will work so that it will give me some ideas also if you could send me the source code for this project also
My email address is goutam.dalai@gmail.com
Hi Karthik,
ReplyDeleteVery useful information !!
can you please share me the entire project with source code, property file and excel sheet. It would be a great help.
email: writetoabhijoshi@gmail.com
Thanks
Abhijit
Thanks Karthic!!exactly landed at right place at right time. I am working on automating data driven api testing using java +Testng+restassured but struck with implemenation of data driving through excel. Can you please share above source code along with excel sheets which would really help me in developing automation framework.
ReplyDeleteHere is my mail ID : naveenreddy.banks@gmail.com
Hi Karthic,
ReplyDeleteVery informative post. Can you please share with me the entire project with source code, property file and excel sheet? That would be great. My email is
marksanders1414@gmail.com
Thank you,
Mark
Hi karthik,
ReplyDeleteCan you please send source code to my mail id.
nagachaitanya.443@gmail.com
Thanks
Hi Karthik,
ReplyDeleteVery useful information !!!
can you please share me the entire project with source code, property file and excel sheet. It would be a great help.
email: mcsolutions.ae@gmail.com
Hi Karthik Thanks a lot for publishing such a useful information.
ReplyDeleteI want to with API Automation, can you please share some sample code for GET,POST and PUT methods.
I will be waiting for your response. My email adress - vtvonline2017@gmail.com
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
Deletecan you send me the basic code to chethan.annem@gmail.com
DeleteHI Karthik, can you please send a working copy (zip) of API automation? my email id is: praveen.motati@gmail.com
ReplyDelete