helper

appian_locust.helper._find_component_by_type_and_index(type_name: str, index: int, component: Any, count: int) → Any
appian_locust.helper.extract(obj: Any, key: str, val: 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.

  • value (any) – value, which can be any type

Returns

list of matched key-value pairs

appian_locust.helper.find_component_by_attribute_in_dict(attribute: str, value: str, component_tree: Dict[str, Any]) → 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 returns None when not found

Parameters
  • attribute – an attribute to search (‘label’ for example)

  • value – the value of the attribute (‘Submit’ for example)

  • component_tree – the json response.

Returns

the json object of the component or None if none is 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 returns the total number of components with that attribute when the index could not be matched

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 or the count of matching attributes if no match 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]) → 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 returns None when not 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.

Returns

the json object of the component or None if none is found

Example

>>> find_component_by_label_and_type_dict('label', 'MyLabel', 'StartProcessLink', self.json_response)
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