diff --git a/flybirds/core/driver/screen.py b/flybirds/core/driver/screen.py index 51aac5f8..a9cb0418 100644 --- a/flybirds/core/driver/screen.py +++ b/flybirds/core/driver/screen.py @@ -10,4 +10,5 @@ def screen_shot(path): def screen_link_to_behave(scenario, step_index, tag=None): - GlobalContext.screen.screen_link_to_behave(scenario, step_index, tag) + result = GlobalContext.screen.screen_link_to_behave(scenario, step_index, tag) + return result diff --git a/flybirds/core/plugin/event/scenario.py b/flybirds/core/plugin/event/scenario.py index 0215b6d9..f62b5640 100644 --- a/flybirds/core/plugin/event/scenario.py +++ b/flybirds/core/plugin/event/scenario.py @@ -9,6 +9,7 @@ from flybirds.core.driver import screen from flybirds.core.global_context import GlobalContext from flybirds.core.plugin.plugins.default.screen_record import link_record +from flybirds.core.plugin.plugins.default.screen import BaseScreen from flybirds.utils import flybirds_log as log from flybirds.utils import launch_helper @@ -86,9 +87,17 @@ def scenario_fail(context, scenario): log.info(info_log) log.error(f'[scenario_fail] step error msg:{step.error_message}') log.info("[scenario_fail] start to do failed screenshot") - screen.screen_link_to_behave( + img_path = screen.screen_link_to_behave( scenario, context.cur_step_index - 1, "fail_" ) + try: + white_percent = BaseScreen.white_screen_detect(img_path) + data = ("

failed screenshot analysis completed:{}% is white screen

" + .format(white_percent)) + scenario.description.append(data) + log.debug(f"[scenario_fail] screenshot white screen percent is {white_percent}") + except: + log.info(f"white screen detect fail") break # save screen recording diff --git a/flybirds/core/plugin/plugins/default/screen.py b/flybirds/core/plugin/plugins/default/screen.py index 327d2043..f5f97840 100644 --- a/flybirds/core/plugin/plugins/default/screen.py +++ b/flybirds/core/plugin/plugins/default/screen.py @@ -5,7 +5,7 @@ import os import time import traceback -from baseImage import Image +from baseImage import Image, Rect from base64 import b64decode from .ui_driver import SIFT @@ -120,17 +120,6 @@ def image_ocr(img_path): g_Context.ocr_result = ocr.ocr(img_path, cls=True) g_Context.image_size = Image(img_path).size 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 - # y = (box[0][1] + box[2][1]) / 2 - # log.info(f"[image ocr result] scan box xy info is:{x},{y}") - # txt = line[1][0] - # log.info(f"[image ocr result] scan txt info is:{txt}") - # score = line[1][1] - # log.info(f"[image ocr result] scan score info is:{score}") @staticmethod @@ -145,5 +134,24 @@ def image_verify(img_source_path, img_search_path): result = match.find_all_results(img_source, img_search) return result + @staticmethod + def white_screen_detect(img_path): + match = SIFT() + img = Image(img_path) + start_time = time.time() + width = img.size[1] + height = img.size[0] + range_height = height / 100 + point_y = 0 + white_percent = 0 + while point_y + range_height <= height: + new_img = img.crop(rect=Rect(0, point_y, width, range_height)) + kp_src, des_src = match.get_keypoint_and_descriptor(new_img) + point_y += range_height + if len(kp_src) < 3: + white_percent += 1 + log.info(f"detect use time:{time.time() - start_time}") + return white_percent + diff --git a/flybirds/core/plugin/plugins/default/ui_driver/opencv/base.py b/flybirds/core/plugin/plugins/default/ui_driver/opencv/base.py index d854e976..9a7eae06 100644 --- a/flybirds/core/plugin/plugins/default/ui_driver/opencv/base.py +++ b/flybirds/core/plugin/plugins/default/ui_driver/opencv/base.py @@ -151,8 +151,8 @@ def get_keypoint_and_descriptor(self, image): image = image.data keypoint, descriptor = self.detector.detectAndCompute(image, None) - if len(keypoint) < 2: - raise NoEnoughPointsError('{} detect not enough feature points in input images'.format(self.METHOD_NAME)) + # if len(keypoint) < 2: + # raise NoEnoughPointsError('{} detect not enough feature points in input images'.format(self.METHOD_NAME)) return keypoint, descriptor @staticmethod