Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handling parameters with spaces and newlines in steps #319

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions flybirds/utils/dsl_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ 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:
"""
Expand Down Expand Up @@ -79,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


Expand All @@ -90,9 +94,14 @@ 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

Expand Down