def ng2_call_component_function(self, element, func, params='', return_out=False):
"""
:Description: Will execute the component instance function with provided parameters.
:Warning: This will only work for Angular components.
:param element: Element for browser instance to target.
:param func: Function to execute from component instance.
:type func: string
:param params: String (naked) args, or list of parameters to pass to target function.
:type params: string, tuple, list
:param return_out: Return output of function call otherwise None
:type return_out: bool
"""
if isinstance(params, string_types):
param_str = params
elif isinstance(params, (tuple, list)):
param_str = self.__serialize_params(params)
else:
raise ValueError('Invalid type specified for function parameters')
exec_str = 'ng.probe(arguments[0]).componentInstance.%s(%s);' % (func, param_str)
if return_out:
return self.__type2python(
self.browser.execute_script('return {}'.format(exec_str), element))
else:
self.browser.execute_script(exec_str, element)
评论列表
文章目录