0

Help, guys, I have been assigned to research gatling with javascript for performance testing, but I am quite junior and struggling to even make a login request from a project.

This is the documentation: https://docs.gatling.io/reference/script/protocols/http/request/#request-name
There is also a nice video by a guy here, that I used for a double check, if I missed some prerequisite: https://www.youtube.com/watch?v=s4WeRrCAk-8

So far this is the solution I am coming up with:

import { atOnceUsers, scenario, simulation } from "@gatling.io/core";
import { http, status, StringBody } from "@gatling.io/http";
export default simulation((setUp) => {
 const httpProtocol = 
 http.baseUrl('https://example.test.com')
 .acceptHeader('*/*')
 .contentTypeHeader('application/json');
 const loginAndLogout = scenario('Login and logout')
 .exec(http('Login').post('/login')
 .body(StringBody("{ \"username\": \"testUser\", \"password\": \"testPass\", \"channel\": \"web\" }"))
 .check(status().is(200)) // Check for a 200 OK response
);
 setUp(loginAndLogout.injectOpen(atOnceUsers(1))).protocols(httpProtocol);
});

A simple get request is working, but a post request with a body is just not doing the job for me. I just get:

"[ERROR] i.g.a.Gatling$ - Run crashed org.graalvm.polyglot.PolyglotException: TypeError: undefined is not a function."

The error itself does not speak too much to me.

I have done previously a full project with "k6", but I am clueless here. Thanks.

asked Nov 7, 2024 at 10:02
1
  • The error itself does not speak too much to me. - how do you think we feel? we can't even tell what part of your code threw the error! Commented Nov 7, 2024 at 10:35

1 Answer 1

1

The error lies in the imports:

import { atOnceUsers, scenario, simulation } from "@gatling.io/core";
import { http, status, StringBody } from "@gatling.io/http";

StringBody needs to be imported from core, not http:

import { StringBody, atOnceUsers, scenario, simulation } from "@gatling.io/core";
import { http, status } from "@gatling.io/http";
answered Nov 7, 2024 at 11:04
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, I feel kind of silly now. But sometimes I guess we need a second set of eyes even for obvious things. The request has passed. Anyway, I guess this may serve as an example of a POST request to someone else checking the internet :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.