Java Interview question Set-1:
SET-01 1-10
Java Interview question Set-2:
Java Interview question Set-3:
Data driven testing for Selenium and Rest Assured with Json file
SDET Interview Question and Answers.
Jenkins Interview Questions and Answers.
Appium Interview Questions and Answers
Selenium Interview Questions and answers.
GIT Interview Questions and Answers
How to fetch test data from json file using jsonobject
1. Create a testdata.json file
2. Create a method which will fetch value from json object using key
public static String getTestData(String input) throws IOException, ParseException {
String testdata;
return testdata = (String) getJsonData().get(input);//input is the key
}
3. Create a method as getJsonData() with return type as JsonObject
public static JSONObject getJsonData() throws IOException, ParseException {
//pass the path of the testdata.json file
File filename = new File("TestData//testdata.json");
//convert json file into string
String json = FileUtils.readFileToString(filename, "UTF-8");
//parse the string into object
Object obj = new JSONParser().parse(json);
//give jsonobject o that I can return it to the function everytime it get called
JSONObject jsonObject = (JSONObject) obj;
return jsonObject;
}
How to fetch test data from json file using jsonPath?
Note: Use https://jsonpath.com/ to write your own jsonpath1. Create a testdata.json file
2. Create a method which will fetch value from json object using key
public static String getdatafromjson(String path) throws IOException {
File f = new File("TestData//testdata.json");
String json = FileUtils.readFileToString(f, "UTF-8");
String result;
return result = JsonPath.read(json, path);
}
There is one more way to do the same which is by using the POJO class, check the post below for all the steps in json to pojo conversion:
How to use mocking and create Stub with Wiremock for your integration tests?
Ans:Click Here For Answer With Code And Steps
Java Interview question Set-1:
SET-01 1-10
Java Interview question Set-2:
Java Interview question Set-3:
***********************************
Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session
Note: If anyone need help in designing framework or virtual support for Automation work then reach out to me @sidharth.shukla19@gmail.com/9619094122
***********************************
*************************************************
SeleniumWebdriver Automation Testing Interview Questions:API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign
Java Related Interview Question Set
https://automationreinvented.blogspot.com/search/label/Java
GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT
Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20QuestionsMobile Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Mobile%20TestingPython Interview Question Set for QAE - SDET - SDE:
https://automationreinvented.blogspot.com/search/label/Python
No comments:
Post a Comment