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:

{
"Departuremonth":"5",
"Creditcard":"4012000077777777",
"Firstname":"test",
"Lastname":"user",
"Phone":"8111231311"
}

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

testData.json:

   { "shortWait":"5000",
      "mediumWait":"12000",
     "longWait":"20000"
   }

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 object.name 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 
   browser.sleep(input.longWait)
 });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download