SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
Steps for Configuring RestAssured
1. Create a maven project in Eclipse.
Please find the sample project structure below:
2. Add the following dependencies in pom.xml and update the project.
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
© RapidValue Solutions 2
Data Seeding via Parameterized API Requests
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
</dependency>
3. Create a new package and a new class.
In src/test/java, create a package ‘com.rvs.httpmethods’ and a java file
‘RequestParameterization.java’
4. Add TestNG library to the project.
Right click on Project -> Build Path -> Add Libraries -> TestNG
5. Start coding.
Data-driven Testing
For data-driven testing, the test values are read directly from the data files rather than using hard
coded values. The data files can be csv files, excel files, text files, etc. A test containing several
sets of hard coded values can be difficult to modify and maintain. It’s alway easier and a best
practice to extend values in the data file than to modify the actual test scripts. Various inputs or
data modifications can be handled easily without even touching the actual test script.
© RapidValue Solutions 3
Data Seeding via Parameterized API Requests
Data-driven test performs following operation in a loop:
- Retrieving input data from storage.
- Parameterizing the required data in the Api request body.
- Sending the request and verifying the response received.
In the example of parameterizing the request body, you have to create an excel sheet with the test
details. This data set basically contains the number and the employee name, which you have to
parameterize in the request.
Test data example is given below, which should be created at
"/src/test/resources/Employees.xlsx”: Sheet name should be “Employees”.
The following is the method that uses Apache POI library functions to fetch test data from the
excel sheet and it will return the data as object.
© RapidValue Solutions 4
Data Seeding via Parameterized API Requests
TestNG Data Providers
REST Assured can be combined with TestNG, and it provides an easy mechanism to create data-
driven tests through the DataProvider.
public Object[][] getDataFromSheet(String TESTDATA_SHEET_PATH, String sheetName) {
FileInputStream file = null;
try {
file = new FileInputStream(TESTDATA_SHEET_PATH);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
book = WorkbookFactory.create(file);
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sheet = book.getSheet(sheetName);
Object[][] data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];
for (int i = 0; i < sheet.getLastRowNum(); i++) {
for (int k = 0; k < sheet.getRow(0).getLastCellNum(); k++) {
data[i][k] = sheet.getRow(i + 1).getCell(k).toString();
}
}
return data;
}
© RapidValue Solutions 5
Data Seeding via Parameterized API Requests
A Data Provider is a method annotated with @DataProvider. A Data Provider returns an
array of objects. It helps you to write data-driven tests which essentially means that same test
method can be run multiple times with different data-sets.
Parameterization allows you to pick different values at run time. It reduces time and effort.
Here, the TestData() method is annotated with @DataProvider annotation and the same is used in
@Test configuration. DataProvider method will return an object array and its dimension must
match the test method. Since your test method has two arguments, the DataProvider method must
return object[][] so that it can be mapped to the arguments in the method.
Here, you need to make sure that the array returned by the DataProvider should match the test
method parameters.
JSON File Creation
A JSON file is a file that stores simple data structures and objects in JavaScript Object Notation
(JSON) format.
In order to create a JSON file in the project, right click on “src/test/resources” and click on
New> Other. On selecting Other option, you will get several options. From these options,
select General > File option, and then click Next. You can create a JSON file by giving the
name “AddEmployee” and ".json" extension and click on finish button. You need to add the
request body in the created JSON file.
@DataProvider
public Object[][] TestData() throws Exception {
String dir = System.getProperty("user.dir");
Object[][] testObjArray = DataProviderUtils.getDataFromSheet(dir +
"//src//test//resources//Employees.xlsx", "Employees");
return (testObjArray);
}
© RapidValue Solutions 6
Data Seeding via Parameterized API Requests
Here, the name inside the curly braces {} will be replaced with the values fetched from the excel
sheet.
Create Multiple Employees
The below method will send the post request with the parameters provided and it will return the
response.
{
"name": "${name}",
"salary": "100100",
"age": "25"
}
public Response postRequest(String URI, String resource, String payloadFolderPath, String
EmpName) throws IOException {
String payloadPath = payloadFolderPath;
String payload = new String(Files.readAllBytes(Paths.get(payloadPath)));
System.out.println(EmpName);
payload = payload.replace("${name}", EmpName);
System.out.println("Payload is" + "n" + payload);
Response resp = RestAssured.given().baseUri(URI)
.body(payload)
.contentType("application/json")
.log().all()
.when()
.post(resource).andReturn();
return resp;
}
AddEmployee.json
© RapidValue Solutions 7
Data Seeding via Parameterized API Requests
The following method will create multiple employees.
@Test(dataProvider="TestData")
public void createMultipleEmployees(String EmpID, String EmpName) throws IOException {
String baseURI = “http: //dummy.restapiexample.com”;
String resource = “/api/v1/ create”;
String dir = System.getProperty("user.dir");
String payloadPath = dir + "//src//test//resources//AddEmployee.json”;
resp = postRequest(baseURI, resource, payloadPath, EmpName);
JSONObject jObj = new JSONObject(resp.getBody().asString());
String emp_id = jObj.getString("id");
String emp_name = jObj.getString("name");
empName.add(emp_name);
empID.add(emp_id);
System.out.println("Created Employee Datails");
empData = new String[empID.size()][2];
}
for (int i = 0; i < empID.size(); i++) {
empData[i][0] = empID.get(i);
empData[i][1] = empName.get(i);
System.out.println(empData[i][0] + " - " + empData[i][1]);
}
© RapidValue Solutions 8
Data Seeding via Parameterized API Requests
Test Execution Output
Conclusion
Parameterization is very important for automation testing. It helps you to iterate on input data
with multiple data sets that make your scripts reusable and maintainable. In few scenarios, you
can still manage with hard coded request but the same approach will not work out where sheer
count of combinations is to be validated. By implementing the right solution, you can keep your
code base and test data size at ideal range and still savor the benefits of optimal coverage.
Hope this blog helped you to understand the concept of parameterization and the actual
implementation in a better way.
Happy Learning!
By,
Mary Geethu, C. A.
Senior Software Engineer
© RapidValue Solutions 9
Data Seeding via Parameterized API Requests
About RapidValue
RapidValue is a global leader in digital product engineering solutions including mobility, omni-channel,
IoT, AI, RPA and cloud to enterprises worldwide. RapidValue offers its digital services to the world’s top
brands, Fortune 1000 companies and innovative emerging start-ups. With offices in the United States, the
United Kingdom, Germany and India and operations spread across the Middle-East, Europe and Canada,
RapidValue delivers enterprise services and solutions across various industry verticals.
Disclaimer:
This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part of it may be used,
circulated, quoted, or reproduced for distribution outside RapidValue. If you are not the intended recipient of this report, you are
hereby notified that the use, circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful.
© RapidValue Solutions
www.rapidvaluesolutions.com/blogwww.rapidvaluesolutions.com
+1 877.643.1850 contactus@rapidvaluesolutions.com
© RapidValue Solutions 10

Weitere ähnliche Inhalte

Was ist angesagt?

Oracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityOracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityrohit vishwakarma
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentalsMadhuri Kavade
 
6.2\9 SSIS 2008R2_Training - DataFlow Transformations
6.2\9 SSIS 2008R2_Training - DataFlow Transformations6.2\9 SSIS 2008R2_Training - DataFlow Transformations
6.2\9 SSIS 2008R2_Training - DataFlow TransformationsPramod Singla
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationRandy Connolly
 
Change tracking
Change trackingChange tracking
Change trackingSonny56
 
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...IndicThreads
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Data Binding and Data Grid View Classes
Data Binding and Data Grid View ClassesData Binding and Data Grid View Classes
Data Binding and Data Grid View ClassesArvind Krishnaa
 
Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETFernando G. Guerrero
 
6.1\9 SSIS 2008R2_Training - DataFlow Transformations
6.1\9 SSIS 2008R2_Training - DataFlow Transformations6.1\9 SSIS 2008R2_Training - DataFlow Transformations
6.1\9 SSIS 2008R2_Training - DataFlow TransformationsPramod Singla
 
Hibernate Query Language
Hibernate Query LanguageHibernate Query Language
Hibernate Query LanguageInnovationM
 

Was ist angesagt? (19)

ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
Oracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityOracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivity
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
6.2\9 SSIS 2008R2_Training - DataFlow Transformations
6.2\9 SSIS 2008R2_Training - DataFlow Transformations6.2\9 SSIS 2008R2_Training - DataFlow Transformations
6.2\9 SSIS 2008R2_Training - DataFlow Transformations
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
exa_cer_g23
exa_cer_g23exa_cer_g23
exa_cer_g23
 
Hibernate
HibernateHibernate
Hibernate
 
Change tracking
Change trackingChange tracking
Change tracking
 
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...
 
Ado.net
Ado.netAdo.net
Ado.net
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Data Binding and Data Grid View Classes
Data Binding and Data Grid View ClassesData Binding and Data Grid View Classes
Data Binding and Data Grid View Classes
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NET
 
Grid View Control CS
Grid View Control CSGrid View Control CS
Grid View Control CS
 
6.1\9 SSIS 2008R2_Training - DataFlow Transformations
6.1\9 SSIS 2008R2_Training - DataFlow Transformations6.1\9 SSIS 2008R2_Training - DataFlow Transformations
6.1\9 SSIS 2008R2_Training - DataFlow Transformations
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
Hibernate Query Language
Hibernate Query LanguageHibernate Query Language
Hibernate Query Language
 

Ähnlich wie Data Seeding via Parameterized API Requests

SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015Pushkar Chivate
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaJignesh Aakoliya
 
Prediction io 架構與整合 -DataCon.TW-2017
Prediction io 架構與整合 -DataCon.TW-2017Prediction io 架構與整合 -DataCon.TW-2017
Prediction io 架構與整合 -DataCon.TW-2017William Lee
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedureftz 420
 
Guide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinGuide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinRapidValue
 
DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)Data Finder
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog SampleSkills Matter
 
Streamlining data analysis through environmental alerts how to integrate ambe...
Streamlining data analysis through environmental alerts how to integrate ambe...Streamlining data analysis through environmental alerts how to integrate ambe...
Streamlining data analysis through environmental alerts how to integrate ambe...Ambee
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
Using Page Objects
Using Page ObjectsUsing Page Objects
Using Page ObjectsGetch88
 
Agile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science MeetupAgile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science MeetupRussell Jurney
 

Ähnlich wie Data Seeding via Parameterized API Requests (20)

Data access
Data accessData access
Data access
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
 
Agile Data Science
Agile Data ScienceAgile Data Science
Agile Data Science
 
Practical OData
Practical ODataPractical OData
Practical OData
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
 
Prediction io 架構與整合 -DataCon.TW-2017
Prediction io 架構與整合 -DataCon.TW-2017Prediction io 架構與整合 -DataCon.TW-2017
Prediction io 架構與整合 -DataCon.TW-2017
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
Guide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinGuide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in Kotlin
 
DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
 
Streamlining data analysis through environmental alerts how to integrate ambe...
Streamlining data analysis through environmental alerts how to integrate ambe...Streamlining data analysis through environmental alerts how to integrate ambe...
Streamlining data analysis through environmental alerts how to integrate ambe...
 
Data Science on Google Cloud Platform
Data Science on Google Cloud PlatformData Science on Google Cloud Platform
Data Science on Google Cloud Platform
 
Node.js and Parse
Node.js and ParseNode.js and Parse
Node.js and Parse
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
Using Page Objects
Using Page ObjectsUsing Page Objects
Using Page Objects
 
Agile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science MeetupAgile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science Meetup
 

Mehr von RapidValue

How to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-SpaHow to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-SpaRapidValue
 
Play with Jenkins Pipeline
Play with Jenkins PipelinePlay with Jenkins Pipeline
Play with Jenkins PipelineRapidValue
 
Accessibility Testing using Axe
Accessibility Testing using AxeAccessibility Testing using Axe
Accessibility Testing using AxeRapidValue
 
Automation in Digital Cloud Labs
Automation in Digital Cloud LabsAutomation in Digital Cloud Labs
Automation in Digital Cloud LabsRapidValue
 
Microservices Architecture - Top Trends & Key Business Benefits
Microservices Architecture -  Top Trends & Key Business BenefitsMicroservices Architecture -  Top Trends & Key Business Benefits
Microservices Architecture - Top Trends & Key Business BenefitsRapidValue
 
Uploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADIUploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADIRapidValue
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with KotlinRapidValue
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360RapidValue
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORSRapidValue
 
Real-time Automation Result in Slack Channel
Real-time Automation Result in Slack ChannelReal-time Automation Result in Slack Channel
Real-time Automation Result in Slack ChannelRapidValue
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDRapidValue
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkRapidValue
 
Video Recording of Selenium Automation Flows
Video Recording of Selenium Automation FlowsVideo Recording of Selenium Automation Flows
Video Recording of Selenium Automation FlowsRapidValue
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterRapidValue
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4RapidValue
 
The Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QAThe Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QARapidValue
 
Test Case Creation in Katalon Studio
Test Case Creation in Katalon StudioTest Case Creation in Katalon Studio
Test Case Creation in Katalon StudioRapidValue
 
How to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindHow to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindRapidValue
 
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValueDevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValueRapidValue
 
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...RapidValue
 

Mehr von RapidValue (20)

How to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-SpaHow to Build a Micro-Application using Single-Spa
How to Build a Micro-Application using Single-Spa
 
Play with Jenkins Pipeline
Play with Jenkins PipelinePlay with Jenkins Pipeline
Play with Jenkins Pipeline
 
Accessibility Testing using Axe
Accessibility Testing using AxeAccessibility Testing using Axe
Accessibility Testing using Axe
 
Automation in Digital Cloud Labs
Automation in Digital Cloud LabsAutomation in Digital Cloud Labs
Automation in Digital Cloud Labs
 
Microservices Architecture - Top Trends & Key Business Benefits
Microservices Architecture -  Top Trends & Key Business BenefitsMicroservices Architecture -  Top Trends & Key Business Benefits
Microservices Architecture - Top Trends & Key Business Benefits
 
Uploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADIUploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADI
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with Kotlin
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
 
Real-time Automation Result in Slack Channel
Real-time Automation Result in Slack ChannelReal-time Automation Result in Slack Channel
Real-time Automation Result in Slack Channel
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDD
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Video Recording of Selenium Automation Flows
Video Recording of Selenium Automation FlowsVideo Recording of Selenium Automation Flows
Video Recording of Selenium Automation Flows
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeter
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4
 
The Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QAThe Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QA
 
Test Case Creation in Katalon Studio
Test Case Creation in Katalon StudioTest Case Creation in Katalon Studio
Test Case Creation in Katalon Studio
 
How to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindHow to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using Valgrind
 
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValueDevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
 
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
A Technology Backgrounder to Serverless Architecture - A Whitepaper by RapidV...
 

Kürzlich hochgeladen

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 

Kürzlich hochgeladen (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Data Seeding via Parameterized API Requests

  • 1. Data Seeding via Parameterized API Requests
  • 2. Data Seeding via Parameterized API Requests Steps for Configuring RestAssured 1. Create a maven project in Eclipse. Please find the sample project structure below: 2. Add the following dependencies in pom.xml and update the project. <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.11</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.13</version> © RapidValue Solutions 2
  • 3. Data Seeding via Parameterized API Requests </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>3.13</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.13</version> </dependency> 3. Create a new package and a new class. In src/test/java, create a package ‘com.rvs.httpmethods’ and a java file ‘RequestParameterization.java’ 4. Add TestNG library to the project. Right click on Project -> Build Path -> Add Libraries -> TestNG 5. Start coding. Data-driven Testing For data-driven testing, the test values are read directly from the data files rather than using hard coded values. The data files can be csv files, excel files, text files, etc. A test containing several sets of hard coded values can be difficult to modify and maintain. It’s alway easier and a best practice to extend values in the data file than to modify the actual test scripts. Various inputs or data modifications can be handled easily without even touching the actual test script. © RapidValue Solutions 3
  • 4. Data Seeding via Parameterized API Requests Data-driven test performs following operation in a loop: - Retrieving input data from storage. - Parameterizing the required data in the Api request body. - Sending the request and verifying the response received. In the example of parameterizing the request body, you have to create an excel sheet with the test details. This data set basically contains the number and the employee name, which you have to parameterize in the request. Test data example is given below, which should be created at "/src/test/resources/Employees.xlsx”: Sheet name should be “Employees”. The following is the method that uses Apache POI library functions to fetch test data from the excel sheet and it will return the data as object. © RapidValue Solutions 4
  • 5. Data Seeding via Parameterized API Requests TestNG Data Providers REST Assured can be combined with TestNG, and it provides an easy mechanism to create data- driven tests through the DataProvider. public Object[][] getDataFromSheet(String TESTDATA_SHEET_PATH, String sheetName) { FileInputStream file = null; try { file = new FileInputStream(TESTDATA_SHEET_PATH); } catch (FileNotFoundException e) { e.printStackTrace(); } try { book = WorkbookFactory.create(file); } catch (InvalidFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } sheet = book.getSheet(sheetName); Object[][] data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()]; for (int i = 0; i < sheet.getLastRowNum(); i++) { for (int k = 0; k < sheet.getRow(0).getLastCellNum(); k++) { data[i][k] = sheet.getRow(i + 1).getCell(k).toString(); } } return data; } © RapidValue Solutions 5
  • 6. Data Seeding via Parameterized API Requests A Data Provider is a method annotated with @DataProvider. A Data Provider returns an array of objects. It helps you to write data-driven tests which essentially means that same test method can be run multiple times with different data-sets. Parameterization allows you to pick different values at run time. It reduces time and effort. Here, the TestData() method is annotated with @DataProvider annotation and the same is used in @Test configuration. DataProvider method will return an object array and its dimension must match the test method. Since your test method has two arguments, the DataProvider method must return object[][] so that it can be mapped to the arguments in the method. Here, you need to make sure that the array returned by the DataProvider should match the test method parameters. JSON File Creation A JSON file is a file that stores simple data structures and objects in JavaScript Object Notation (JSON) format. In order to create a JSON file in the project, right click on “src/test/resources” and click on New> Other. On selecting Other option, you will get several options. From these options, select General > File option, and then click Next. You can create a JSON file by giving the name “AddEmployee” and ".json" extension and click on finish button. You need to add the request body in the created JSON file. @DataProvider public Object[][] TestData() throws Exception { String dir = System.getProperty("user.dir"); Object[][] testObjArray = DataProviderUtils.getDataFromSheet(dir + "//src//test//resources//Employees.xlsx", "Employees"); return (testObjArray); } © RapidValue Solutions 6
  • 7. Data Seeding via Parameterized API Requests Here, the name inside the curly braces {} will be replaced with the values fetched from the excel sheet. Create Multiple Employees The below method will send the post request with the parameters provided and it will return the response. { "name": "${name}", "salary": "100100", "age": "25" } public Response postRequest(String URI, String resource, String payloadFolderPath, String EmpName) throws IOException { String payloadPath = payloadFolderPath; String payload = new String(Files.readAllBytes(Paths.get(payloadPath))); System.out.println(EmpName); payload = payload.replace("${name}", EmpName); System.out.println("Payload is" + "n" + payload); Response resp = RestAssured.given().baseUri(URI) .body(payload) .contentType("application/json") .log().all() .when() .post(resource).andReturn(); return resp; } AddEmployee.json © RapidValue Solutions 7
  • 8. Data Seeding via Parameterized API Requests The following method will create multiple employees. @Test(dataProvider="TestData") public void createMultipleEmployees(String EmpID, String EmpName) throws IOException { String baseURI = “http: //dummy.restapiexample.com”; String resource = “/api/v1/ create”; String dir = System.getProperty("user.dir"); String payloadPath = dir + "//src//test//resources//AddEmployee.json”; resp = postRequest(baseURI, resource, payloadPath, EmpName); JSONObject jObj = new JSONObject(resp.getBody().asString()); String emp_id = jObj.getString("id"); String emp_name = jObj.getString("name"); empName.add(emp_name); empID.add(emp_id); System.out.println("Created Employee Datails"); empData = new String[empID.size()][2]; } for (int i = 0; i < empID.size(); i++) { empData[i][0] = empID.get(i); empData[i][1] = empName.get(i); System.out.println(empData[i][0] + " - " + empData[i][1]); } © RapidValue Solutions 8
  • 9. Data Seeding via Parameterized API Requests Test Execution Output Conclusion Parameterization is very important for automation testing. It helps you to iterate on input data with multiple data sets that make your scripts reusable and maintainable. In few scenarios, you can still manage with hard coded request but the same approach will not work out where sheer count of combinations is to be validated. By implementing the right solution, you can keep your code base and test data size at ideal range and still savor the benefits of optimal coverage. Hope this blog helped you to understand the concept of parameterization and the actual implementation in a better way. Happy Learning! By, Mary Geethu, C. A. Senior Software Engineer © RapidValue Solutions 9
  • 10. Data Seeding via Parameterized API Requests About RapidValue RapidValue is a global leader in digital product engineering solutions including mobility, omni-channel, IoT, AI, RPA and cloud to enterprises worldwide. RapidValue offers its digital services to the world’s top brands, Fortune 1000 companies and innovative emerging start-ups. With offices in the United States, the United Kingdom, Germany and India and operations spread across the Middle-East, Europe and Canada, RapidValue delivers enterprise services and solutions across various industry verticals. Disclaimer: This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part of it may be used, circulated, quoted, or reproduced for distribution outside RapidValue. If you are not the intended recipient of this report, you are hereby notified that the use, circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful. © RapidValue Solutions www.rapidvaluesolutions.com/blogwww.rapidvaluesolutions.com +1 877.643.1850 contactus@rapidvaluesolutions.com © RapidValue Solutions 10