question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem loading .csv data into the .yml file for request body

See original GitHub issue

So the problem is that the “template” variables doesn’t get replaced when running the script.

“Real url” scrabled

home.yml file:

config:
    target: "http://someurl.com"
    phases:
      - duration: 1
        arrivalCount: 1
    payload:
      path: "users.csv"
      fields:
        - "email"
        - "password"
      order: "sequence"
    processor: "./log.js"
scenarios:
  - flow: 
    - log: "New virtual user running"
    - post:
        url: "/tokens"
        headers:
          Content-Type: "application/json"
        json:
          email: "{{ email }}"
          password: "{{ password }}"
        beforeRequest: "setJSONBody"
        afterResponse: "logHeaders"

users.csv file: (doesn’t matter what the actual data is actually)

email,password
my@email.com,awesomePassword

log.js file:

module.exports = {
    setJSONBody: setJSONBody,
    logHeaders: logHeaders
  }

  function setJSONBody(requestParams, context, ee, next) {
    console.log(requestParams)
    return next(); // MUST be called for the scenario to continue
  }

  function logHeaders(requestParams, response, context, ee, next) {
    console.log(response.body);
    return next(); // MUST be called for the scenario to continue
  }

Request (when running the test):

{ url: 'http://someurl.com/tokens',
  headers: {},
  json: { email: '{{ email }}', password: '{{ password }}' },
  beforeRequest: 'setJSONBody',
  afterResponse: 'logHeaders',
  method: 'POST',
  timeout: 120000,
}

As you might notice the template variables: '{{ email }}' and '{{ password }}' should be replaced by the input data from the .csv

What is wrong here? @hassy by your request I created this issue from the gitter comment I posted

If more information is required please let me know.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hassycommented, Sep 26, 2017

The variables do actually get replaced. beforeRequest hooks run before the substitutions happen, that’s why you’re seeing the templates in the output from your function.

To verify, run nc -l 10888 in one window, change target to “http://localhost:10888” and run your script. You should see something like:

$ nc -l 10888

POST /tokens HTTP/1.1
user-agent: Artillery (https://artillery.io)
content-type: application/json
host: localhost:10888
accept: application/json
content-length: 39
Connection: keep-alive

{"email":"email","password":"password"}

Edit/P.S.: thanks for taking the time to provide a reproducible test case! 😃

0reactions
rodrigofariasmcommented, May 28, 2019

@hassy Could you see that above? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem loading .csv data into the .yml file for request body #378
So the problem is that the "template" variables doesn't get replaced when running the script. "Real url" scrabled home.yml file: config: ...
Read more >
How to access csv data into yml file by storing it in a variable?
I am creating a .yml load scripting file for artillery tool and I am using the payload section which extracts the information from...
Read more >
Importing issues from CSV - GitLab Docs
You can import issues to a project by uploading a CSV file with the following ... To import issues, GitLab requires CSV files...
Read more >
Request body for Importing contacts with CSV file
Request body for Importing contacts with CSV file ... I am receiving a "Unable to parse the request body as multipart form-data" error....
Read more >
Using CSV DATA SET CONFIG - BlazeMeter Docs
The CSV Data Set Config is used to read lines from a file and to split them into variables. The following article elaborates...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found