Skip to content

Commit

Permalink
Merge pull request #108 from ctripcorp/98-app-支持页面加载异常检测
Browse files Browse the repository at this point in the history
feat:add blank screen detect
  • Loading branch information
clgwlg authored Aug 26, 2022
2 parents 936d935 + 6767253 commit 49477ca
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
3 changes: 2 additions & 1 deletion flybirds/core/driver/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion flybirds/core/plugin/event/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = ("<h4 style=\"color:DodgerBlue;\">failed screenshot analysis completed:{}% is white screen</h4>"
.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
Expand Down
32 changes: 20 additions & 12 deletions flybirds/core/plugin/plugins/default/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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



4 changes: 2 additions & 2 deletions flybirds/core/plugin/plugins/default/ui_driver/opencv/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49477ca

Please sign in to comment.