How To Read Data From JSON File In Playwright | Data Driven Test In Playwright

Поділитися
Вставка
  • Опубліковано 5 лип 2024
  • In this tutorial, we'll delve discuss data-driven testing in Playwright. If you've ever thought how to efficiently read data from a JSON file for your Playwright scripts, you're in the right place!
    Timeline
    00:00 - Why you should not hard code test data
    02:40 - Reading Data From JSON Files
    17:26 -Implementing Data-Driven Tests
    Resources
    Explore additional resources and documentation to deepen your understanding of data-driven testing in Playwright.
    playwright.dev/docs/test-para...
    Playwright Series - • Playwright Tutorials F...
    Subscribe and Stay Updated:
    Don't forget to subscribe for more insightful tutorials on Playwright, testing strategies. Hit the bell icon to receive notifications whenever we release new content!
    Connect with us:
    Email - mukeshotwani@learn-automation.com
    Linkedin- / mukesh-otwani-93631b99
    Instagram- / mukeshotwaniofficial
    Facebook Group- / 256655817858291
  • Наука та технологія

КОМЕНТАРІ • 24

  • @The4m3r
    @The4m3r 7 місяців тому +3

    This is great, finally something in a pool of playwright videos accross youtube, useful not just click and type, we need more content like this. Thank you

  • @ganeshs4651
    @ganeshs4651 4 дні тому

    Hi Mukesh,
    I couldn't find your video for API Rest testing using Playwright for complex Json payload. Could you please share the link or create a new video for the same?

  • @shreyanshjain4519
    @shreyanshjain4519 7 місяців тому +1

    Looking forward to more such videos 🙂

  • @arpitlahoti6086
    @arpitlahoti6086 8 днів тому

    Hi Mukesh I have done this same in my playwright and it works perfectly fine now I need to achieve clicking on a login as well and see every time It takes the new user from json file and login into the url so if any user is blocked or locked it can throw an error - how do I do that ? Please assist

  • @Rana-Farhan
    @Rana-Farhan Місяць тому +1

    This channel require more views and subscribers.

  • @Mukeshotwani
    @Mukeshotwani  7 місяців тому

    Which data source you are using for test data?

  • @gadulayuvasaisantosh9036
    @gadulayuvasaisantosh9036 7 місяців тому +1

    hi Mukesh
    had a query ..
    rather than giving input data , can you please explain faker integration for randomly generating ids if we have a scenario for signing up multiple ids
    Thanks..

    • @Mukeshotwani
      @Mukeshotwani  6 місяців тому

      You can use below faker module www.npmjs.com/package/@faker-js/faker

  • @shreevallinataraj4500
    @shreevallinataraj4500 4 місяці тому

    Hi Mukesh, i tried using this in my project but i am getting the error for using describe, could you please suggest me Error: Playwright Test did not expect test.describe() to be called here.
    Most common reasons include:
    - You are calling test.describe() in a configuration file.
    - You are calling test.describe() in a file that is imported by the configuration file.
    - You have two different versions of @playwright/test. This usually happens
    when one of the dependencies in your package.json depends on @playwright/test.

  • @shreyanshjain4519
    @shreyanshjain4519 7 місяців тому +2

    Hi Mukesh, Thank you for this video :-) I am going through it completed watching till starting 10 mins. Just wanted to mention here that I was able to read the data from the json file using the below line of code.
    const testData = require("../test-data/readjson.json"); (did not use JSON.stringify and JSON.parse)

    • @Mukeshotwani
      @Mukeshotwani  7 місяців тому

      Great Shreyansh , how are you using that data in your script ? Can you try and let me know the results.

    • @rifattaque7301
      @rifattaque7301 6 місяців тому

      @@Mukeshotwani yes we don't need the parsing and stringifying the data to access it. you just simply import the json file and then use dot notation to access it like you did in the video.

    • @rathishramankutty302
      @rathishramankutty302 5 місяців тому

      I guess why we do the .parse and .stringify is to convert a jscript object into json and viseversa. in fact the data is already in json body so doesnt needed to do the manipulation there@@Mukeshotwani

  • @Leader977
    @Leader977 5 місяців тому +1

    Thank you a lot!

  • @sivaramakrishnareddyrajula9605
    @sivaramakrishnareddyrajula9605 6 місяців тому +1

    Hi Mukesh,
    I have multiple different sets of data having key value pairs stored in a const array, I need to read data using key. Can you help me to read data using key?

    • @Mukeshotwani
      @Mukeshotwani  6 місяців тому

      Its very easy basically same data we are reading from JSON. In case you want to keep in array then u can use direct array. Recommendation is not to hardcode test data.

    • @sivaramakrishnareddyrajula9605
      @sivaramakrishnareddyrajula9605 5 місяців тому

      Thank you for your reply.
      I am getting this TypeError: testdata is not iterable playwright. However, this video really helps me.
      FYI, I used counter before for loop and incremented counter in loop as I have 1600+ records in json file which are generating from excel source.

  • @harithay2127
    @harithay2127 5 місяців тому +1

    Hi Mukesh it is such a great video, could you please provide code snippets and I will do practice on this code

    • @harithay2127
      @harithay2127 5 місяців тому +1

      I tried your code but still I am getting errors like duplicate test

  • @goranstojanovski7471
    @goranstojanovski7471 5 місяців тому +1

    HI Mukesh,
    Great video, but it would be more interesting and advanced if you record a video for creation new user using random method for each field.
    Have a nice day :)

    • @Mukeshotwani
      @Mukeshotwani  5 місяців тому +1

      Noted, will be recording soon.