mardi 22 septembre 2020

Locust multiple users login

I want to allow my locust application to login with more than one user account.

I've tried random.shuffle(), but it's still only one account.

Here is the code:

from locust import HttpUser, task, TaskSet, between, exception, events
import logging
import random

paths_in_dict = {"hard_path": "secure/izar.xhtml/",
                 "standard_analysis_path": "analysis/STANDARD/",
                 "smart_analysis_path": "analysis/SMART/"}
passwd = 'radio'
logins = [
    'aaa', 'bbb', 'ccc', 'ddd', 'eee'
]
random.shuffle(logins)
login_pass = [(elem, passwd) for elem in logins]

if len(login_pass) > 0:
    user, passwd = login_pass.pop()
    default_headers = {'X-Username': user, 'X-Password': passwd}


class MyUser(HttpUser):
    wait_time = between(5, 9)
    host = "https://localhost:9003/"

    def on_start(self):
        self.client.verify = False
        self.login()

    def on_stop(self):
        pass

    def login(self):
        self.client.request(method="POST", url="login.xhtml", headers=default_headers,
                            name="---ON START---LOGIN")
        logging.info('Login with %s username and %s password', user, passwd)

# ----------------------------------MAIN LINKS/DROPDOWNS----------------------------------------------
    @task
    def dashboard(self):
        dashboard_get_response = self.client.get(paths_in_dict["hard_path"] + "dashboard", name="Dashboard")
        return dashboard_get_response

How to make it works with all of the elements from logins list?




Aucun commentaire:

Enregistrer un commentaire