How to use _get_diff_message method in toolium

Best Python code snippet using toolium_python

test_visual_test.py

Source:test_visual_test.py Github

copy

Full Screen

...142 assert re.compile(expected_row).match(row) is not None143def test_diff_message_equal():144 message = None145 expected_message = ''146 assert expected_message == VisualTest._get_diff_message(message, 1000000)147def test_diff_message_size_pil():148 message = ''149 expected_message = 'Image dimensions do not match'150 assert expected_message == VisualTest._get_diff_message(message, 1000000)151def test_diff_message_size_perceptualdiff():152 message = """The new screenshot 'C:\\...\\01_login_form__test_login.png' did not match the baseline 'C:\\...\\login_form.png':153 FAIL: Image dimensions do not match"""154 expected_message = 'Image dimensions do not match'155 assert expected_message == VisualTest._get_diff_message(message, 1000000)156def test_diff_message_size_imagemagick():157 message = 'Image dimensions do not match'158 expected_message = 'Image dimensions do not match'159 assert expected_message == VisualTest._get_diff_message(message, 1000000)160def test_diff_message_diff_pil():161 message = ("The new screenshot 'C:\\...\\01_login_form__test_login.png' did not match the baseline "162 "'C:\\...\\login_form.png' (by a distance of 14794.11)")163 expected_message = 'Distance of 0.01479411'164 assert expected_message == VisualTest._get_diff_message(message, 1000000)165def test_diff_message_diff_perceptualdiff():166 message = "The new screenshot 'C:\\...\\01_login_form__test_login.png' did not match the baseline "167 message += """'C:\\...\\login_form.png' (See C:\\...\\01_login_form__test_login.diff.png):168 FAIL: Images are visibly different169 15040 pixels are different170 """171 expected_message = 'Distance of 0.01504000'172 assert expected_message == VisualTest._get_diff_message(message, 1000000)173def test_diff_message_diff_imagemagick():174 message = ("The new screenshot 'C:\\...\\01_login_form__test_login.png' did not match the baseline "175 "'C:\\...\\login_form.png' (See C:\\...\\01_login_form__test_login.diff.png):\n"176 "5443.77 (0.0830666) @ 0,0")177 expected_message = 'Distance of 0.08306660'178 assert expected_message == VisualTest._get_diff_message(message, 1000000)179def assert_image(visual, img, img_name, expected_image_filename):180 """Save img in an image file and compare with the expected image181 :param img: image object182 :param img_name: temporary filename183 :param expected_image_filename: filename of the expected image184 """185 # Save result image in output folder186 result_file = os.path.join(visual.output_directory, img_name + '.png')187 img.save(result_file)188 # Output image and expected image must be equal189 expected_image = os.path.join(root_path, 'resources', expected_image_filename + '.png')190 compare_image_files(result_file, expected_image)191def compare_image_files(image, expected_image, threshold=0.1):192 """Compare two images...

Full Screen

Full Screen

visual_test.py

Source:visual_test.py Github

copy

Full Screen

...198 if self.driver_wrapper.config.getboolean_optional('VisualTests', 'complete_report'):199 self._add_result_to_report('equal', report_name, image_file, baseline_file)200 return None201 except AssertionError as exc:202 diff_message = self._get_diff_message(str(exc), width * height)203 self._add_result_to_report('diff', report_name, image_file, baseline_file, diff_message)204 self.logger.warning("Visual error in '%s': %s", os.path.splitext(os.path.basename(baseline_file))[0],205 diff_message)206 if self.driver_wrapper.config.getboolean_optional('VisualTests', 'fail') or self.force:207 raise exc208 else:209 return diff_message210 def _add_result_to_report(self, result, report_name, image_file, baseline_file, message=''):211 self.results[result] += 1212 row = self._get_html_row(result, report_name, image_file, baseline_file, message)213 self._add_data_to_report_before_tag(row, '</tbody>')214 self._update_report_summary()215 def _add_data_to_report_before_tag(self, data, tag):216 with open(os.path.join(self.output_directory, self.report_name), "r+") as f:217 report = f.read()218 index = report.find(tag)219 report = report[:index] + data + report[index:]220 f.seek(0)221 f.write(report)222 def _update_report_summary(self):223 """Update asserts counter in report"""224 new_results = 'Visual asserts</b>: {} ({} failed)'.format(sum(self.results.values()), self.results['diff'])225 with open(os.path.join(self.output_directory, self.report_name), "r+") as f:226 report = f.read()227 report = re.sub(r'Visual asserts</b>: [0-9]* \([0-9]* failed\)', new_results, report)228 f.seek(0)229 f.write(report)230 def _add_summary_to_report(self):231 summary = '<p><b>Execution date</b>: {}</p>'.format(datetime.datetime.now().strftime('%d/%m/%Y %H:%M:%S'))232 summary += '<p><b>Baseline name</b>: {}</p>'.format(path.basename(self.baseline_directory))233 summary += '<p><b>Visual asserts</b>: {} ({} failed)</p>'.format(sum(self.results.values()),234 self.results['diff'])235 self._add_data_to_report_before_tag(summary, '</div>')236 def _get_html_row(self, result, report_name, image_file, baseline_file, message=''):237 row = '<tr class=' + result + '>'238 row += '<td>' + report_name + '</td>'239 # Create baseline column240 baseline_col = self._get_img_element(baseline_file, 'Baseline image')241 row += '<td>' + baseline_col + '</td>'242 # Create image column243 image_col = self._get_img_element(image_file, 'Screenshot image')244 row += '<td>' + image_col + '</td>'245 # Create diff column246 diff_file = image_file.replace('.png', '.diff.png')247 diff_col = self._get_img_element(diff_file, message) if os.path.exists(diff_file) else message248 row += '<td>' + diff_col + '</td>'249 row += '</tr>'250 return row251 def _get_img_element(self, image_file, image_title):252 if not image_file:253 return ''254 image_file_path = path.relpath(image_file, self.output_directory).replace('\\', '/')255 return '<img src="{}" title="{}"/>'.format(image_file_path, image_title)256 @staticmethod257 def _get_diff_message(message, image_size):258 if message is None:259 # Images are equal260 return ''261 elif message == '' or 'Image dimensions do not match' in message:262 # Different sizes in pil (''), perceptualdiff or imagemagick engines263 return 'Image dimensions do not match'264 # Check pil engine message265 m = re.search('\(by a distance of (.*)\)', message)266 if m:267 return 'Distance of %0.8f' % (float(m.group(1)) / image_size)268 # Check perceptualdiff engine message269 m = re.search('([0-9]*) pixels are different', message)270 if m:271 return 'Distance of %0.8f' % (float(m.group(1)) / image_size)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful