0

Feature: Api test for Login user and get token

Scenario Outline: Auth login get token Given A login When I send the POST request to /auth/login Then I get response statusCode 200 Then I get response token as string When I send the current user GET request to /auth/me Then I get the current user response statusCode 200 Then I get response of current user Given A refresh When I send the refresh auth session POST request to /auth/refresh Then I get the refresh auth session response statusCode 200 Then I get response of refresh auth session data with token

Examples: 
  | request                                          | refreshRequest         |
  | {"username": "kminchelle","password": "0lelplR"} | {"expiresInMins": 30 } |

I want read request data from a json file like Examples: | read("data/data.json") |

Is there any proper way to load the data

1 Answer 1

0

You can do this with Handlebars!

The handlebars library can be installed

const Handlebars = require('handlebars');

/**
 * Registers handlebars helpers with the given handlebars object.
 * @param {object} hbs The handlebars object.
 * @returns {object} The handlebars object.
 */
function registerHelpers(hbs) {
    // Data Format Helpers

    // Converts JSON object to a string.
    hbs.registerHelper('json', context => JSON.stringify(context));
}


// this is where we initialize the common helper functions with handlebars.
registerHelpers(Handlebars);

Reference data from JSON files

Place your JSON files in the ./data folder in your project. You can then reference them by name.

Given a file called myfile.json which contains { "value": 1, "message": "my message" }:

  • {{data.myfile.value}} - outputs 1
  • {{data.myfile.message}} - outputs my message

Data Format Helpers

If you want to output a value as a JSON object, use the json handlebars helper with the triple-braces: {{{json data.myfile}}} - outputs the full json object as a string

Examples: 
  | request                                  |  
  | {{json data.events.RequestBody}}         | 


processMessage(filepath, context) {
     return Handlebars.compile(filepath);
}

const fileContents = processMessage(request, [context]);

return JSON.parse(fileContents );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.