I have to take unique value for each users in csv for each iteration. Will you prefer any suggestions it would be better for my next process...
Asked
Active
Viewed 309 times
-1
-
It is really unclear what you are asking. Can you please try to make it more concise/clear and possibly include an example? – fhorrobin Jan 17 '22 at 06:35
-
I have to take different value from each user for example. In CSV Account name prabha1, prabha2 ,. 2 users have to take unique values not same value – Prabhakaran D Jan 18 '22 at 07:03
1 Answers
0
Something like:
from locust import HttpLocust, TaskSet, task
import logging, sys
import csv
USER_CREDENTIALS = None
class LoginWithUniqueUsersSteps(TaskSet):
email = "NOT_FOUND"
password = "NOT_FOUND"
def on_start(self):
if len(USER_CREDENTIALS) > 0:
self.email, self.password = USER_CREDENTIALS.pop()
@task
def login(self):
self.client.post("/login", {
'email': self.email, 'password': self.password
})
logging.info('Login with %s email and %s password', self.email, self.password)
class LoginWithUniqueUsersTest(HttpLocust):
task_set = LoginWithUniqueUsersSteps
host = "http://blazedemo.com"
sock = None
def __init__(self):
super(LoginWithUniqueUsersTest, self).__init__()
global USER_CREDENTIALS
if (USER_CREDENTIALS == None):
with open('credentials.csv', 'rb') as f:
reader = csv.reader(f)
USER_CREDENTIALS = list(reader)
should do the trick for you.
More information:

Dmitri T
- 159,985
- 5
- 83
- 133
-
I have to take different value from each user for example. In CSV Account name prabha1, prabha2 ,. 2 users have to take unique values not same value, if you give clear csvreader it is very helpful for me – Prabhakaran D Feb 01 '22 at 09:54