My Website creates token for every user. How can I assign unique access token dynamically

I have website that assign token to every user. in my script the access token get over ridden once other user uses the token url.
Please guide for a solution using chainbuilder if possible.

Hi @agandhi,

I’m not sure to understand your requirements or how your website works.

Common patterns involve that each virtual user will have a login/password to authenticate against the website and then used the provided token for following requests.

In that scenario, you can create a csv file with a lot of login/password pair in your system under test and use it as a feeder in your scenario.

login,password
user1,password1
user2,password2

Then, your scenario (the description for one virtual user) will call the login, save the provided token in a session variable then use this token in each request.

    FeederBuilder<String> feeder = csv("users.csv");

    ActionBuilder login = http("login")
            .post("/login")
            .formParam("login", "#{login}") // from feeder
            .formParam("password", "#{password}") // from feeder
            .check(
                    header("X-Token").saveAs("token") // save the content of X-Token header in session variable named "token"
            );

    ActionBuilder privatePage = http("private page")
            .get("/private/page")
            .header("Token", "#{token}") // use the "token" session variable
            .check(bodyString().find());

    ScenarioBuilder scn =
            scenario("With login")
                    .feed(feeder) // each virtual user will read 1 line of your file
                    .exec(login)
                    .exec(privatePage)
            ;

Does it help?

Cheers!

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