diff --git a/flybirds/core/dsl/globalization/i18n.py b/flybirds/core/dsl/globalization/i18n.py index c576e502..714017fe 100644 --- a/flybirds/core/dsl/globalization/i18n.py +++ b/flybirds/core/dsl/globalization/i18n.py @@ -140,7 +140,10 @@ ], "from {param1} find[{selector}]element": [ "向{param1}查找[{selector}]的元素"], - + "from {param1} find[{selector}]text": [ + "向{param1}扫描[{selector}]的文案"], + "from {param1} find[{selector}]image": [ + "向{param1}查找[{selector}]的图像"], "unblock the current page": ["解除当前页面限制"], "current page is [{param}]": ["当前页面是[{param}]"], "current page is not last page": ["当前页面已不是上一个指定页面"], diff --git a/flybirds/core/dsl/step/element.py b/flybirds/core/dsl/step/element.py index 90487292..91a00a8b 100644 --- a/flybirds/core/dsl/step/element.py +++ b/flybirds/core/dsl/step/element.py @@ -356,6 +356,32 @@ def full_screen_swipe_to_ele_aaa(context, param1=None, selector=None): g_Context.step.full_screen_swipe_to_ele_aaa(context, param1, selector) +@step("from {param1} find[{selector}]text") +@ele_wrap +def full_screen_swipe_to_ocr_txt(context, param1=None, selector=None): + """ + Full screen swipe in the specified direction to find the specified + selector element + :param context: step context + :param param1: slide direction (top/bottom/left/right) + :param selector: locator string for selector element (or None). + """ + g_Context.step.full_screen_swipe_to_ocr_txt(context, param1, selector) + + +@step("from {param1} find[{selector}]image") +@ele_wrap +def full_screen_swipe_to_img(context, param1=None, selector=None): + """ + Full screen swipe in the specified direction to find the specified + selector element + :param context: step context + :param param1: slide direction (top/bottom/left/right) + :param selector: locator string for selector element (or None). + """ + g_Context.step.full_screen_swipe_to_img(context, param1, selector) + + @step("clear [{selector}] and input[{param2}]") @ele_wrap def ele_clear_input(context, selector=None, param2=None): diff --git a/flybirds/core/global_resource.py b/flybirds/core/global_resource.py index 03dafad8..f9b0a202 100644 --- a/flybirds/core/global_resource.py +++ b/flybirds/core/global_resource.py @@ -268,7 +268,7 @@ def get_ele_locator(key): return key ele_locator = all_locators.get(key) if ele_locator is None: - log.info( + log.debug( f"the ele_locator.json has no element locator configuration " f"for [{key}]") return key diff --git a/flybirds/core/plugin/plugins/default/app_base_step.py b/flybirds/core/plugin/plugins/default/app_base_step.py index 7aabba40..f88a71c4 100644 --- a/flybirds/core/plugin/plugins/default/app_base_step.py +++ b/flybirds/core/plugin/plugins/default/app_base_step.py @@ -94,6 +94,12 @@ def swipe_to_ele(self, context, p_selector, param2, c_selector): def full_screen_swipe_to_ele_aaa(self, context, param1, selector): step_adjust.full_screen_swipe_to_ele_aaa(context, param1, selector) + def full_screen_swipe_to_ocr_txt(self, context, param1, selector): + step_adjust.full_screen_swipe_to_ocr_txt(context, param1, selector) + + def full_screen_swipe_to_img(self, context, param1, selector): + step_adjust.full_screen_swipe_to_img(context, param1, selector) + def position_not_change(self, context, selector, param2): position_not_change(context, selector, param2) diff --git a/flybirds/core/plugin/plugins/default/screen.py b/flybirds/core/plugin/plugins/default/screen.py index 6fd07813..e80babc4 100644 --- a/flybirds/core/plugin/plugins/default/screen.py +++ b/flybirds/core/plugin/plugins/default/screen.py @@ -24,7 +24,7 @@ def screen_shot(path): """ Take a screenshot and save """ - log.info(f"[screen_shot] screen shot start. path is:{path}") + log.debug(f"[screen_shot] screen shot start. path is:{path}") cur_platform = g_Context.platform try: if cur_platform is None: @@ -44,7 +44,7 @@ def screen_shot(path): "Screenshot failed path: {}, error: {}".format(path, str(e)), traceback.format_exc(), ) - log.info("[screen_shot] screen shot end!") + log.debug("[screen_shot] screen shot end!") @staticmethod def screen_link_to_behave(scenario, step_index, tag=None, link=True): @@ -80,13 +80,13 @@ def screen_link_to_behave(scenario, step_index, tag=None, link=True): feature_name) else: current_screen_dir = os.path.join(feature_name) - log.info(f"[screen_link_to_behave] screen_shot_dir path :" + log.debug(f"[screen_link_to_behave] screen_shot_dir path :" f"{screen_shot_dir} and " f"current_screen_dir path: {current_screen_dir}") file_helper.create_dirs_path_object(current_screen_dir) src_path = "../screenshot/{}/{}".format(feature_name, file_name) - log.info("[screen_link_to_behave] src_path: {}".format(src_path)) + log.debug("[screen_link_to_behave] src_path: {}".format(src_path)) data = ( 'embeddingsTags, stepIndex={}, '.format(step_index, src_path) @@ -102,13 +102,13 @@ def image_ocr(img_path): """ Take a screenshot and ocr """ - log.info(f"[image ocr path] image path is:{img_path}") + log.debug(f"[image ocr path] image path is:{img_path}") ocr = g_Context.ocr_driver_instance g_Context.ocr_result = ocr.ocr(img_path, cls=True) g_Context.image_size = Image(img_path).size - log.info(f"[image ocr path] image size is:{g_Context.image_size}") - for line in g_Context.ocr_result: - log.info(f"[image ocr result] scan line info is:{line}") + log.debug(f"[image ocr path] image size is:{g_Context.image_size}") + # for line in g_Context.ocr_result: + # log.info(f"[image ocr result] scan line info is:{line}") # box = line[0] # log.info(f"[image ocr result] scan box info is:{box}") # x = (box[0][0] + box[1][0]) / 2 diff --git a/flybirds/core/plugin/plugins/default/step/click.py b/flybirds/core/plugin/plugins/default/step/click.py index cd71c337..39dc04f2 100644 --- a/flybirds/core/plugin/plugins/default/step/click.py +++ b/flybirds/core/plugin/plugins/default/step/click.py @@ -2,12 +2,13 @@ """ Step implement of element click. """ +import re import flybirds.core.global_resource as gr import flybirds.core.plugin.plugins.default.ui_driver.poco.findsnap \ as find_snap import flybirds.utils.dsl_helper as dsl_helper from flybirds.core.global_context import GlobalContext as g_Context -from flybirds.core.plugin.plugins.default.step.verify import ocr_txt_exist +from flybirds.core.plugin.plugins.default.step.verify import ocr_txt_contain from flybirds.core.plugin.plugins.default.step.common import img_verify @@ -109,9 +110,9 @@ def click_coordinates(context, x, y): def click_ocr_text(context, param): - ocr_txt_exist(context, param) + ocr_txt_contain(context, param) for line in g_Context.ocr_result: - if line[1][0] == param: + if re.search(param, line[1][0], flags=0) is not None: box = line[0] x = (box[0][0] + box[1][0]) / 2 y = (box[0][1] + box[2][1]) / 2 diff --git a/flybirds/core/plugin/plugins/default/step/page_show_adjust.py b/flybirds/core/plugin/plugins/default/step/page_show_adjust.py index 59fe7fcb..76078e68 100644 --- a/flybirds/core/plugin/plugins/default/step/page_show_adjust.py +++ b/flybirds/core/plugin/plugins/default/step/page_show_adjust.py @@ -141,3 +141,99 @@ def full_screen_swipe_to_ele_aaa(context, param1, param2): distance, duration, ) + + +def full_screen_swipe_to_ocr_txt(context, param1, param2): + poco_instance = gr.get_value("pocoInstance") + handled_param2_temp = handle_str(param2) + param2_dict = dsl_helper.params_to_dic(handled_param2_temp) + + search_dsl_str = param2_dict["selector"] + + if "swipeCount" in param2_dict.keys(): + swipe_count = int(param2_dict["swipeCount"]) + else: + swipe_count = gr.get_frame_config_value("swipe_search_count", 5) + + direction = param1.strip() + + screen_size = gr.get_device_size() + + start_x = None + if "startX" in param2_dict.keys(): + start_x = float(param2_dict["startX"]) + start_y = None + if "startY" in param2_dict.keys(): + start_y = float(param2_dict["startY"]) + + if "distance" in param2_dict.keys(): + distance = float(param2_dict["distance"]) + else: + distance = gr.get_frame_config_value("swipe_search_distance", 0.3) + + duration = None + if gr.get_frame_config_value("use_search_swipe_duration", False): + duration = gr.get_frame_config_value("search_swipe_duration", 1) + if "duration" in param2_dict.keys(): + duration = float(param2_dict["duration"]) + + ps.full_screen_swipe_search_ocr( + context, + poco_instance, + search_dsl_str, + swipe_count, + direction, + screen_size, + start_x, + start_y, + distance, + duration, + ) + + +def full_screen_swipe_to_img(context, param1, param2): + poco_instance = gr.get_value("pocoInstance") + handled_param2_temp = handle_str(param2) + param2_dict = dsl_helper.params_to_dic(handled_param2_temp) + + search_dsl_str = param2_dict["selector"] + + if "swipeCount" in param2_dict.keys(): + swipe_count = int(param2_dict["swipeCount"]) + else: + swipe_count = gr.get_frame_config_value("swipe_search_count", 5) + + direction = param1.strip() + + screen_size = gr.get_device_size() + + start_x = None + if "startX" in param2_dict.keys(): + start_x = float(param2_dict["startX"]) + start_y = None + if "startY" in param2_dict.keys(): + start_y = float(param2_dict["startY"]) + + if "distance" in param2_dict.keys(): + distance = float(param2_dict["distance"]) + else: + distance = gr.get_frame_config_value("swipe_search_distance", 0.3) + + duration = None + if gr.get_frame_config_value("use_search_swipe_duration", False): + duration = gr.get_frame_config_value("search_swipe_duration", 1) + if "duration" in param2_dict.keys(): + duration = float(param2_dict["duration"]) + + ps.full_screen_swipe_search_img( + context, + poco_instance, + search_dsl_str, + swipe_count, + direction, + screen_size, + start_x, + start_y, + distance, + duration, + ) diff --git a/flybirds/core/plugin/plugins/default/step/verify.py b/flybirds/core/plugin/plugins/default/step/verify.py index 50d029b1..685de80e 100644 --- a/flybirds/core/plugin/plugins/default/step/verify.py +++ b/flybirds/core/plugin/plugins/default/step/verify.py @@ -274,14 +274,17 @@ def wait_ocr_text_appear(context, param): ocr(context) txts = [line[1][0] for line in g_Context.ocr_result] fixed_txt = paddle_fix_txt(txts) - if param in fixed_txt: - text_exist = True - else: + for txt in fixed_txt: + if re.search(param, txt, flags=0) is not None: + text_exist = True + if text_exist is False: if time.time() - start > timeout/2: time.sleep(timeout/2) else: time.sleep(5) if time.time() - start > timeout: + for line in g_Context.ocr_result: + log.info(f"[image ocr result] scan line info is:{line}") message = "text not found in {} seconds, expect text:{}" \ .format(timeout, param) raise FlybirdVerifyException(message) @@ -293,19 +296,24 @@ def ocr_txt_exist(context, param): fixed_txt = paddle_fix_txt(txts) verify.text_container(param, fixed_txt) else: + for line in g_Context.ocr_result: + log.info(f"[image ocr result] scan line info is:{line}") message = "ocr result is null" raise FlybirdVerifyException(message) -def ocr_txt_contain(context, param): +def ocr_txt_contain(context, param, islog=True): if len(g_Context.ocr_result) >= 1: txts = [line[1][0] for line in g_Context.ocr_result] fixed_txt = paddle_fix_txt(txts) - result = None + result = False for txt in fixed_txt: - if param in txt: + if re.search(param, txt, flags=0) is not None: result = True - if result is None: + return result + if result is False and islog is True: + for line in g_Context.ocr_result: + log.info(f"[image ocr result] scan line info is:{line}") message = "ocr result not contain {}".format(param) raise FlybirdVerifyException(message) else: @@ -319,6 +327,8 @@ def ocr_txt_not_exist(context, param): fixed_txt = paddle_fix_txt(txts) verify.text_not_container(param, fixed_txt) else: + for line in g_Context.ocr_result: + log.info(f"[image ocr result] scan line info is:{line}") message = "ocr result is null" raise FlybirdVerifyException(message) @@ -334,22 +344,23 @@ def paddle_fix_txt(txt): return txt -def img_exist(context, param): +def img_exist(context, param, islog=True): start = time.time() step_index = context.cur_step_index - 1 result = img_verify(context, param) if len(result) == 0: - src_path = "../../../{}".format(param) - data = ( - 'embeddingsTags, stepIndex={}, '.format(step_index, src_path) - ) - context.scenario.description.append(data) - # context.cur_step_index += 1 + if islog is True: + src_path = "../../../{}".format(param) + data = ( + 'embeddingsTags, stepIndex={}, '.format(step_index, src_path) + ) + context.scenario.description.append(data) raise Exception("[image exist verify] image not found !") else: log.info(f"[image exist verify] cost time:{time.time() - start}") log.info(f"[image exist verify] result:{result}") + return True def img_not_exist(context, param): diff --git a/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_swipe.py b/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_swipe.py index d4738f79..6d6d177c 100644 --- a/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_swipe.py +++ b/flybirds/core/plugin/plugins/default/ui_driver/poco/poco_swipe.py @@ -12,6 +12,8 @@ from flybirds.core.exceptions import FlybirdNotFoundException from flybirds.core.global_context import GlobalContext as g_Context from flybirds.utils import language_helper as lan +from flybirds.core.plugin.plugins.default.step.verify import ocr, ocr_txt_contain, img_exist +import flybirds.utils.flybirds_log as log def air_bdd_full_screen_swipe( @@ -286,3 +288,105 @@ def air_bdd_swipe_search( raise FlybirdNotFoundException(message, {}) if gr.get_frame_config_value("use_snap", False): findsnap.fix_refresh_status(True) + + +def full_screen_swipe_search_ocr( + context, + poco, + search_dsl_str, + swipe_count, + direction, + screen_size, + start_x=None, + start_y=None, + distance=None, + duration=None, +): + """ + Full screen swipe to find + """ + direction = point_helper.search_direction_switch(direction) + start_point = point_helper.get_swipe_search_start_point( + direction, start_x, start_y + ) + + if distance is None: + distance = 0.3 + + log_count = swipe_count + searched = False + while swipe_count >= 0: + try: + ocr(context) + searched = ocr_txt_contain(context, search_dsl_str, islog=False) + if searched is True: + break + except Exception: + pass + if swipe_count == 0: + break + air_bdd_full_screen_swipe( + poco, start_point, screen_size, direction, distance, duration + ) + swipe_count -= 1 + if not searched: + for line in g_Context.ocr_result: + log.info(f"[image ocr result] scan line info is:{line}") + message = "swipe to {} {} times,not find {}".format( + direction, log_count, search_dsl_str + ) + raise FlybirdNotFoundException(message, {}) + + +def full_screen_swipe_search_img( + context, + poco, + search_dsl_str, + swipe_count, + direction, + screen_size, + start_x=None, + start_y=None, + distance=None, + duration=None, +): + """ + Full screen swipe to find + """ + direction = point_helper.search_direction_switch(direction) + start_point = point_helper.get_swipe_search_start_point( + direction, start_x, start_y + ) + + if distance is None: + distance = 0.3 + + log_count = swipe_count + searched = False + while swipe_count >= 0: + try: + searched = img_exist(context, search_dsl_str, islog=False) + if searched is True: + break + except Exception: + pass + if swipe_count == 0: + break + air_bdd_full_screen_swipe( + poco, start_point, screen_size, direction, distance, duration + ) + swipe_count -= 1 + if not searched: + step_index = context.cur_step_index - 1 + src_path = "../../../{}".format(search_dsl_str) + data = ( + 'embeddingsTags, stepIndex={}, '.format(step_index, src_path) + ) + context.scenario.description.append(data) + + message = "swipe to {} {} times,not find {}".format( + direction, log_count, search_dsl_str + ) + raise FlybirdNotFoundException(message, {}) +