Utilities module
- appian_locust.utilities.credentials.procedurally_generate_credentials(CONFIG: dict) None
Helper method that can be used to procedurally generate a set of Appian user credentials
Note: This class must be called in the UserActor class of your Locust test in order to create the credentials before any Locust users begin to pick them up.
- Parameters:
CONFIG – full locust config dictionary, AKA the utls.c variable in locust tests Make sure the following keys are present.
procedural_credentials_prefix – Base string for each generated username
procedural_credentials_count – Appended to prefix, will create 1 -> Count+1 users
procedural_credentials_password – String which will serve as the password for all users
- Returns:
None
- appian_locust.utilities.credentials.setup_distributed_creds(CONFIG: dict) dict
Helper method to distribute Appian credentials across separate load drivers when running Locust in distributed mode. Credential pairs will be passed out in Round Robin fashion to each load driver.
Note: This class must be called in the UserActor class of your Locust test to ensure that the “credentials” key is prepared before tests begin.
Note: If fewer credential pairs are provided than workers, credentials will be distributed to workers in a Modulo fashion.
- Parameters:
CONFIG – full locust config dictionary, AKA the utls.c variable in locust tests Make sure the following keys are present.
- Returns:
same as input but with credentials key updated to just the subset of credentials required for given load driver.
- Return type:
CONFIG
- appian_locust.utilities.helper.extract_all_by_label(obj: dict | list, label: str) list
Recursively search for all fields with a matching label in JSON tree. :param obj: The json tree to search for fields in :param label: The label used to identify elements we want to return
Returns (list): A list of all elements in obj that match label
- appian_locust.utilities.helper.extract_values(obj: Dict[str, Any], key: str, val: Any) List[Dict[str, Any]]
Pull all values of specified key from nested JSON.
- Parameters:
obj (dict) – Dictionary to be searched
key (str) – tuple of key and value.
val (any) – value, which can be any type
- Returns:
list of matched key-value pairs
- appian_locust.utilities.helper.extract_values_multiple_key_values(obj: Dict[str, Any], key: str, vals: List[Any]) List[Dict[str, Any]]
Pull all values where the key value matches an entry in vals from nested JSON.
- Parameters:
obj (dict) – Dictionary to be searched
key (str) – a key in the dictionary
vals (List[any]) – A list of values corresponding to the key, which can be any type
- Returns:
list of matched key-value pairs
- appian_locust.utilities.helper.find_component_by_attribute_and_index_in_dict(attribute: str, value: str, index: int, component_tree: Dict[str, Any]) Any
Find a UI component by the given attribute (label for example) in a dictionary It returns the index’th match in a depth first search of the json tree It returns the dictionary that contains the given attribute with the given value or throws an error when none is found
- Parameters:
attribute – an attribute to search (‘label’ for example)
value – the value of the attribute (‘Submit’ for example)
index – the index of the component to find if multiple components are found with the same ‘value’ for ‘attribute’ (1 for example)
component_tree – the json response.
- Returns:
The json object of the component
- Raises:
ComponentNotFoundException if the component cannot be found. –
Example
>>> find_component_by_attribute_and_index_in_dict('label', 'Submit', 1, self.json_response)
will search the json response to find the first component that has ‘Submit’ as the label
- appian_locust.utilities.helper.find_component_by_attribute_in_dict(attribute: str, value: str, component_tree: Dict[str, Any], raise_error: bool = True, throw_attribute_exception: bool = False) Any
Find a UI component by the given attribute (label for example) in a dictionary It only returns the first match in a depth first search of the json tree It returns the dictionary that contains the given attribute with the given value or throws an error when none is found.
- Parameters:
attribute – an attribute to search (‘label’ for example)
value – the value of the attribute (‘Submit’ for example)
component_tree – the json response.
raise_error – If set to False, will return None instead of raising an error. (Default: True)
throw_attribute_exception – If set to False then if the component is not found an exception is thrown using the attribute and value in the exception.
- Returns:
The json object of the component
- Raises:
ComponentNotFoundException if the component cannot be found. –
Example
>>> find_component_by_attribute_in_dict('label', 'Submit', self.json_response)
will search the json response to find a component that has ‘Submit’ as the label
- appian_locust.utilities.helper.find_component_by_index_in_dict(component_type: str, index: int, component_tree: Dict[str, Any]) Any
Find a UI component by the index of a given type of component (“RadioButtonField” for example) in a dictionary Performs a depth first search and counts quantity of the component, so the 1st is the first one It returns the dictionary that contains the given attribute with the requested index or throws an error when none is found.
- Parameters:
component_type – type of the component(#t in the JSON response, ‘RadioButtonField’ for example)
index – the index of the component with the component_type (‘1’ for example - Indices start from 1)
component_tree – the json response
- Returns:
The json object of the component
- Raises:
ComponentNotFoundException if the component cannot be found. –
Example
>>> find_component_by_index_in_dict('RadioButtonField', 1, self.json_response)
will search the json response to find the first component that has ‘RadioButtonField’ as the type
- appian_locust.utilities.helper.find_component_by_label_and_type_dict(attribute: str, value: str, type: str, component_tree: Dict[str, Any], raise_error: bool = True) Any
Find a UI component by the given attribute (like label) in a dictionary, and the type of the component as well. (#t should match the type value passed in) It only returns the first match in a depth first search of the json tree. It returns the dictionary that contains the given attribute with the given label and type or throws an error when none is found if the raise_error value is True. Otherwise it will return None if the component cannot be found.
- Parameters:
label – label of the component to search
value – the value of the label
type – Type of the component (TextField, StartProcessLink etc.)
component_tree – the json response.
raise_error – If set to False, will return None instead of raising an error. (Default: True)
- Returns:
The json object of the component or None if the component cannot be found.
- Raises:
ComponentNotFoundException if the component cannot be found. –
Example
>>> find_component_by_label_and_type_dict('label', 'MyLabel', 'StartProcessLink', self.json_response)
- appian_locust.utilities.helper.find_component_by_type_and_attribute_and_index_in_dict(component_tree: Dict[str, Any], type: str = '', attribute: str = '', value: str = '', index: int = 1, raise_error: bool = True) Any
Find a UI component by the given type and/or attribute with ‘value’ in a dictionary Returns the index’th match in a depth first search of the json tree Returns the dictionary that contains the given attribute with the given value or throws an error when none is found Note: Both type and attribute matching are optional, which will cause this function to return the index’th component in the tree
- Parameters:
component_tree – the json response
- Keyword Arguments:
type (str) – the component type to match against (default: ‘’)
attribute (str) – an attribute to search (default: ‘’)
value (str) – the value of the attribute (default: ‘’)
index (int) – the index of the component to find if multiple components match the above criteria, 1-indexed (default: 1)
raise_error (bool) – if this is set to false, it will return None instead of raising an error.
- Returns:
The json object of the component or None if ‘raise_error’ is set to false.
- Raises:
ComponentNotFoundException if the attribute or type checks fail. –
Exception if the component is found but at an incorrect index. –
Example
>>> find_component_by_attribute_and_index_in_dict('label', 'Submit', 1, self.json_response)
will search the json response to find the first component that has ‘Submit’ as the label
- appian_locust.utilities.helper.format_label(label: str, delimiter: str | None = None, index: int = 0) str
Simply formats the string by replacing a space with underscores
- Parameters:
label – string to be formatted
delimiter – If provided, string will be split by it
index – used with delimiter parameter, which item will be used in the “split”ed list.
- Returns:
formatted string
- appian_locust.utilities.helper.get_random_item(list_of_items: List[Any], exclude: List[Any] = []) Any
Gets a random item from the given list excluding the items if any provided
- Parameters:
list_of_items – list of items of any data type
exclude – if any items needs to be excluded in random pick
- Returns:
Randomly picked Item
- Raises:
In case of no item to pick, Exception will be raised –
- appian_locust.utilities.helper.get_username(auth: list) str
Returns the username from an auth list :param auth: Appian Locust authorization list
Returns (str): Username from auth list
- appian_locust.utilities.helper.list_filter(list_var: List[str], filter_string: str, exact_match: bool = False) List[str]
from the given list, return the list with filtered values.
- Parameters:
list_var (list) – list of strings
filter_string (str) – string which will be used to filter
exact_match (bool, optional) – filter should be based on exact match or partial match. default is partial.
- Returns:
List with filtered values
- appian_locust.utilities.helper.remove_type_info(sail_dict: Dict[str, Any]) Dict[str, Any]
Returns a flattened dictionary with SAIL type info removed :param sail_dict: SAIL Dictionary to remove type information from
Returns (dict): Flattened dictionary
- appian_locust.utilities.helper.repeat(num_times: int = 2, wait_time: float = 0.0) Callable
This function allows an arbitrary function to be executed an arbitrary number of times The intended use is as a decorator:
>>> @repeat(2) ... def arbitrary_function(): ... print("Hello World") ... arbitrary_function() Hello World Hello World
- Parameters:
num_times (int) – an integer
- Implicit Args:
arbitrary_function (Callable): a python function
- Returns:
A reference to a function which performs the decorated function num_times times
- class appian_locust.utilities.loadDriverUtils.loadDriverUtils
Bases:
object
- load_config(config_file: str = './config.json') dict
Load a json configuration file into a dictionary :param config_file: Location where config file can be found
- Returns (dict): Dictionary containing configuration. Will also be stored in
loadDriverUtils.c
- appian_locust.utilities.logger.getLogger(name: str | None = None) Logger
- Parameters:
name (str, optional) – Name of the logger. it is common practice to use file name here but it can be anything.
Returns: logger object