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
Out of curiosity, does the same thing happen if you convert your yaml file to JSON and run that? (You can convert it with npm run artillery convert ./specs/yourFile.yml)
I only ask because the indentation looks a bit off in the yml you shared, and JSON doesn't care about indentation
@ericmacfarland Here is the yml converted to json
{
"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 }}"
}
]
}
@3lb3njy
I'll take a look, in the mean time, did you receive the same error when you run Artillery with that JSON file?
@ericmacfarland yes I got the same error with the json.
@ericmacfarland the error was in the "Log" tag, it was a wrong indentation.
I got the same Error, testing my echo websocket.
# usage:
# artillery run ws_test.yml
config:
target: 'ws://localhost:4000'
phases:
- duration: 20
arrivalRate: 10
ws:
# Set a custom subprotocol:
# subprotocols:
# - json
# - soap
scenarios:
- engine: "ws"
flow:
- send: "test"
Error:
script.scenarios.forEach(function(scenario) {
^
TypeError: Cannot read property 'forEach' of undefined
at checkIfXPathIsUsed (C:\Users\Steffie\AppData\Roaming\npm\node_modules\artillery\lib\commands\run.js:315:20)
at fn (C:\Users\Steffie\AppData\Roaming\npm\node_modules\artillery\node_modules\async\lib\async.js:746:34)
at C:\Users\Steffie\AppData\Roaming\npm\node_modules\artillery\node_modules\async\lib\async.js:1213:16
at C:\Users\Steffie\AppData\Roaming\npm\node_modules\artillery\node_modules\async\lib\async.js:166:37
at C:\Users\Steffie\AppData\Roaming\npm\node_modules\artillery\node_modules\async\lib\async.js:706:43
at C:\Users\Steffie\AppData\Roaming\npm\node_modules\artillery\node_modules\async\lib\async.js:167:37
at Immediate.<anonymous> (C:\Users\Steffie\AppData\Roaming\npm\node_modules\artillery\node_modules\async\lib\async.js:1206:34)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
scenarios should be at the top level (same as config)
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
Most helpful comment
scenariosshould be at the top level (same asconfig)