def save_page_source(driver, name, folder=None): """ Saves the page HTML to the current directory (or given subfolder). If the folder specified doesn't exist, it will get created. @Params name - The file name to save the current page's HTML to. folder - The folder to save the file to. (Default = current folder) """ from seleniumbase.core import log_helper if not name.endswith(".html"): name = name + ".html" if folder: abs_path = os.path.abspath('.') file_path = abs_path + "/%s" % folder if not os.path.exists(file_path): os.makedirs(file_path) html_file_path = "%s/%s" % (file_path, name) else: html_file_path = name page_source = driver.page_source html_file = codecs.open(html_file_path, "w+", "utf-8") rendered_source = log_helper.get_html_source_with_base_href( driver, page_source) html_file.write(rendered_source) html_file.close()
def addFailure(self, test, err, capt=None, tbinfo=None): try: page_source = test.driver.page_source except Exception: # Since we can't get the page source from here, skip saving it return test_logpath = self.options.log_path + "/" + test.id() if not os.path.exists(test_logpath): os.makedirs(test_logpath) html_file_name = "%s/%s" % (test_logpath, self.logfile_name) html_file = codecs.open(html_file_name, "w+", "utf-8") rendered_source = log_helper.get_html_source_with_base_href(test.driver, page_source) html_file.write(rendered_source) html_file.close()
def addFailure(self, test, err, capt=None, tbinfo=None): try: page_source = test.driver.page_source except Exception: # Since we can't get the page source from here, skip saving it return test_logpath = self.options.log_path + "/" + test.id() if not os.path.exists(test_logpath): os.makedirs(test_logpath) html_file_name = "%s/%s" % (test_logpath, self.logfile_name) html_file = codecs.open(html_file_name, "w+", "utf-8") rendered_source = log_helper.get_html_source_with_base_href( test.driver, page_source) html_file.write(rendered_source) html_file.close()