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

КОМЕНТАРІ • 36

  • @Kumarkumar-gf3kk
    @Kumarkumar-gf3kk 3 роки тому +2

    Appreciate Author, video posted is very clean and descriptive

  • @AbidHussain-no6vd
    @AbidHussain-no6vd 3 роки тому

    Thanks for this important concept, where can learn @DataProvider also in depth.

  • @olegs3036
    @olegs3036 4 роки тому +1

    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;
      }
      }

  • @abhijitkumar8615
    @abhijitkumar8615 11 місяців тому

    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

  • @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.

  • @uigreseu5756
    @uigreseu5756 11 місяців тому +1

    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

  • @dibyajyotimohanty9252
    @dibyajyotimohanty9252 2 роки тому

    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.

  • @azharuddinkhan2317
    @azharuddinkhan2317 3 роки тому

    @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 3 роки тому

      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 роки тому +1

      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 .

  • @jayanthyadav4354
    @jayanthyadav4354 2 роки тому +1

    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 3 роки тому +2

      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

  • @sebastus27
    @sebastus27 3 роки тому

    I have these errors Cannot resolve method 'dataProvider' and Cannot resolve method 'name'.

  • @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="")?

  • @priyankasahu8780
    @priyankasahu8780 Рік тому

    Thank you.This is very helpful

  • @praveenmaddi4903
    @praveenmaddi4903 4 роки тому +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

  • @commonman8370
    @commonman8370 2 роки тому

    Now a days the problem how to approach for a solution. I think i have got some idea now. Thanks

  • @deepakpathak9368
    @deepakpathak9368 Рік тому +1

    Thanks!

  • @sebastus27
    @sebastus27 3 роки тому +1

    Now, I have this problem: Data provider must return Object[][] or Iterator

    • @gomathisubramanian8
      @gomathisubramanian8 Рік тому

      +1 while we try the same from intellij. Can you please provide us how to resolve the issue @
      SDET- QA Automation Techie

  • @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 роки тому +1

      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

  • @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 2 роки тому +1

    Please help