Ashutosh Anshu Ashutosh Anshu -4 years ago 89
JSON Question

How to pass wait time or sleep time through json data?

Is it possible to pass wait time or sleep time though Json data.

For example, this is my Json data:


which i will be fetching in my protractor codes. Now in some places in protractor, I have used sleep to wait for the element.

browser.sleep(3000); //sleep for 3 seconds

So, that sleep time I am writing as a code in protractor. I want to call that sleep or wait from the json data only.

Can anyone suggest something on this?

Answer Source

Yes, it is possible to pass any kind of data from json file. It's quite easy too. Follow below code:

1->Create json file ex-testData.json with following inputs


   { "shortWait":"5000",

2->Import the testData.json file on sepc.js/methods.js file where you would like to use it.

 var input=require("../testData.json")//make sure testData.json file path is correct

3->Now you can read the respective wait value from testData.json file using syntax like "input.shortWait" and pass this value to wait/sleep methods as follows:

it('example to pass wait time from json file:'function(){
   //line of codes
   utility.wait(input.shorWait);//make sure that wait method available in 
   //utility file 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download