def save_screenshot(self, image_name, directory=''): root_dir = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) self.get_driver().save_screenshot(root_dir + '/' + directory + f'/testui-{image_name}') logger.log_debug( f'{self.device_name}: Screenshot saved in "{root_dir}/testui-{image_name}"' )
def remove_log_file(self, when_no_errors=True): """ removes appium log file. If when_no_errors is False, it will always remove errors, if True, just when there are errors. :param when_no_errors: :return: """ if self.file_name is not None: try: if when_no_errors and len(self.errors) == 0: os.remove(self.file_name) elif not when_no_errors: os.remove(self.file_name) except FileNotFoundError: logger.log_debug('Log file already removed')
def compare(self, image_match='', max_scale=2.0, min_scale=0.3): found, p1 = compare_images(self.__original, self.__comparison, self.__threshold, image_match, max_scale, min_scale) if self.__threshold > p1: logger.log_debug( f'{self.__device_name}: Image match not found between: {self.__original} ' f'and {self.__comparison}. Threshold={self.__threshold}, matched = {p1}' ) return False, p1 else: logger.log_debug( f'{self.__device_name}: Image match found between: {self.__original} ' f'and {self.__comparison}. Threshold={self.__threshold}, matched = {p1}' ) return True, p1
def compare_video(self, image_match='', frame_rate_reduction=1, max_scale=2.0): found, p = compare_video_image(self.__original, self.__comparison, self.__threshold, image_match, frame_rate_reduction, max_scale) if found: logger.log_debug( f'{self.__device_name}: Image match found between video: {self.__original} ' f'and image {self.__comparison}. Threshold={self.__threshold}, matched = {p}' ) return True else: logger.log_debug( f'{self.__device_name}: Image match not found between video: {self.__original} ' f'and image {self.__comparison}. Threshold={self.__threshold}, matched = {p}' ) return False
def draw_match(original: str, comparison: str, threshold=0.9, device_name='Device'): method = cv2.TM_CCOEFF_NORMED # Read the images from the file root_dir = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) large_image = cv2.imread(root_dir + '/' + comparison) small_image = cv2.imread(root_dir + '/' + original) logger.log_debug( f'{device_name}: Comparing "{original}" with "{comparison}"') res = cv2.matchTemplate(small_image, large_image, method) loc = np.where(res >= threshold) null, w, h = large_image.shape[::-1] # For each match... suh = None for pt in zip(*loc[::-1]): suh = cv2.rectangle(small_image, pt, (pt[0] + w, pt[1] + h), (0, 66, 255), 1) cv2.imwrite('something.png', suh)
def save_screenshot(self, image_name=""): config = self.__configuration root_dir = config.screenshot_path if not config.screenshot_path: root_dir = path.dirname( path.dirname(path.dirname(path.abspath(__file__)))) root_dir = path.join(root_dir, "report_screenshots") Path(root_dir).mkdir(parents=True, exist_ok=True) current_time = datetime.now().strftime("%Y-%m-%d%H%M%S") if not image_name: image_name = f'ERROR-{self.device_name}-{current_time}.png' final_path = path.join(root_dir, image_name) self.get_driver().save_screenshot(final_path) logger.log_debug( f'{self.device_name}: Screenshot saved in "{final_path}"') return final_path
def __quit_driver(driver, debug): try: driver.quit() except Exception as err: if debug: logger.log_debug(f"appium was probably closed {err}. \n")