Before hook in java

package simulations;

import api.CustomHeaders;
import api.StandardHeader;
import api.URLs;
import helper.IdentityHelper;
import helpers.ConfigProvider;
import helpers.Device;

import io.gatling.javaapi.core.FeederBuilder;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import models.Config;
import static io.gatling.javaapi.core.CoreDsl.csv;
import static io.gatling.javaapi.core.CoreDsl.rampUsers;
import io.gatling.javaapi.core.Simulation;
import static io.gatling.javaapi.http.HttpDsl.http;

public class FastLoginSimulation extends Simulation {

    FeederBuilder<String> feeder = csv("customer2.csv").queue();
    private Device device = new Device();
    private IdentityHelper identityHelper = new IdentityHelper();
    private String deviceId = "#{deviceId}";
    //private Config config = ConfigProvider.getConfig();
    private Config config;

    public void before() {
        //"Getting environment config");
        System.out.println("Simulation is about to start!");
        config = ConfigProvider.getConfig();

    HttpProtocolBuilder httpProtocol = http
            .header(CustomHeaders.DEVICE_ID, deviceId)
            .userAgentHeader("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 " +
                    "(KHTML, like Gecko) Chrome/ Mobile Safari/537.36")
            .header(StandardHeader.CONTENT_TYPE, "application/json");

    ScenarioBuilder scn = identityHelper.login("login", feeder, device);


Does the before hook initialize after HttpProtocolBuilder because when I run the above script it gives a null pointer because config object is null but if I remove before hook and initialize config directly at class level it works.

That’s the whole purpose of this before hook
The simulation is initialized but not yet started.


1 Like

But will before hook initialise before the simulation. Looks like before hook is not running before httpprotocol builder.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.