diff --git a/flybirds/core/plugin/event/step.py b/flybirds/core/plugin/event/step.py index 24ee6287..edbc8d11 100644 --- a/flybirds/core/plugin/event/step.py +++ b/flybirds/core/plugin/event/step.py @@ -6,6 +6,7 @@ from flybirds.core.global_context import GlobalContext from flybirds.utils import flybirds_log as log from flybirds.utils import launch_helper +import flybirds.core.global_resource as gr def step_init(context, step): @@ -36,12 +37,61 @@ def run(context, step): log.info(step) step_init(context, step) log.info(f"run step:{step.name}") + # # if there is a hook custom behavior, call the related function + # before_step_extend = launch_helper.get_hook_file("before_step_extend") + # if before_step_extend is not None: + # before_step_extend(context, step) + + +class OnUserBefore: # pylint: disable=too-few-public-methods + """ + before step + """ + + name = "OnUserBefore" + order = 50 + + @staticmethod + def can(context, step): + return True + + @staticmethod + def run(context, step): + """ + exe before step + """ # if there is a hook custom behavior, call the related function before_step_extend = launch_helper.get_hook_file("before_step_extend") if before_step_extend is not None: before_step_extend(context, step) +class OnWebBefore: # pylint: disable=too-few-public-methods + """ + before step + """ + + name = "OnWebBefore" + order = 15 + + @staticmethod + def can(context, step): + if gr.get_platform() is not None \ + and (gr.get_platform().lower() == "web"): + return True + else: + return False + + @staticmethod + def run(context, step): + """ + exe before step + """ + if hasattr(GlobalContext, "get_global_cache"): + if GlobalContext.get_global_cache("web_console") is not None: + GlobalContext.set_global_cache("web_console", None) + + class OnAfter: # pylint: disable=too-few-public-methods """ after step @@ -67,4 +117,6 @@ def run(context, step): # join step event to global processor var = GlobalContext.join("before_step_processor", OnBefore, 1) +var4 = GlobalContext.join("before_step_processor", OnUserBefore, 1) + var1 = GlobalContext.join("after_step_processor", OnAfter, 1) diff --git a/flybirds/core/plugin/plugins/default/web/page.py b/flybirds/core/plugin/plugins/default/web/page.py index b5555ce1..3f961ecf 100644 --- a/flybirds/core/plugin/plugins/default/web/page.py +++ b/flybirds/core/plugin/plugins/default/web/page.py @@ -41,6 +41,7 @@ def init_page(): page.route("**/*", handle_route) # request listening events page.on("request", handle_request) + page.on("console", handle_page_error) ele_wait_time = gr.get_frame_config_value("wait_ele_timeout", 30) page_render_timeout = gr.get_frame_config_value("page_render_timeout", @@ -109,6 +110,18 @@ def cur_page_equal(self, context, param): verify_helper.text_equal(target_url, cur_url) +def handle_page_error(msg): + if hasattr(msg, "type") and msg.type is not None: + need_log = False + if msg.type.lower() == "warn": + need_log = True + if msg.type.lower() == "error": + need_log = True + if need_log: + if hasattr(msg, "text"): + log.info(f"=====================page console==================:\n {msg.text}") + + def handle_request(request): # interception request handle parsed_uri = urlparse(request.url) diff --git a/flybirds/template/pscript/custom_handle/operation.py b/flybirds/template/pscript/custom_handle/operation.py index ac4d79cc..5606e3ee 100644 --- a/flybirds/template/pscript/custom_handle/operation.py +++ b/flybirds/template/pscript/custom_handle/operation.py @@ -127,3 +127,9 @@ def get_page_url(param): """ pass + +def get_global_value(v): + """ + replace with global cache + """ + pass diff --git a/flybirds/utils/dsl_helper.py b/flybirds/utils/dsl_helper.py index 4745459c..e82dc652 100644 --- a/flybirds/utils/dsl_helper.py +++ b/flybirds/utils/dsl_helper.py @@ -170,8 +170,31 @@ def wrapper_func(*args, **kwargs): ele_key = v.split(',')[0] ele_value = gr.get_ele_locator(ele_key) v = selector_str.replace(ele_key, ele_value, 1) + new_v = get_global_value(v) + if new_v is not None: + v = new_v kwargs[k] = v func(*args, **kwargs) # Do something after the function. return wrapper_func + + +def get_global_value(v): + projectScript = gr.get_value("projectScript") + if projectScript is not None: + if hasattr(projectScript, "custom_operation"): + custom_operation = projectScript.custom_operation + if custom_operation is not None and hasattr(custom_operation, + "get_global_value"): + rp = custom_operation.get_global_value(v) + if rp is not None: + return rp + elif hasattr(projectScript, "app_operation"): + app_operation = projectScript.app_operation + if app_operation is not None and hasattr(app_operation, + "get_global_value"): + rp = app_operation.get_global_value(v) + if rp is not None: + return rp + return None