コード例 #1
0
 def stop_recording_and_compare(self,
                                comparison,
                                threshold=0.9,
                                FPS_reduction=1,
                                not_found=False,
                                keep_image_as='',
                                assertion=True):
     now = datetime.now()
     current_time = now.strftime("%Y-%m-%d%H%M%S")
     video_name = f'{self.device_udid}{current_time}.mp4'
     self.stop_recording_screen(video_name)
     root_dir = os.path.dirname(
         os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
     found = ImageRecognition(video_name, comparison, threshold, device_name=self.device_name) \
         .compare_video(keep_image_as, frame_rate_reduction=FPS_reduction)
     os.remove(root_dir + f'/{video_name}')
     if not found and not not_found:
         if assertion:
             raise Exception(
                 f'{self.device_name}: The image and video compared did not match. '
                 f'Threshold={threshold}')
         else:
             return False
     if found and not_found:
         if assertion:
             raise Exception(
                 f'{self.device_name}: The image and video compared matched. threshold={threshold}'
             )
         else:
             return False
     return True
コード例 #2
0
    def is_image_match(self,
                       image_name,
                       threshold=0.9,
                       image_match='',
                       max_scale=2.0,
                       min_scale=0.3):
        """
        Takes screenshot of the element and compares it with the one you provide as 'image_name'
        :param min_scale:
        :param max_scale:
        :param image_match: returns the image with a rectangle showing the match
        :param image_name: relative path to image
        :param threshold: limit to consider image as a match (0 to 1)
        :return: Elements
        """
        is_not = self.__is_not
        self.__is_not = False
        self.screenshot(self.device_name + '.png')
        found, p = ImageRecognition(self.device_name + '.png', image_name, threshold, self.device_name) \
            .compare(image_match=image_match, max_scale=max_scale, min_scale=min_scale)
        if not found and not is_not:
            return False
        if found and is_not:
            return False
        root_dir = os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/'
        os.remove(root_dir + self.device_name + '.png')

        return True
コード例 #3
0
 def get_dimensions(self):
     now = datetime.now()
     current_time = now.strftime("%Y-%m-%d%H%M%S")
     image_name = f'{self.device_udid}{current_time}.png'
     self.save_screenshot(image_name)
     dimensions = ImageRecognition(
         f'testui-{image_name}').image_original_size()
     self.__delete_screenshot(image_name)
     return dimensions
コード例 #4
0
    def find_image_match(self,
                         comparison,
                         threshold=0.90,
                         assertion=False,
                         not_found=False,
                         image_match=''):
        now = datetime.now()
        current_time = now.strftime("%Y-%m-%d%H%M%S")
        image_name = f'{self.device_udid}{current_time}.png'
        image_path = self.save_screenshot(image_name)
        found, p = ImageRecognition(image_path, comparison, threshold,
                                    self.device_name).compare(image_match)
        if assertion and not found and not not_found:
            exception = f'{self.device_name}: The images compared did not match. threshold={threshold}, matched = {p}\n'
            logger.log_error(error_with_traceback(exception))
            raise Exception(exception)
        os.remove(image_path)

        return found
コード例 #5
0
    def screenshot(self, image_name='cropped_image.png'):
        """
        Takes screenshot of the specific element
        :param image_name: relative path to image taken
        :return:
        """
        self.wait_until_visible()
        self.testui_driver.save_screenshot(
            f'{self.device_name}-crop_image.png')
        dimensions = self.dimensions
        top_left = self.location
        ImageRecognition(
            f'testui-{self.device_name}-crop_image.png').crop_original_image(
                top_left.x + dimensions.x // 2, top_left.y + dimensions.y // 2,
                dimensions.x, dimensions.y, image_name)
        root_dir = os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
        os.remove(root_dir + f'/testui-{self.device_name}-crop_image.png')

        return self