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
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
Thank you for the information Ankur. It's really informative, appreciate your efforts. Good Job!
ReplyOn 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
Replyno working E/launcher - Error: Error: Cannot find module '../Data/testdata.json'
ReplyRequire 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
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
ReplyReally nice and interesting post. I was looking for this kind of information and enjoyed reading this one.
ReplyData Science Certification in Bangalore
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.
Reply360DigiTG supply chain analytics beginner's guide
This is really useful information. I am satisfied with reading your blog.
Replyhow to learn java easily
cross platform mobile app development
successful social media campaigns
what is microsoft azure
tableau interview questions and answers
This is a splendid website! I"m extremely content with the remarks!ExcelR Data Analytics Course
ReplyIts 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
ReplyThis is the best explanation for this title and keep updating here...
ReplyOpenspan Online Training
Openspan Online Course
Matlab Training in Chennai
Leadership Training in Chennai
This blog is helpful to me and I hope this will be valuable information.
Replymultithreading in java
nested if java
string in java
non primitive data types
software testing interview question and answer
angularjs interview questions
Well done work and this post very useful for me to know about this topic...
ReplyFull Stack developer Course in Pune
Full Stack developer Course in Hyderabad
Full Stack Developer Training in Chennai
Full Stack developer Course in Mumbai
Full Stack developer Course in Gurgaon
Google Adwords Online Course
Google Ads Online Course
This is great work and it is a very innovative blog. Well done!
ReplyGo Lang Training in Chennai
Google Cloud Training in Chennai
Google Cloud Online Training
Google Cloud Online Course
Aivivu - ฤแบกi lรฝ chuyรชn vรฉ mรกy bay trong nฦฐแปc vร quแปc tแบฟ
Replysฤn vรฉ mรกy bay giรก rแบป ฤi Mแปน
vรฉ mรกy bay tแปซ mแปน vแป viแปt nam bao nhiรชu tiแปn
ฤแบทt vรฉ mรกy bay tแปซ ฤแปฉc vแป viแปt nam
giรก vรฉ nhแบญt viแปt
Mรกy bay tแปซ Hร n Quแปc vแป Viแปt Nam
vรฉ mรกy bay tแปซ canada vแป viแปt nam giรก rแบป
khรกch sแบกn cรกch ly แป sร i gรฒn