Reading Data from JSON File Using Protractor



Reading Data from JSON File Using Protractor

As we all are aware, data-driven testing is one of the important aspects we need to take care of while designing any testing framework. There could be different approaches to Data-Driven Testing like

  •         Reading Test Data from a properties file
  •         Reading Test Data from JSON File
  •         Reading Test Data from excel

We already have seen in another blog, how to read data from a properties file and use it in our automation framework. Please refer to this link to know about it.

In this blog, we will learn how to read data from JSON File and use them in our protractor automation test.

Before proceeding further to this blog, I assume you have basic knowledge about protractor and how to find XPath and execute protractor automation tests.


For this purpose lets first create one JSON file in our project lets name it as object.json


In this JSON File I will store my Application URL along with few data locator
Please Note that JSON file will always store data in Key-value pair inside { } braces for e.g “ElementName”:”Xpath”

Below is sample JSON File


Now to Read data from this JSON File inside our automation script we need to provide the path of this JSON File using require and then we can read data from this JSON File using JSONfileName.ElementName and can execute our automation script

Below is my runner class to execute this automation scripts



SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
Purushotham
June 6, 2019 at 3:04 PM

Thank you for the information Ankur. It's really informative, appreciate your efforts. Good Job!

Reply
avatar
September 11, 2019 at 10:37 PM

On the off chance that the identifiers of the two rooms are unique, open their regular entryway and bring together their identifiers and furthermore their rundowns. ExcelR Data Science Courses

Reply
avatar
April 29, 2020 at 4:05 PM

no working E/launcher - Error: Error: Cannot find module '../Data/testdata.json'
Require stack:
- C:\Users\hemas\Documents\Protractor TypeScript\JSFile\stepDefination\steps.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\cucumber\lib\cli\index.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\cucumber\lib\index.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\protractor-cucumber-framework\lib\cucumberLoader.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\protractor-cucumber-framework\index.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\protractor\built\runner.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\protractor\built\launcher.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\protractor\built\cli.js
- C:\Users\hemas\Documents\Protractor TypeScript\node_modules\protractor\bin\protractor
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (C:\Users\hemas\Documents\Protractor TypeScript\stepDefination\steps.ts:11:14)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at C:\Users\hemas\Documents\Protractor TypeScript\node_modules\cucumber\lib\cli\index.js:119:42
at Array.forEach ()
at Cli.getSupportCodeLibrary (C:\Users\hemas\Documents\Protractor TypeScript\node_modules\cucumber\lib\cli\index.js:119:22)
at Cli.run (C:\Users\hemas\Documents\Protractor TypeScript\node_modules\cucumber\lib\cli\index.js:141:37)
[16:00:39] E/launcher - Process exited with error code 100
npm ERR! code ELIFECYCLE
npm ERR! errno 100
npm ERR! protractor-typescript@1.0.0 cucumbertest: `protractor JSFile/cucumberconfig.js`
npm ERR! Exit status 100
npm ERR!
npm ERR! Failed at the protractor-typescript@1.0.0 cucumbertest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\hemas\AppData\Roaming\npm-cache\_logs\2020-04-29T10_30

Reply
avatar
June 16, 2020 at 3:43 PM

This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post. I will visit your blog regularly for Some latest post. buy instagram spread likes cheap

Reply
avatar
July 3, 2020 at 8:12 PM

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one.
Data Science Certification in Bangalore

Reply
avatar
August 11, 2020 at 4:29 PM

I truly appreciate essentially perusing the entirety of your weblogs. Basically needed to advise you that you have individuals like me who value your work. Certainly an extraordinary post. Caps off to you! The data that you have given is useful.
360DigiTG supply chain analytics beginner's guide

Reply
avatar
Anonymous
December 18, 2020 at 11:19 AM

This is a splendid website! I"m extremely content with the remarks!ExcelR Data Analytics Course

Reply
avatar
December 29, 2020 at 2:39 PM

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.Best Data Science Courses in Hyderabad

Reply
avatar
November 8, 2024 at 3:23 PM

This article provides a comprehensive guide on how to incorporate data-driven testing into your Protractor automation framework by reading data from a JSON file.
Data science courses in Visakhapatnam

Reply
avatar
November 8, 2024 at 5:10 PM

"Nice write-up! If you're looking to upskill in data science, be sure to check out the Data science courses in Brighton. It's a great learning opportunity for anyone wanting to get ahead in the field!"

Reply
avatar
November 19, 2024 at 9:33 PM

This blog does an excellent job of explaining how to read data from a JSON file for Protractor automation tests. The clear examples and structured approach make it easy to follow and implement. Great insights for enhancing test frameworks!
Data science courses in Gujarat





Reply
avatar
November 24, 2024 at 3:17 PM

Reading data from a JSON file using Protractor allows you to dynamically input values into your tests, making them more flexible and reusable. By utilizing the `fs` module and parsing the data, you can easily integrate external datasets into your automation scripts.

Data science courses in Pune

Reply
avatar
November 26, 2024 at 12:55 PM

https://www.qaautomation.co.in/2018/12/reading-data-from-json-file-using-protractor.html?showComment=1732605920461#c38070791554567812

Reply
avatar
December 7, 2024 at 4:20 PM

Fantastic guide! I’ve been using Protractor for end-to-end testing, but reading data from JSON files has always been a challenge. Your clear, easy-to-follow example made it a lot simpler. It’s also a nice touch to explain how to handle different data structures in JSON. This will be very useful in my future projects
Data science courses in Glasgow

Reply
avatar
December 8, 2024 at 6:28 PM

This post on reading data from JSON files using Protractor is extremely well-done! A great guide for anyone in automation testing.

Data science courses in France

Reply
avatar
December 13, 2024 at 1:24 AM

Reading data from a JSON file in Protractor is a smart way to implement data-driven testing by keeping test data separate from the code. This approach enhances flexibility, as you can easily update your test data without modifying the test scripts themselves. It's an efficient method for automating tests and ensuring your framework can handle dynamic input sources.


Data science Courses in City of Westminster

Neel KBH
kbhneel@gmail.com

Reply
avatar
December 13, 2024 at 4:53 PM


This guide on reading data from a JSON file using Protractor is concise and practical. It clearly explains how to integrate JSON data into Protractor tests, enhancing test efficiency and reusability. The step-by-step approach, paired with examples, makes it easy for developers to understand and implement dynamic test data management.
Data science Courses in Berlin


Reply
avatar
December 18, 2024 at 8:49 PM

Thank you for the information! such an amazing information.
Data science Courses in Ireland

Reply
avatar