helper¶
-
appian_locust.helper.
_validate_component_found
(component: Optional[Dict[str, Any]], label: str, type: Optional[str] = None) → None¶
-
appian_locust.helper.
_validate_component_found_by_attribute
(component: Dict[str, Any], attribute: str, value_for_attribute: str) → None¶
-
appian_locust.helper.
_validate_component_found_by_index
(component: Optional[Dict[str, Any]], index: int, type: Optional[str] = None) → None¶
-
appian_locust.helper.
extract
(obj: Any, key: str, vals: List[Any]) → Generator¶ Recursively search for values of key in JSON tree.
-
appian_locust.helper.
extract_all_by_label
(obj: Union[dict, list], label: str) → list¶ Recursively search for all fields with a matching label in JSON tree.
-
appian_locust.helper.
extract_item_by_label
(obj: Union[dict, list], label: str) → Generator¶ Recursively search for all fields with a matching label in JSON tree. And return as a generator
-
appian_locust.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.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.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.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.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.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.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. –
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.helper.
format_label
(label: str, delimiter: str = 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.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.helper.
get_username
(auth: list) → str¶
-
appian_locust.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.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