From bd0ca7fa53724385971907d3b7faec4645307896 Mon Sep 17 00:00:00 2001 From: SmithMMTK Date: Fri, 30 Oct 2020 21:14:59 +0700 Subject: [PATCH 1/3] Update credentials.csv --- .../credentials.csv | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/credentials.csv b/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/credentials.csv index 2fdf3eb..4258c87 100644 --- a/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/credentials.csv +++ b/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/credentials.csv @@ -1,5 +1,5 @@ -LocustPerformanceUser5@gmail.com,5678901 -LocustPerformanceUser4@gmail.com,456789 -LocustPerformanceUser3@gmail.com,345678 -LocustPerformanceUser2@gmail.com,234567 -LocustPerformanceUser1@gmail.com,123456 +081-xxx-2332,5678901 +081-xxx-8767,456789 +081-xxx-3412,345678 +081-xxx-1122,234567 +081-xxx-7383,123456 From bf3ae0db3659fc25cd61c060b5817003c0723113 Mon Sep 17 00:00:00 2001 From: SmithMMTK Date: Fri, 30 Oct 2020 21:15:17 +0700 Subject: [PATCH 2/3] Update LocustScriptWithCredentialsInSeparateCsvFile.py --- ...tScriptWithCredentialsInSeparateCsvFile.py | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/LocustScriptWithCredentialsInSeparateCsvFile.py b/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/LocustScriptWithCredentialsInSeparateCsvFile.py index 90c218e..8153074 100644 --- a/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/LocustScriptWithCredentialsInSeparateCsvFile.py +++ b/Locust script and external CSV file with users credentials/Option 3 - Users credentials in separate CSV file/LocustScriptWithCredentialsInSeparateCsvFile.py @@ -1,33 +1,40 @@ -from locust import HttpLocust, TaskSet, task +import time +import random import logging, sys import csv +from locust import HttpUser, TaskSet, task, between +# Global variable to load test data from 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() +class QuickstartUser(HttpUser): + wait_time = between(1, 2) + host = "http://www.microsoft.com" @task - def login(self): - self.client.post("/login", { - 'email': self.email, 'passowrd': 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 main_page(self): + self.client.get("/") + + # Check Mobile number to use for login + if (self.mobile == "NO_MORE_USER"): + print("NO MORE MOBILE") + else: + print("Mobile number: ", self.mobile, " otp: ", self.otp ) + self.stop() - def __init__(self): - super(LoginWithUniqueUsersTest, self).__init__() + def on_start(self): global USER_CREDENTIALS + + # Load test data from csv file if (USER_CREDENTIALS == None): - with open('credentials.csv', 'rb') as f: + print("open file") + with open('credentials.csv', 'r') as f: reader = csv.reader(f) USER_CREDENTIALS = list(reader) + + # Load top record from dataset and mark for processed + if len(USER_CREDENTIALS) > 0: + self.mobile, self.otp = USER_CREDENTIALS.pop() + else: + self.mobile = "NO_MORE_MOBILE" + self.otp = "N/A" From 246cefca38783313324e1aca7a0e46e786e1b17d Mon Sep 17 00:00:00 2001 From: SmithMMTK Date: Fri, 30 Oct 2020 21:16:14 +0700 Subject: [PATCH 3/3] Update LocustScripWithCredentialsInSeparatePythonFile.py --- ...cripWithCredentialsInSeparatePythonFile.py | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Locust script and external CSV file with users credentials/Option 2 - Users credentials in separate Python script/LocustScripWithCredentialsInSeparatePythonFile.py b/Locust script and external CSV file with users credentials/Option 2 - Users credentials in separate Python script/LocustScripWithCredentialsInSeparatePythonFile.py index 20d0c7a..1b5b96c 100644 --- a/Locust script and external CSV file with users credentials/Option 2 - Users credentials in separate Python script/LocustScripWithCredentialsInSeparatePythonFile.py +++ b/Locust script and external CSV file with users credentials/Option 2 - Users credentials in separate Python script/LocustScripWithCredentialsInSeparatePythonFile.py @@ -1,26 +1,23 @@ -from locust import HttpLocust, TaskSet, task -import logging, sys from credentials import * +from locust import HttpUser, TaskSet, task, between -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() +class QuickstartUser(HttpUser): + wait_time = between(1, 2) + host = "http://www.microsoft.com" @task - def login(self): - self.client.post("/login", { - 'email': self.email, 'passowrd': self.password - }) - logging.info('Login with %s email and %s password', self.email, self.password) + def main_page(self): + self.client.get("/") + #print("task created.") + + print("login by: ", self.email, " password: ", self.password ) + self.stop() -class LoginWithUniqueUsersTest(HttpLocust): - task_set = LoginWithUniqueUsersSteps - host = "http://blazedemo.com" - sock = None - def __init__(self): - super(LoginWithUniqueUsersTest, self).__init__() + def on_start(self): + #print("Job started") + if len(USER_CREDENTIALS) > 0: + self.email, self.password = USER_CREDENTIALS.pop() + else: + self.email = "NO_MORE_USER" + self.password = "N/A"