skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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 :)


  2. 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";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search