-1

I have a json request which requires current date to create the contract. I am writing automation script using Karate.

I know its possible use the javascript and java methods inside the feature file.

I have tried using the javascript but I seem not to get it correct

Below is the javascript I have tried, But I have limited knowledge with Javascript .. So I dont know how to call it as a method.

@Scenario1 Scenario:


* def familyCompositionPlan = read ('classpath:contract_management_service_json_files/create-family-composition-plan.json')

Given url CreatePlan And request familyCompositionPlan
* eval familyCompositionPlan.planCode = 'KTR-Plan' + code
* eval familyCompositionPlan.planName = 'Karate Plan' + code
* eval familyCompositionPlan.productId = resultPrd
* eval familyCompositionPlan.tierId = resultTier
* eval familyCompositionPlan.effFromDate = dd 
When method POST 
Then status 200


`function currentDate()
 {
 var s = '';
 var date = function()
 {var today = new Date();
 var dd = String(today.getDate()).padStart(2, '0');
 var mm = String(today.getMonth() + 1).padStart(2, '0');
 var yyyy = today.getFullYear();
 today = yyyy + '-' + mm + '-' + dd;};return s;
 }`
Kris
  • 8,680
  • 4
  • 39
  • 67
Koos
  • 39
  • 1
  • 8

1 Answers1

1

2 suggestions.

Don't have a space after read and before the (.

Use Java to do date manipulation: https://stackoverflow.com/a/52892797/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248