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