Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
963dc1e
added builtinfunctions for performance testing
Sakib75 Jun 12, 2022
8da2349
added perfomance module in sequential action
Sakib75 Jun 12, 2022
f1bdc56
added actions for locust
Sakib75 Jun 12, 2022
82a6053
removed type on builtinfunc
Sakib75 Jun 12, 2022
9e74620
reverted back the unintentional changes
Sakib75 Jun 13, 2022
208e81c
left right
Sakib75 Jun 13, 2022
e1ca9fc
standalone script for converting server json to locust json
Sakib75 Jun 13, 2022
9e90236
logic changed for searching locust config in aciton
Sakib75 Jun 13, 2022
29fc775
updated the filepath of sample json
Sakib75 Jun 13, 2022
90f94f8
formatted output json
Sakib75 Jun 13, 2022
8c6fdcd
read data from testcase json
Sakib75 Jun 13, 2022
e4e8927
function name updated, output path added
Sakib75 Jun 14, 2022
08aba64
changed locust user 'user name' to 'name'
Sakib75 Jun 14, 2022
091e102
Refactor and update assign_locust_user
Oytizzo Jun 14, 2022
cc18ff8
updated dataset reading logic
Sakib75 Jun 14, 2022
fbbc13c
docs updated
Sakib75 Jun 14, 2022
794259e
username/classname to case-sensitive, user type to HttpUser and User
Sakib75 Jun 15, 2022
ae2af1e
Move and update packages for perf
Oytizzo Jun 15, 2022
6898c4a
added optional parameter sequential and weight
Sakib75 Jun 15, 2022
4e54852
Merge branch 'performance_testing' of https://github.com/AutomationSo…
Sakib75 Jun 15, 2022
7579882
username to user name and removed sequential from user
Sakib75 Jun 16, 2022
db62a94
removed sequential from user
Sakib75 Jun 16, 2022
c225d9a
updated user with new format
Sakib75 Jun 16, 2022
6ebfea3
added taskset action
Sakib75 Jun 16, 2022
59a4354
reverted setting.conf
Sakib75 Jun 16, 2022
7291f47
Add dir for storing generated locust files
Oytizzo Jun 16, 2022
1b28482
Add the initial code for run_performance_test action
Oytizzo Jun 16, 2022
fb28408
fixed the mentioned issues
Sakib75 Jun 19, 2022
2ceb940
Add functionality for generating locust python file
Oytizzo Jun 19, 2022
55a55c9
Bugfix
Oytizzo Jun 19, 2022
8ebcaf0
Remove duplicate line
Oytizzo Jun 19, 2022
7872c83
Update generate_performance_testing action
Oytizzo Jun 20, 2022
580b4cd
Add and update run_performance_test
Oytizzo Jun 20, 2022
60bcf7c
Executed the run_performance_test with subprocess
Oytizzo Jun 20, 2022
f391176
Update run, generate locust and add settings for keeping the track of…
Oytizzo Jun 30, 2022
64f54d8
resolved subprocess issue and run_perf update
Oytizzo Jun 30, 2022
9cafa50
Save report to AutomationLog dir
Oytizzo Jun 30, 2022
b9b8398
Update settings.py for report dirs
Oytizzo Jul 1, 2022
667e642
Update path for html report
Oytizzo Jul 1, 2022
28bc15b
update and remove print_exc
Oytizzo Jul 4, 2022
f6b0755
Revert settings.conf
Oytizzo Jul 4, 2022
66e3729
Add csv file generator and update the file name with run_id
Oytizzo Jul 6, 2022
f9ecfde
refactor and remove redundant codes
Oytizzo Jul 6, 2022
33fdca1
Add documentation
Oytizzo Jul 6, 2022
8d3a2a7
Merge branch 'dev' of https://github.com/AutomationSolutionz/Zeuz_Pyt…
Oytizzo Jul 8, 2022
c970cb3
Delete unused code from tests dir in Performance_Testing
Oytizzo Jul 8, 2022
c643b27
Modify CHANGELOG and version, delete generated codes
Oytizzo Jul 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions Framework/Built_In_Automation/Performance_Testing/BuiltInFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
from Framework.Utilities.decorators import logger, deprecated
import inspect,sys,random
from Framework.Utilities import CommonUtil, ConfigModule
import traceback
global sr
from Framework.Built_In_Automation.Shared_Resources import BuiltInFunctionSharedResources as sr

MODULE_NAME = inspect.getmodulename(__file__)

@logger
def locust_config(data_set):
"""
Save locust configuration to a variable
Args:
data_set:
swarm | input parameter | integer
spawn | input parameter | integer
locust config | performance action | variable_name

Returns:
"passed" if success.
"zeuz_failed" otherwise.
"""

sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME

try:
locust_var = losust_var_name = swarm = spawn = None
try:
for left, mid, right in data_set:
left = left.strip().lower()
if mid.strip().lower() == "input parameter":
if "swarm" == left:
swarm = float(right.strip().lower())
elif "spawn" == left:
spawn = float(right.strip().lower())
elif "action" == mid.strip().lower():
if "locust config" == left:
losust_var_name = right.strip()
if None in [losust_var_name,swarm,spawn]:
CommonUtil.ExecLog(sModuleInfo, f"dataset is inaccurate", 3)
return "zeuz_failed"
locust_var = {
"locust_config": {
"swarm": swarm,
"spawn": spawn
},
"users": {}
}
except:
CommonUtil.ExecLog(sModuleInfo, "Failed to parse data.", 1)
traceback.print_exc()
return "zeuz_failed"
sr.Set_Shared_Variables(losust_var_name, locust_var)
return "passed"
except:
return CommonUtil.Exception_Handler(sys.exc_info())


@logger
def assign_locust_user(data_set):
"""
Add Locust user configuration to the existing locust variable
This action provides that data to creates a user class into locust file
Args:
data_set:
wait_time | input parameter | between(int,int)
host | input parameter | url of host
name | input parameter | user/class name Case sensitive
type | input parameter | type of user/class
assign locust user | performance action | existing locust variable name
Returns:
"passed" if success.
"zeuz_failed" otherwise.
"""

sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME

try:
locust_var = losust_var_name = name = user_type = wait_time = host = None
try:
for left, mid, right in data_set:
left = left.strip().lower()
if mid.strip().lower() == "input parameter":
if "name" == left:
name = right.strip()
if "type" == left:
user_type = right.strip().lower()
user_type = 'HttpUser' if user_type == 'httpuser' else "User" if user_type == "user" else None
elif "wait_time" == left:
wait_time = right.strip().lower()
elif "host" == left:
host = right.strip().lower()
elif mid.strip().lower() == "action":
if "assign locust user" == left:
losust_var_name = right.strip()
if None in [losust_var_name,name,user_type,wait_time,host]:
CommonUtil.ExecLog(sModuleInfo, f"dataset is inaccurate", 3)
return "zeuz_failed"
locust_var = sr.Get_Shared_Variables(losust_var_name,log=False)
locust_var['users'][name] = {'type':user_type,'wait_time' : wait_time,'host':host,'tasks':[]}
except:
CommonUtil.ExecLog(sModuleInfo, "Failed to parse data.", 1)
traceback.print_exc()
return "zeuz_failed"
sr.Set_Shared_Variables(losust_var_name, locust_var)
return "passed"
except:
return CommonUtil.Exception_Handler(sys.exc_info())

@logger
def assign_locust_task(data_set):
"""
Add task configuration to the existing locust user
This action provides that data to define the tasks performed by locust user/class
Args:
data_set:
action | input parameter | get/post etc
data | input parameter | url of endpoint
task name | input parameter | string
name | input parameter | existing user/class name Case sensitive
assign locust task | performance action | existing locust variable name
Returns:
"passed" if success.
"zeuz_failed" otherwise.
"""

sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME

try:
locust_var = locust_var_name = action = data = name = task_name = None
try:
for left, mid, right in data_set:
left = left.strip().lower()
if mid.strip().lower() == "input parameter":
if "action" == left.strip():
action = right.strip().lower()
elif "data" == left.strip():
data = right.strip().lower()
elif "name" == left.strip():
name = right.strip()
elif "task name" == left:
task_name = right.strip().lower()
elif mid.strip().lower() == "action":
if "assign locust task" == left:
locust_var_name = right.strip()
if None in [locust_var_name,action,data,name,task_name]:
CommonUtil.ExecLog(sModuleInfo, f"dataset is inaccurate", 3)
return "zeuz_failed"
locust_var = sr.Get_Shared_Variables(locust_var_name,log=False)
locust_var['users'][name]['tasks'].append({'action':action,'data':data,'name':task_name})
except:
CommonUtil.ExecLog(sModuleInfo, "Failed to parse data.", 1)
traceback.print_exc()
return "zeuz_failed"
sr.Set_Shared_Variables(locust_var_name, locust_var)
return "passed"
except:
return CommonUtil.Exception_Handler(sys.exc_info())
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import json
import pprint

# Check if action is disabled
def check_if_disabled(action):
if action.get('action_disabled') == 'false':
return True
else:
return False
# Check if the action is a locust action
def selected_locust_action(action):
all_locust_actions = ['locust config','assign locust user','assign locust task']
locust_actions = [ac[0] for ac in action['Action data'] if ac[0] in all_locust_actions]
if(locust_actions):
return locust_actions[0]
else:
return False

# Get the values for the action paramteres
def get_values(step_actions,action_val_map):
data = dict()
for sa in step_actions:
variable_name = action_val_map.get(sa[0])
if(variable_name):
variable_value = sa[2]
data[variable_name] = variable_value
return data

def convert_json(input_json_file_path,output_json_file_path):
input_json_file_path = os.path.dirname(os.path.realpath(__file__)) + '/' + input_json_file_path
output_json_file_path = os.path.dirname(os.path.realpath(__file__)) + '/' + output_json_file_path
input_json_data = json.load(open(input_json_file_path))
testcase = input_json_data["TestCases"]
steps = testcase[0]["Steps"]
actions = []
for step in steps:
actions = actions + step["Step actions"]
all_locusts = dict()
for action in actions:
locust_action = selected_locust_action(action)
if(check_if_disabled(action) == False and locust_action):
step_actions = action['Action data']
if(locust_action == 'locust config'):
params = get_values(step_actions,{'swarm':'swarm','spawn':'spawn','locust config':'variable_name'})
all_locusts[params['variable_name']] = ({"locust_config": {"swarm": params['swarm'],"spawn": params['spawn']},"users": {}})
if(locust_action == 'assign locust user'):
params = get_values(step_actions,{'type':'type','name':'name','host':'host','wait_time':'wait_time','assign locust user':'variable_name'})
all_locusts[params['variable_name']]['users'][params['name']] = {'type':params['type'],'wait_time' : params['wait_time'],'host':params['host'],'tasks':[]}

if(locust_action == 'assign locust task'):
params = get_values(step_actions,{'action':'http_method','data':'data','name':'name','assign locust task':'variable_name'})
all_locusts[params['variable_name']]['users'][params['name']]['tasks'].append({'action': 'client.' + params['http_method'],'data':params['data'],'name':params['name']})

pprint.pprint(all_locusts)

with open(output_json_file_path, "w") as outfile:
json.dump(all_locusts,outfile,indent=4 )

import os
if __name__ == '__main__':
convert_json(input_json_file_path="sample2.json", output_json_file_path="sample_zeuz_json.json")
143 changes: 143 additions & 0 deletions Framework/Built_In_Automation/Performance_Testing/tests/sample1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
[
{
"action_name": "Locust config",
"action_disabled": "true",
"step_actions": [
[
"swarm",
"input parameter",
"10"
],
[
"spawn",
"input parameter",
"100"
],
[
"locust config",
"performance action",
"PERF_VARIABLE"
]
]
},
{
"action_name": "Define user",
"action_disabled": "true",
"step_actions": [
[
"type",
"input parameter",
"HttpUser"
],
[
"name",
"input parameter",
"WebsiteUser"
],
[
"host",
"input parameter",
"https://xyz.com"
],
[
"wait_time",
"input parameter",
"between(5, 15)"
],
[
"assign locust user",
"performance action",
"PERF_VARIABLE"
]
]
},
{
"action_name": "Define task",
"action_disabled": "true",
"step_actions": [
[
"action",
"input parameter",
"get"
],
[
"data",
"input parameter",
"/"
],
[
"name",
"input parameter",
"WebsiteUser"
],
[
"assign locust task",
"performance action",
"PERF_VARIABLE"
]
]
},
{
"action_name": "Define task",
"action_disabled": "true",
"step_actions": [
[
"action",
"input parameter",
"get"
],
[
"data",
"input parameter",
"/static/assets.js"
],
[
"name",
"input parameter",
"WebsiteUser"
],
[
"assign locust task",
"performance action",
"PERF_VARIABLE"
]
]
},
{
"action_name": "Define task",
"action_disabled": "true",
"step_actions": [
[
"action",
"input parameter",
"post"
],
[
"data",
"input parameter",
"/submit/form"
],
[
"name",
"input parameter",
"WebsiteUser"
],
[
"assign locust task",
"performance action",
"PERF_VARIABLE"
]
]
},
{
"action_name": "Generate locust python file + run locust file",
"action_disabled": "true",
"step_actions": [
[
"run performance test",
"performance action",
"PERF_VARIABLE"
]
]
}
]
Loading