JSON Tutorial Part-6 | Data Driven Testing in Selenium with Java using JSON File

  Рет қаралды 53,036

SDET- QA

SDET- QA

Күн бұрын

Пікірлер: 36
@deepakpathak9368
@deepakpathak9368 2 жыл бұрын
Thanks!
@sdetpavan
@sdetpavan 2 жыл бұрын
Welcome
@Kumarkumar-gf3kk
@Kumarkumar-gf3kk 3 жыл бұрын
Appreciate Author, video posted is very clean and descriptive
@sdetpavan
@sdetpavan 3 жыл бұрын
Glad it was helpful!
@AbidHussain-no6vd
@AbidHussain-no6vd 3 жыл бұрын
Thanks for this important concept, where can learn @DataProvider also in depth.
@uigreseu5756
@uigreseu5756 Жыл бұрын
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
@jeyasankara4781
@jeyasankara4781 Жыл бұрын
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.
@abhijitkumar8615
@abhijitkumar8615 Жыл бұрын
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
@olegs3036
@olegs3036 4 жыл бұрын
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?
@Kumarkumar-gf3kk
@Kumarkumar-gf3kk 3 жыл бұрын
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; } }
@jayanthyadav4354
@jayanthyadav4354 3 жыл бұрын
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') "
@bonybaby1912
@bonybaby1912 4 жыл бұрын
Which is better for data driven testing, Excel or JSON? what are the advantages and disadvantages of JSON over excel for data driven testing?
@manishbhatia2724
@manishbhatia2724 4 жыл бұрын
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
@praveenmaddi4903
@praveenmaddi4903 4 жыл бұрын
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;
@mohammedzakaria8783
@mohammedzakaria8783 4 жыл бұрын
Can anyone pls explain why its showing the above error? any solution? Thanks
@priyankasahu8780
@priyankasahu8780 Жыл бұрын
Thank you.This is very helpful
@sdetpavan
@sdetpavan Жыл бұрын
Glad it was helpful!
@azharuddinkhan2317
@azharuddinkhan2317 4 жыл бұрын
@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
@amlam5685
@amlam5685 4 жыл бұрын
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.
@AbidHussain-no6vd
@AbidHussain-no6vd 3 жыл бұрын
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 .
@sebastus27
@sebastus27 3 жыл бұрын
Mr SDET, I have a question, what does name mean from the @DataProvider(name="dp")?
@Kumarkumar-gf3kk
@Kumarkumar-gf3kk 3 жыл бұрын
@DataProvider(name="dp")? dp is the identifier(name) of DataProider .you can give any value as name for the data provider @DataProvider(name="")?
@sebastus27
@sebastus27 3 жыл бұрын
I have these errors Cannot resolve method 'dataProvider' and Cannot resolve method 'name'.
@commonman8370
@commonman8370 3 жыл бұрын
Now a days the problem how to approach for a solution. I think i have got some idea now. Thanks
@dibyajyotimohanty9252
@dibyajyotimohanty9252 3 жыл бұрын
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.
@sharana_rani
@sharana_rani 3 жыл бұрын
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?
@Kumarkumar-gf3kk
@Kumarkumar-gf3kk 3 жыл бұрын
can be achieved .only thing is one need to get familiar with Jason parsing (simple json api)
@sharana_rani
@sharana_rani 3 жыл бұрын
@@Kumarkumar-gf3kk hi thanks I have got hands on that long back
@sebastus27
@sebastus27 3 жыл бұрын
Now, I have this problem: Data provider must return Object[][] or Iterator
@gomathisubramanian8
@gomathisubramanian8 2 жыл бұрын
+1 while we try the same from intellij. Can you please provide us how to resolve the issue @ SDET- QA Automation Techie
@olegs3036
@olegs3036 4 жыл бұрын
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]
@pamci284
@pamci284 4 жыл бұрын
is this issue resolved?
@chagantisivakrishna9979
@chagantisivakrishna9979 2 жыл бұрын
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" } ] }
@jayanthyadav4354
@jayanthyadav4354 3 жыл бұрын
Please help
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Taking ScreenShot ONLY for Failed Tests in Selenium using TestNG Listener
32:12
Naveen AutomationLabs
Рет қаралды 118 М.
Data Driven Testing using JSON in Selenium WebDriver
21:39
Specialize Automation
Рет қаралды 21 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,3 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН