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