From 7a8e72bb9e6f6deabaf9f7bad783fedc20c8f21a Mon Sep 17 00:00:00 2001 From: "yong.peng" Date: Fri, 18 Oct 2024 18:16:15 +0800 Subject: [PATCH 1/2] fix: Handling parameters with spaces and newlines in steps --- .../default/ui_driver/poco/poco_input.py | 38 ++++++++++++++++++- .../default/ui_driver/poco/poco_text.py | 4 +- flybirds/utils/dsl_helper.py | 18 ++++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_input.py b/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_input.py index f9ea4d07..7cdd317b 100644 --- a/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_input.py +++ b/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_input.py @@ -3,6 +3,8 @@ Poco element input """ from airtest.core.api import text, time +from airtest.core.helper import G +import subprocess import flybirds.core.plugin.plugins.default.ui_driver.poco.poco_ele as poco_ele import flybirds.utils.flybirds_log as log @@ -29,7 +31,13 @@ def air_bdd_input( poco_object.set_text(input_str) except Exception as input_error: try: - log.info(f"air_bdd_input has error:{str(input_error)}") + log.info(f"air_bdd_input has error:{str(input_error)} change ime to yosemite") + package_name = "com.netease.nie.yosemite" + if not check_app_status(package_name): + G.DEVICE.yosemite_ime.start() + time.sleep(30) + # G.DEVICE.start_app(package_name, '/.ime.ImeService') + log.info("start yosemite ime successfully") poco_object.click() text(input_str) except Exception as input_error: @@ -38,3 +46,31 @@ def air_bdd_input( if not (after_input_wait is None): time.sleep(after_input_wait) + + +def is_app_installed(package_name): + try: + result = subprocess.run(['adb', 'shell', 'pm', 'list', 'packages'], capture_output=True, text=True) + return package_name in result.stdout + except subprocess.CalledProcessError as e: + print(f"Error checking if app is installed: {e}") + return False + + +def is_app_running(package_name): + try: + result = subprocess.run(['adb', 'shell', 'ps'], capture_output=True, text=True) + return package_name in result.stdout + except subprocess.CalledProcessError as e: + print(f"Error checking if app is running: {e}") + return False + + +def check_app_status(package_name): + package_name = "com.netease.nie.yosemite" + if is_app_installed(package_name) and is_app_running(package_name): + log.info(f"{package_name} is installed and running") + return True + else: + return False + diff --git a/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_text.py b/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_text.py index fdf333de..07bd9c80 100644 --- a/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_text.py +++ b/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_text.py @@ -25,7 +25,7 @@ def get_ele_text_replace_space( if ele_str is None: ele_str = poco_object.attr('label') handled_ele_str = re.sub(pattern, "", ele_str.replace(u"\u200b", "")) - if not (deal_method_name is None): + if deal_method_name is not None: deal_method = getattr(params_deal_module, deal_method_name) handled_ele_str = deal_method(handled_ele_str) handled_ele_str = re.sub(pattern, "", handled_ele_str) @@ -47,7 +47,7 @@ def get_ele_text( if ele_str is None: ele_str = poco_object.attr('label') ele_str = ele_str.replace(u"\u200b", "") - if not (deal_method_name is None): + if deal_method_name is not None: deal_method = getattr(params_deal_module, deal_method_name) ele_str = deal_method(ele_str) return ele_str diff --git a/flybirds/utils/dsl_helper.py b/flybirds/utils/dsl_helper.py index dda44770..e7685069 100644 --- a/flybirds/utils/dsl_helper.py +++ b/flybirds/utils/dsl_helper.py @@ -41,6 +41,13 @@ def sleep(sleep_time): def add_res_dic(dsl_params, functin_pattern, def_key): result_dic = {} + # 替换 @@空@@ 为空格 + if dsl_params is not None and "@@空格@@" in dsl_params: + dsl_params = re.sub(r'@@空格@@', ' ', dsl_params) + # 替换 @#@换行#符号@#@ 为换行符 + if dsl_params is not None and "@#@换行#符号@#@" in dsl_params: + dsl_params = re.sub(r'@#@换行#符号@#@', '\n', dsl_params) + match_obj = re.match(functin_pattern, dsl_params) if match_obj is not None: """ @@ -90,9 +97,16 @@ def params_to_dic(dsl_params, def_key="selector"): subsequent processes """ result_dic = {} - functin_pattern = re.compile(r"([\S\s]+),\s*([a-zA-Z0-9_]+)\s*=\s*(\S+)") + function_pattern = re.compile(r"([\S\s]+),\s*([a-zA-Z0-9_]+)\s*=\s*(\S+)") if isinstance(dsl_params, str): - result_dic = add_res_dic(dsl_params, functin_pattern, def_key) + result_dic = add_res_dic(dsl_params, function_pattern, def_key) + selector = result_dic.get("selector") + # 替换 @@空@@ 为空格 + if selector is not None and "@@空格@@" in selector: + result_dic["selector"] = re.sub(r'@@空格@@', ' ', selector) + # 替换 @#@换行#符号@#@ 为换行符 + if selector is not None and "@#@换行#符号@#@" in selector: + result_dic["selector"] = re.sub(r'@#@换行#符号@#@', '\n', selector) log.info("result_dic: {}".format(result_dic)) return result_dic From ad80933aa9b94d1115a7377d50c3f8787f698649 Mon Sep 17 00:00:00 2001 From: "yong.peng" Date: Fri, 18 Oct 2024 18:33:53 +0800 Subject: [PATCH 2/2] fix: Handling parameters with spaces and newlines in steps --- flybirds/utils/dsl_helper.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/flybirds/utils/dsl_helper.py b/flybirds/utils/dsl_helper.py index e7685069..f7389005 100644 --- a/flybirds/utils/dsl_helper.py +++ b/flybirds/utils/dsl_helper.py @@ -41,10 +41,8 @@ def sleep(sleep_time): def add_res_dic(dsl_params, functin_pattern, def_key): result_dic = {} - # 替换 @@空@@ 为空格 if dsl_params is not None and "@@空格@@" in dsl_params: dsl_params = re.sub(r'@@空格@@', ' ', dsl_params) - # 替换 @#@换行#符号@#@ 为换行符 if dsl_params is not None and "@#@换行#符号@#@" in dsl_params: dsl_params = re.sub(r'@#@换行#符号@#@', '\n', dsl_params) @@ -86,7 +84,6 @@ def add_res_dic(dsl_params, functin_pattern, def_key): else: result_dic[def_key] = dsl_params.strip().replace(u"\u200b", "") - # print('result_dic44444', result_dic) return result_dic @@ -101,10 +98,8 @@ def params_to_dic(dsl_params, def_key="selector"): if isinstance(dsl_params, str): result_dic = add_res_dic(dsl_params, function_pattern, def_key) selector = result_dic.get("selector") - # 替换 @@空@@ 为空格 if selector is not None and "@@空格@@" in selector: result_dic["selector"] = re.sub(r'@@空格@@', ' ', selector) - # 替换 @#@换行#符号@#@ 为换行符 if selector is not None and "@#@换行#符号@#@" in selector: result_dic["selector"] = re.sub(r'@#@换行#符号@#@', '\n', selector) log.info("result_dic: {}".format(result_dic))