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.

Foreach not found

See original GitHub issue

Today adding a dictionary to a variable in the yml I got a foreach error.

JS Class

var randomName = faker.name.firstName;
    var randomLastName = faker.name.lastName;
    var addresses = [];

    // noinspection JSAnnotator
    for( var i = 0; i < faker.random.number(5); i++ ){

        var address = new Object();

        address.zipcode = faker.address.zipCode();
        address.city = faker.address.city();
        address.county = faker.address.county();
        address.streetName = faker.address.streetName();
        address.latitude = faker.address.latitude();
        address.long = faker.address.longitude();

        addresses.push(address);
    }

   // console.log(addresses)
     userContext.vars.name = randomName;
     userContext.vars.lastname = randomLastName;
     userContext.vars.address = addresses;
    return done();


yml file
config:
  target: 'http://127.0.0.1:8000'
  http:
      timeout: 10
  phases:
    - duration: 2
      arrivalRate: 2
  processor: "./specs/PersonsFaker.js"

scenarios:
  - name: "Add a person with addresses"
    flow:
      - function: "addPerson"
      - post:
          url: "/person/"
          json:
            firstName: "{{ firstname }}"
            lastName: "{{ lastname }}"
            address: "{{ address }} "
  - log: "Address {{ firstname }}, {{ lastname }}"

This is the output

/node_modules/artillery/lib/commands/run.js:451
    scenario.flow.forEach(function(step) {
                 ^
TypeError: Cannot read property 'forEach' of undefined

I updated with the current main branch and nothing is changing.

Repasted the yml file

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
hassycommented, Apr 1, 2019

scenarios should be at the top level (same as config)

0reactions
zaheerakhtercommented, Apr 14, 2020

Error - TypeError: scenario.flow.forEach is not a function

config:
    target: "wss://uel"
    phases:
      - duration: 60
        arrivalRate: 100
    ws:
      # Set a custom subprotocol:
scenarios:
    - engine: "ws"
      flow:
        loop:
          - send:  "{ \"op\": \"p\" }"
          - think: 1
        count: 10
Read more comments on GitHub >

github_iconTop Results From Across the Web

Foreach command not found - Ask Ubuntu
I'd previously used the foreach command on older Ubuntu versions without a problem, but now I'm getting "command not found".
Read more >
forEach not working when for loop does with an array of objects
forEach iterates over indexes not over properties . ... If you intend to add in the way you are, then just use an...
Read more >
Don't use Array.forEach, use for() instead Example - Coderwall
Don't use Array.forEach, use for() instead Example protip about performance, loop, and javascript.
Read more >
forEach loop is not working - JavaScript
In this challenge, for loop is working fine. But forEach loop is not. Why so? Your code so far function findElement(arr, func) {...
Read more >
Foreach Loop not working - Microsoft Community Hub
Hello I am trying to get a foreach loop to work but when I run the script the way it is in the...
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