Best Python code snippet using toolium_python
visual_test.py
Source:visual_test.py
...208 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 row...
statistics.py
Source:statistics.py
...56 def get_average_number_of_words(self):57 if self.get_number_of_entries() == 0:58 return 059 return round(self.get_number_of_words() / self.get_number_of_entries(), 2)60 def _get_html_row(self, key, value):61 return ('<tr align="left">'62 '<td bgcolor="#e7e7e7"> ' + key + '</td>'63 '<td bgcolor="#aaaaaa"> <b>' + str(value) + '</b></td>'64 '</tr>')65 @property66 def overall_pairs(self):67 return [68 [_('Words'), self.get_number_of_words()],69 [_('Distinct Words'), self.get_number_of_distinct_words()],70 [_('Edited Days'), self.get_number_of_entries()],71 [_('Letters'), self.get_number_of_chars()],72 [_('Days between first and last Entry'), self.get_number_of_usage_days()],73 [_('Average number of Words'), self.get_average_number_of_words()],74 [_('Percentage of edited Days'), self.get_edit_percentage()],75 ]76 @property77 def day_pairs(self):78 day = self.journal.day79 return [80 [_('Words'), day.get_number_of_words()],81 [_('Lines'), len(day.text.splitlines())],82 [_('Letters'), len(day.text)],83 ]84 def get_stats_html(self):85 self.journal.save_old_day()86 page = '<html><body bgcolor="#8e8e95"><table cellspacing="5" border="0" width="400">\n'87 stats = self.pairs88 for key, value in stats:89 page += self._get_html_row(key, value)90 page += '</body></table></html>'91 return page92 def show_dialog(self, dialog):93 self.journal.save_old_day()94 self.days = self.journal.days95 day_store = dialog.day_list.get_model()96 day_store.clear()97 for pair in self.day_pairs:98 day_store.append(pair)99 overall_store = dialog.overall_list.get_model()100 overall_store.clear()101 for pair in self.overall_pairs:102 overall_store.append(pair)103 dialog.show_all()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!