简体   繁体   中英

SOA Automation using javaScript to get the value from json using cucumber feature file

getScheduleInfo.inputData.newSchedules[0].name=propValues[0]; 
getScheduleInfo.inputData.newSchedules[0].description=propValues[1]; 
getScheduleInfo.inputData.newSchedules[0].startDate=propValues[2]

This is the javaScript function written earlier which hard coded I want to get the values dynamically using for loop

You could keep an array of property names ( name , description and startDate ) and access those within your for loop to change each property (by using bracket notation ) upon each iteration like so:

const props = ['name', 'description', 'startDate'];
for(let i = 0; i < props.length; i++) {
  const prop = props[i];
  getScheduleInfo.inputData.newSchedules[0][prop] = propValues[i]; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM