Best Python code snippet using SeleniumBase
master_qa.py
Source:master_qa.py
...291 f.write(page_header)292 for line in self.page_results_list:293 f.write("%s\n" % line)294 f.close()295 def __add_results_page(self, html):296 abs_path = os.path.abspath('.')297 file_path = abs_path + "/%s" % self.LATEST_REPORT_DIR298 results_file_name = self.RESULTS_PAGE299 results_file = "%s/%s" % (file_path, results_file_name)300 f = open(results_file, 'w')301 f.write(html)302 f.close()303 return results_file304 def __process_manual_check_results(self, auto_close_results_page=False):305 perfection = True306 failures_count = self.manual_check_count - self.manual_check_successes307 print("\n\n*** Test Result: ***")308 if self.manual_check_successes == self.manual_check_count:309 pass310 else:311 print("WARNING: There were page issues detected!")312 perfection = False313 if self.incomplete_runs > 0:314 print("WARNING: Not all tests finished running!")315 perfection = False316 if perfection:317 if self.manual_check_count > 0:318 print("SUCCESS: Everything checks out OKAY!")319 else:320 print("WARNING: No manual checks were performed!")321 else:322 pass323 self.__add_bad_page_log_file() # Includes successful results324 log_string = self.__clear_out_old_logs(get_log_folder=True)325 log_folder = log_string.split('/')[-1]326 abs_path = os.path.abspath('.')327 file_path = abs_path + "/%s" % self.ARCHIVE_DIR328 log_path = "%s/%s" % (file_path, log_folder)329 web_log_path = "file://%s" % log_path330 tf_color = "#11BB11"331 if failures_count > 0:332 tf_color = "#EE3A3A"333 ir_color = "#11BB11"334 if self.incomplete_runs > 0:335 ir_color = "#EE3A3A"336 summary_table = '''<div><table><thead><tr>337 <th>TESTING SUMMARY</th>338 <th> </th>339 </tr></thead><tbody>340 <tr style="color:#00BB00"><td>CHECKS PASSED: <td>%s</tr>341 <tr style="color:%s" ><td>CHECKS FAILED: <td>%s</tr>342 <tr style="color:#4D4DDD"><td>TOTAL VERIFICATIONS: <td>%s</tr>343 <tr style="color:%s" ><td>INCOMPLETE TEST RUNS: <td>%s</tr>344 </tbody></table>''' % (self.manual_check_successes,345 tf_color,346 failures_count,347 self.manual_check_count,348 ir_color,349 self.incomplete_runs)350 summary_table = '''<h1 id="ContextHeader" class="sectionHeader" title="">351 %s</h1>''' % summary_table352 log_link_shown = '../%s%s/' % (353 self.ARCHIVE_DIR, web_log_path.split(self.ARCHIVE_DIR)[1])354 csv_link = '%s/%s' % (web_log_path, self.BAD_PAGE_LOG)355 csv_link_shown = '%s' % self.BAD_PAGE_LOG356 log_table = '''<p><p><p><p><h2><table><tbody>357 <tr><td>LOG FILES LINK: <td><a href="%s">%s</a></tr>358 <tr><td>RESULTS TABLE: <td><a href="%s">%s</a></tr>359 </tbody></table></h2><p><p><p><p>''' % (360 web_log_path, log_link_shown, csv_link, csv_link_shown)361 failure_table = '<h2><table><tbody></div>'362 any_screenshots = False363 for line in self.page_results_list:364 line = line.split(',')365 if line[1] == '"FAILED!"' or line[1] == '"ERROR!"':366 if not any_screenshots:367 any_screenshots = True368 failure_table += '''<thead><tr>369 <th>SCREENSHOT FILE </th>370 <th>LOCATION OF FAILURE</th>371 </tr></thead>'''372 display_url = line[3]373 if len(display_url) > 60:374 display_url = display_url[0:58] + '...'375 line = '<a href="%s">%s</a>' % (376 "file://" + log_path + '/' + line[2], line[2]) + '''377 <td>378 ''' + '<a href="%s">%s</a>' % (line[3], display_url)379 line = line.replace('"', '')380 failure_table += '<tr><td>%s</tr>\n' % line381 failure_table += '</tbody></table>'382 table_view = '%s%s%s' % (383 summary_table, log_table, failure_table)384 report_html = '<html><head>%s</head><body>%s</body></html>' % (385 style, table_view)386 results_file = self.__add_results_page(report_html)387 archived_results_file = log_path + '/' + self.RESULTS_PAGE388 shutil.copyfile(results_file, archived_results_file)389 print(390 "\n*** The results html page is located at: ***\n" + results_file)391 self.open("file://%s" % archived_results_file)392 if auto_close_results_page:393 # Long enough to notice the results before closing the page394 time.sleep(1.0)395 else:396 # The user can decide when to close the results page397 print("\n*** Close the html report window to continue ***")398 while len(self.driver.window_handles):...
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!!