JSON Tutorial Part-6 | Data Driven Testing in Selenium with Java using JSON File
Вставка
- Опубліковано 7 січ 2020
- Topic : Data Driven Testing in Selenium with Java using JSON File
JSON Used
---------------------
{
"userlogins": [
{
"username": "abc@gmail.com",
"password": "Test@123"
},
{
"username": "xyz@gmail.com",
"password": "Test@12"
},
{
"username": "pqr@gmail.com",
"password": "Test@123"
}
]
}
#########################
Udemy Courses:
#########################
Manual Testing+Agile with Jira Tool
************************************
► shorturl.at/xNXZ4
Selenium with Java+Cucumber
********************************
► shorturl.at/aIKMW
Selenium with Python & PyTest
********************************
► shorturl.at/ELW09
Selenium with python using Robot framework
****************************************
► shorturl.at/bcDPZ
API Testing(Postman, RestAssured & SoapUI)
*****************************************
► shorturl.at/uAWY7
Web & API Automation using Cypress with Javascript
********************************************
► rb.gy/4uum2n
Playwright with Javascript
**************************
► shorturl.at/gALZ1
Jmeter-Performance Testing
************************
► rb.gy/ocj7r2
SDET Essencials(Full Stack QA)
*************************
► rb.gy/hlnf2v
Appium-Mobile Automation Testing
************************************
► rb.gy/wmzv64
Java Collections
*****************
► bit.ly/3S66ezE
Python Programming
*********************
► urlis.net/gdsfpb0s
Cucumber BDD Framework
***************************
► bit.ly/3F7d69r
Protractor with Javascript
***************************
► urlis.net/4uddm1qb
####################################
UA-cam Playlists:
####################################
Manual Testing & Agile
***********************
► bit.ly/3ujvaYa
► bit.ly/3OYzxQj
SQL
*************************
► bit.ly/3R6XjeG
► bit.ly/3nE0a1s
► bit.ly/3IeKuuJ
linux & Shell Scripting
**********************
► bit.ly/3up1Z6a
► bit.ly/3nzvGxx
Java
**********************
► bit.ly/3R9QfOs
► bit.ly/3AoRMKM
► bit.ly/3IbTTDn
► bit.ly/3ybXInv
► bit.ly/3yCoHdw
Selenium With Java+Cucumber
********************************
► bit.ly/3P2FMm4
► bit.ly/3yhiIt4
► bit.ly/3uokzet
► bit.ly/3a7XIND
► bit.ly/3umN2S9
► bit.ly/3aar7GW
► bit.ly/3y9kD2S
► bit.ly/3uhLskn
Python
********************************
► bit.ly/3agNgU0
► bit.ly/3NJNnoy
► bit.ly/2CTQ4mR
► bit.ly/3OIYWh1
Selenium With Python,Pytest&Behave
***************************************
► bit.ly/3OHHoC9
► bit.ly/3IeNLdv
► bit.ly/2J4tPeT
► bit.ly/3ydSkAq
Selenium With Python Using Robert Framework
(Web&API Testing)
*************************************************
► bit.ly/3nUvlpr
► bit.ly/3nUvE3z
API Testing (Postman,SoapUi,&Rest Assured)
**********************************************
► bit.ly/3OXacWY
► bit.ly/3yh0UhE
► bit.ly/3nC9DWQ
► bit.ly/3yGfhNS
► bit.ly/3OJa11H
► bit.ly/3P2slCC
Mobile App Testing Appium
****************************
► bit.ly/3Al49HG
Performance Testing Jmeter
*******************************
► bit.ly/3nz4fE7
Maven,Jenkins,Git,Github,CI/CD
*******************************
► bit.ly/3P16HPj
► bit.ly/3yhlUVA
► bit.ly/3afYfwT
► bit.ly/3yGzweG
► bit.ly/3yF73Ws
► bit.ly/3NCOmH7
SQL,DB Testing&ETL,Bigdata
*******************************
► bit.ly/3NKOcNY
► bit.ly/3OVpDyI
► bit.ly/3NEvUy0
► bit.ly/3IryxlT
► bit.ly/3RkWBLh
JavaScript Based Automation Tools
********************************
► bit.ly/3nUx51X
► bit.ly/3AqI6Q0
► bit.ly/3yeurbT
► bit.ly/3ujzpTK
Selector Hub Tools
********************
►rb.gy/h3h424
GraphQL
******************
► rb.gy/sj3gys
Cypress API Testing
********************
► shorturl.at/fjKPX
Cypress Web Testing
**********************
► shorturl.at/agjlK
Playwright with Javascipt
**************************
► shorturl.at/adSTY
#SeleniumTesting
#DataDrivenTesting
#JavaProgramming
#JSONFile
#AutomatedTesting
#QualityAssurance
#TestingFramework
#TestAutomation
#SoftwareTesting
#SeleniumJava
#TestingTips
#TestScripts
#QAEngineer
#TestDesign
#SeleniumWebdriver
#JSONData
#TestFrameworks
#AutomationScripting
#TestingTutorial
#TestingBestPractices
#TestCases
#JavaDevelopers
#AutomatedTests
#QACommunity
#TestDrivenDevelopment
#SeleniumTips
#JSONParsing
#ContinuousTesting
#TestAutomationTools
#SeleniumTricks
#CodingInJava
#DataVisualization
#QualityEngineering
#TestDataManagement
#JSONInJava
#SeleniumExperts
#AgileTesting
#AutomatedTestCases
#TestingInnovation
#JSONAutomation
#SeleniumWithJSON
#JavaCoding
#TestingSolutions
#JSONTesting
#TestDrivenQA
#SeleniumLearning
Appreciate Author, video posted is very clean and descriptive
Glad it was helpful!
Thanks for this important concept, where can learn @DataProvider also in depth.
Hi @SDET, thank you for the video. I do everything by video and when I set the String type in the method - Java swears and offers to set the Object type, why?
this the method i created as per video i run the code with out any errors
@DataProvider(name = "dp")
public String[] readJson() {
// Here we are going to use simple json jar
// We need to create JSon praser object to read json data
JSONParser jsonParser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(".\\jsonfiles\\testdata.json");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] arr = null;
try {
Object obj = jsonParser.parse(reader);
//Cast the object to JSOn Object
JSONObject userloginsJsonobj = (JSONObject) obj;
//Convert to user JSON Array
JSONArray userLoginArray = (JSONArray)userloginsJsonobj.get("userlogins");
//create a java array
arr = new String[userLoginArray.size()];
// Iterate through user Jsaon array
for (int i = 0; i < userLoginArray.size(); i++) {
JSONObject users = (JSONObject) userLoginArray.get(i);
String user = (String) users.get("username");
String pwd = (String) users.get("password");
arr[i] = user + "," + pwd;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return arr;
}
}
I have a different scenario here, i have userdata in a json file and all these datas are unique. I want to pass them as a parameter in different test cases under @test method.
In your eg you are passing same data everytime, but I want to pass first array data in first test case, 2nd array data in 2nd test case and so on. Note. The test cases are individual classes.
Can you please let me know how to achieve that
Thanks for your teaching sir, and I have the question that.... Is it possible to read the data from Excel then convert as json and pass to our specific function by single code?
I have solved read the data from Excel file and convert as JSON file. But I need to pass the converted json data into specific function using dataprovider in a single step.
Hello. Why I'm not able to use String[] . It tells me that I should use Object[][]. The problem is that I try to reproduce the code from your video but it asks me to make return type Object[][]. Why? I would like to use String [] like in your video
Hii sdet can you plz explain how to convert nested and complex json file into csv by using java code.its really helpful for me.
@SDET , how your code is reading single dimension array by using data provider, as I am aware testng data provider needs 2 D Array Object ? Please clarify
The return type of data provider could be any object [],[][].[][][].., it is up to you what to wanna use, also it depends on your logic and the complicity of the data you are dealing with. Here it is easy to use an array to retrieve data from JsonArray and return it with username and password combined.
2D array also ARRAY only ( Array of Array) . if u think in depth here readjson data method is returning array , but again split method is applied on element of returned array , which returning array again .
Geting error java.lang.ClassCastException: class org.json.simple.JSONArray cannot be cast to class org.json.JSONObject (org.json.simple.JSONArray and org.json.JSONObject are in unnamed module of loader 'app') "
Which is better for data driven testing, Excel or JSON? what are the advantages and disadvantages of JSON over excel for data driven testing?
JSON has mainly advantages rather than disadvantes
1.JSON is more lightweight
2.No need to install seperate software to read excels.This is specifically useful when running scripts on server.
3.No more complicated code.
In excel we need to provide following hiearchy
File,Sheet,rownum/colnum,cell
I have these errors Cannot resolve method 'dataProvider' and Cannot resolve method 'name'.
Mr SDET, I have a question, what does name mean from the @DataProvider(name="dp")?
@DataProvider(name="dp")? dp is the identifier(name) of DataProider .you can give any value as name for the data provider @DataProvider(name="")?
Thank you.This is very helpful
Glad it was helpful!
When I executed same code , i am getting Below error . Tried in Google also but did get anything. Please help me to sort out the issue
Error Message: org.json.simple.parser.ParseException must return either Object[] [] or Iterator[], not class [Ljava.lang.String;
Can anyone pls explain why its showing the above error? any solution? Thanks
Now a days the problem how to approach for a solution. I think i have got some idea now. Thanks
Thanks!
Welcome
Now, I have this problem: Data provider must return Object[][] or Iterator
+1 while we try the same from intellij. Can you please provide us how to resolve the issue @
SDET- QA Automation Techie
Hi
If I don't define my data into Jsonfile under an array and I defined all my data in single object. how do I read the file data in testng?
can be achieved .only thing is one need to get familiar with Jason parsing (simple json api)
@@Kumarkumar-gf3kk hi thanks
I have got hands on that long back
org.testng.internal.reflect.MethodMatcherException:
[public void ReadJSONFile.test(java.lang.String,java.lang.String)] has no parameters defined but was found to be using a data provider (either explicitly specified or inherited from class level annotation).
Data provider mismatch
Method: test([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(java.lang.String) null,1234433]
is this issue resolved?
How to deal with , In case if we are getting the same kind of response from a webpage , for example
{
"flights": [
{
"code": "A70567",
"description": "from bombay to delhi"
}
]
}
Please help