Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  176] [ 1]  / answers: 1 / hits: 6678  / 5 Years ago, tue, august 20, 2019, 12:00:00

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;
}`

More From » karate

 Answers
8

2 suggestions.



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



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


[#6524] Saturday, August 17, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shylaelisan

Total Points: 37
Total Questions: 94
Total Answers: 110

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;