code: def assert_image_exists(self, pattern, timeout=20.0, **kwargs):
          
          pattern = self.d.pattern_open(pattern)
          match_kwargs = kwargs.copy()
          match_kwargs.pop('safe', None)
          match_kwargs.update({
              'timeout': timeout,
              'safe': True,
          })
          res = self.d.wait(pattern, **match_kwargs)
          is_success = res is not None
          message = 'assert image exists'
          if res:
              x, y = res.pos
              kwargs['position'] = {'x': x, 'y': y}
              message = 'image exists\npos %s\nconfidence=%.2f\nmethod=%s' % (res.pos, res.confidence, res.method)
          else:
              res = self.d.match(pattern)
              if res is None:
                  message = 'Image not found'
              else:
                  th = kwargs.get('threshold') or pattern.threshold or self.image_match_threshold
                  message = 'Matched: %s\nPosition: %s\nConfidence: %.2f\nThreshold: %.2f' % (
                      res.matched, res.pos, res.confidence, th)
  
          kwargs['target'] = self._save_screenshot(pattern, name_prefix='target')
          kwargs['screenshot'] = self.last_screenshot
          kwargs.update({
              'action': 'assert_image_exists',
              'message': message,
              'success': is_success,
          })
          self._add_assert(**kwargs)
docs: Assert if image exists
          Args:
              - pattern: image filename # not support pattern for now
              - timeout (float): seconds
              - safe (bool): not raise assert error even throung failed.