def test_04_get_text(self): # OCR on iOS 13 text = ImageUtils.get_text(self.app_image_default_ios) assert 'taps left' in text assert 'Tap the button' in text assert 'TAP' in text # OCR on Hello-World app text = ImageUtils.get_text(self.app_image_ios) assert 'My App' in text assert 'Tap the button' in text assert 'HIT' in text assert '42 clicks left' in text # OCR on Hello-World app text = ImageUtils.get_text(self.app_image) assert 'My App' in text assert 'Tap the button' in text assert 'TAP' in text assert '42 taps left' in text # OCR on complex screen (iPhone home screen). text = ImageUtils.get_text(self.iphone_image) assert 'Monday' in text assert 'Reminders' in text assert 'Settings' in text
def test_05_get_text_unicode(self): text = ImageUtils.get_text(self.unicode_image) Log.info(text) assert 'Ter Stegen' in text assert 'Neymar' in text text = ImageUtils.get_text(self.app_image_ng) Log.info(text) assert 'Ter Stegen' in text assert 'Piqué' in text
def test_01_read_image(self): img = ImageUtils.read_image(self.app_image) assert (img[1, 1] == numpy.array([117, 117, 117 ])).all(), 'Pixel 1x1 should be gray.' assert (img[200, 200] == numpy.array( [255, 255, 255])).all(), 'Pixel 200x200 should be white.'
def get_text(self): img_name = "actual_{0}_{1}.png".format(self.id, time.time()) actual_image_path = os.path.join(Settings.TEST_OUT_IMAGES, img_name) File.delete(actual_image_path) self.get_screen(path=actual_image_path, log_level=logging.DEBUG) text = ImageUtils.get_text(image_path=actual_image_path) File.delete(path=actual_image_path) return text
def get_main_color(self): image_path = os.path.join( Settings.TEST_OUT_IMAGES, self.name, 'screen_{0}.png'.format(int(time.time() * 1000))) self.get_screen(image_path, log_level=logging.DEBUG) result = ImageUtils.get_main_color(image_path) File.delete(path=image_path) return result
def get_screen_text(): """ Get text of current screen of host machine. :return: All the text visible on screen as string """ actual_image_path = os.path.join(Settings.TEST_OUT_IMAGES, "host_{0}.png".format(time.time())) if File.exists(actual_image_path): File.delete(actual_image_path) Screen.save_screen(path=actual_image_path) text = ImageUtils.get_text(image_path=actual_image_path) File.delete(actual_image_path) return text
def screen_match(self, expected_image, tolerance=0.1, timeout=30): """ Verify screen match expected image. :param expected_image: Name of expected image. :param tolerance: Tolerance in percents. :param timeout: Timeout in seconds. """ if File.exists(expected_image): match = False error_msg = 'Screen of {0} does NOT match {1}.'.format( self.name, expected_image) t_end = time.time() + timeout diff_image = None while time.time() < t_end: actual_image = expected_image.replace('.png', '_actual.png') self.get_screen(path=actual_image, log_level=logging.DEBUG) result = ImageUtils.image_match(actual_image=actual_image, expected_image=expected_image, tolerance=tolerance) if result[0]: Log.info('Screen of {0} matches {1}.'.format( self.name, expected_image)) match = True break else: diff_image = result[2] error_msg += ' Diff is {0} %.'.format(result[1]) Log.info(error_msg) time.sleep(3) if not match: if diff_image is not None: diff_image_path = expected_image.replace( '.png', '_diff.png') diff_image.save(diff_image_path) assert match, error_msg else: Log.info('Expected image not found!') Log.info('Actual image will be saved as expected: ' + expected_image) time.sleep(timeout) self.get_screen(path=expected_image, log_level=logging.DEBUG) assert False, "Expected image not found!"
def test_03_get_main_color(self): actual_color = ImageUtils.get_main_color(image_path=self.app_image) assert (actual_color == self.white ).all(), 'Main color is wrong. It should be white.'
def test_02_get_pixels_by_color(self): blue_pixels = ImageUtils.get_pixels_by_color(image_path=self.app_image, color=self.blue) assert blue_pixels == 18604, 'Blue pixels count is wrong. Actual: {0} Expected: {1}'.format( blue_pixels, 18604)