Gatling version: 3.13.2
Gatling flavor: javascript
Gatling build tool: maven gradle sbt bundle npm
My simulation works perfectly when retrieves only one key-value pair from .json/.csv file. But once I want to retrieve random value from .json/.csv file and add feeder - I receive error “undefined is not a function”.
My simulation with csv feeding:
import {
simulation,
scenario,
pause,
atOnceUsers,
AllowList,
DenyList,
StringBody,
jsonFeeder,
feed,
csv
} from "@gatling.io/core";
import {http, status} from "@gatling.io/http";
const credsFeeder = csv("../resources/creds.csv").random();
const httpProtocol = http
.baseUrl("https://qa.myproject.co")
.inferHtmlResources()
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
const headers_0 = {
"Content-Type": "application/json",
"Prefer": "timezone=Europe/Bratislava",
"sec-ch-ua": "Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "macOS"
};
const scn = scenario("loginSF")
.feed(credsFeeder)
.exec(
http("request_0")
.post("/api/authentication/auth/sign_in")
.headers(headers_0)
.body(
StringBody(`{
"login": "#{login}",
"password": "#{password}"
}`)
)
.check(status().is(200)) // Check if the login is successful
);
export default simulation((setUp) => {
setUp(scn.injectOpen(atOnceUsers(10))).protocols(httpProtocol);
});
My creds.csv:
login,password
log1,pas1
log2,pas2
My simulation with json feeding:
import { simulation, scenario, atOnceUsers, jsonFeeder } from "@gatling.io/core";
import { http, status } from "@gatling.io/http";
const httpProtocol = http
.baseUrl("https://qa.myproject.co")
.inferHtmlResources()
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
const headers_0 = {
"Content-Type": "application/json",
"Prefer": "timezone=Europe/Bratislava",
"sec-ch-ua": "Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "macOS",
};
const credsFeeder = jsonFeeder("../resources/creds.json").random();
const scn = scenario("loginSF")
.feed(credsFeeder)
.exec(
http("request_0")
.post("/api/authentication/auth/sign_in")
.headers(headers_0)
.body((session) => {
// Dynamically retrieve the login and password from the session
const login = session.get("login");
const password = session.get("password");
return JSON.stringify({
login: login,
password: password
});
})
.check(status().is(200))
);
export default simulation((setUp) => {
setUp(scn.injectOpen(atOnceUsers(100))).protocols(httpProtocol);
});
My creds.json:
[
{
"login": "log1",
"password": "pass1"
},
{
"login": "log1",
"password": "pass1"
}
]
Both options work fine when there is only one key-value pair in .csv file/.json file
Full error log:
Run crashed
org.graalvm.polyglot.PolyglotException: TypeError: undefined is not a function
at <js>.:=>(bundle.js:2893)
at <js>.:program(bundle.js:1)
at org.graalvm.polyglot.Context.eval(Context.java:402)
at io.gatling.js.JsSimulationHelper.loadSimulation(JsSimulationHelper.java:64)
at io.gatling.js.JsSimulation.<init>(JsSimulation.java:38)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
... 9 common frames omitted
Wrapped by: java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:501)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:485)
at io.gatling.app.SimulationClass$Java.params(SimulationClass.scala:47)
at io.gatling.app.Runner.load(Runner.scala:73)
at io.gatling.app.Runner.run(Runner.scala:58)
at io.gatling.app.Gatling$.start(Gatling.scala:83)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
at io.gatling.app.Gatling$.main(Gatling.scala:40)
at io.gatling.app.Gatling.main(Gatling.scala)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:501)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:485)
at io.gatling.app.SimulationClass$Java.params(SimulationClass.scala:47)
at io.gatling.app.Runner.load(Runner.scala:73)
at io.gatling.app.Runner.run(Runner.scala:58)
at io.gatling.app.Gatling$.start(Gatling.scala:83)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
at io.gatling.app.Gatling$.main(Gatling.scala:40)
at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: org.graalvm.polyglot.PolyglotException: TypeError: undefined is not a function
at <js>.:=>(bundle.js:2893)
at <js>.:program(bundle.js:1)
at org.graalvm.polyglot.Context.eval(Context.java:402)
at io.gatling.js.JsSimulationHelper.loadSimulation(JsSimulationHelper.java:64)
at io.gatling.js.JsSimulation.<init>(JsSimulation.java:38)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
... 9 more
/Users/anna/Documents/gatling-js/javascript/node_modules/@gatling.io/cli/target/java.js:33
reject(Error("Gatling process finished with code " + code));
^
Error: Gatling process finished with code 1
at ChildProcess.<anonymous> (/Users/anna/Documents/gatling-js/javascript/node_modules/@gatling.io/cli/target/java.js:33:24)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1101:16)
at ChildProcess._handle.onexit (node:internal/child_process:305:5)