Esempio n. 1
0
 def finalize(self, result):
     log_helper.archive_logs_if_set(self.options.log_path,
                                    self.options.archive_logs)
     if self.report_on:
         if not self.import_error:
             report_helper.add_bad_page_log_file(self.page_results_list)
             report_log_path = report_helper.archive_new_report_logs()
             report_helper.build_report(report_log_path,
                                        self.page_results_list,
                                        self.successes, self.failures,
                                        self.options.browser,
                                        self.show_report)
Esempio n. 2
0
def pytest_unconfigure():
    """ This runs after all tests have completed with pytest. """
    proxy_helper.remove_proxy_zip_if_present()
    if sb_config.reuse_session:
        # Close the shared browser session
        if sb_config.shared_driver:
            try:
                sb_config.shared_driver.quit()
            except AttributeError:
                pass
            except Exception:
                pass
        sb_config.shared_driver = None
    log_helper.archive_logs_if_set(sb_config.log_path, sb_config.archive_logs)
Esempio n. 3
0
def pytest_unconfigure():
    """ This runs after all tests have completed with pytest. """
    proxy_helper.remove_proxy_zip_if_present()
    if sb_config.reuse_session:
        # Close the shared browser session
        if sb_config.shared_driver:
            try:
                sb_config.shared_driver.quit()
            except AttributeError:
                pass
            except Exception:
                pass
        sb_config.shared_driver = None
    log_helper.archive_logs_if_set(sb_config.log_path, sb_config.archive_logs)

    # Dashboard post-processing: Disable time-based refresh and stamp complete
    if sb_config.dashboard and not sb_config._only_unittest:
        stamp = ""
        if sb_config._dash_is_html_report:
            # (If the Dashboard URL is the same as the HTML Report URL:)
            # Have the html report refresh back to a dashboard on update
            stamp += ('\n<script type="text/javascript" src="%s">'
                      '</script>' % constants.Dashboard.LIVE_JS)
        stamp += "\n<!--Test Run Complete-->"
        find_it = constants.Dashboard.META_REFRESH_HTML
        swap_with = ''  # Stop refreshing the page after the run is done
        try:
            # Part 1: Finalizing the dashboard / integrating html report
            time.sleep(0.3)  # Add time for "livejs" to detect changes
            abs_path = os.path.abspath('.')
            dashboard_path = os.path.join(abs_path, "dashboard.html")
            if os.path.exists(dashboard_path):
                with open(dashboard_path, 'r', encoding='utf-8') as f:
                    the_html = f.read()
                # If the test run doesn't complete by itself, stop refresh
                the_html = the_html.replace(find_it, swap_with)
                the_html += stamp
                if sb_config._dash_is_html_report and (
                        sb_config._saved_dashboard_pie):
                    the_html = the_html.replace("<h1>dashboard.html</h1>",
                                                sb_config._saved_dashboard_pie)
                    the_html = the_html.replace(
                        "</head>", '</head><link rel="shortcut icon" '
                        'href="https://seleniumbase.io/img/dash_pie_2.png">')
                    if sb_config._dash_final_summary:
                        the_html += sb_config._dash_final_summary
                time.sleep(0.25)
                with open(dashboard_path, "w", encoding='utf-8') as f:
                    f.write(the_html)
            # Part 2: Appending a pytest html report with dashboard data
            html_report_path = os.path.join(abs_path,
                                            sb_config._html_report_name)
            if sb_config._using_html_report and (
                    os.path.exists(html_report_path)
                    and not sb_config._dash_is_html_report):
                # Add the dashboard pie to the pytest html report
                with open(html_report_path, 'r', encoding='utf-8') as f:
                    the_html = f.read()
                if sb_config._saved_dashboard_pie:
                    the_html = the_html.replace(
                        "<h1>%s</h1>" % sb_config._html_report_name,
                        sb_config._saved_dashboard_pie)
                    the_html = the_html.replace(
                        "</head>", '</head><link rel="shortcut icon" '
                        'href="https://seleniumbase.io/img/dash_pie_2.png">')
                    if sb_config._dash_final_summary:
                        the_html += sb_config._dash_final_summary
                with open(html_report_path, "w", encoding='utf-8') as f:
                    f.write(the_html)
        except Exception:
            pass
Esempio n. 4
0
def _perform_behave_unconfigure_():
    from seleniumbase.core import log_helper
    from seleniumbase.core import proxy_helper

    proxy_helper.remove_proxy_zip_if_present()
    if hasattr(sb_config, "reuse_session") and sb_config.reuse_session:
        # Close the shared browser session
        if sb_config.shared_driver:
            try:
                if (
                    not is_windows
                    or sb_config.browser == "ie"
                    or sb_config.shared_driver.service.process
                ):
                    sb_config.shared_driver.quit()
            except AttributeError:
                pass
            except Exception:
                pass
        sb_config.shared_driver = None
    if hasattr(sb_config, "log_path"):
        log_helper.archive_logs_if_set(
            sb_config.log_path, sb_config.archive_logs
        )
    # Dashboard post-processing: Disable time-based refresh and stamp complete
    if not hasattr(sb_config, "dashboard") or not sb_config.dashboard:
        # Done with "behave_unconfigure" unless using the Dashboard
        return
    stamp = "\n<!--Test Run Complete-->"
    find_it = constants.Dashboard.META_REFRESH_HTML
    swap_with = ""  # Stop refreshing the page after the run is done
    find_it_2 = "Awaiting results... (Refresh the page for updates)"
    swap_with_2 = (
        "Test Run ENDED: Some results UNREPORTED due to skipped tearDown()"
    )
    find_it_3 = '<td class="col-result">Untested</td>'
    swap_with_3 = '<td class="col-result">Unreported</td>'
    find_it_4 = 'href="%s"' % constants.Dashboard.DASH_PIE_PNG_1
    swap_with_4 = 'href="%s"' % constants.Dashboard.DASH_PIE_PNG_2
    try:
        abs_path = os.path.abspath(".")
        dashboard_path = os.path.join(abs_path, "dashboard.html")
        # Part 1: Finalizing the dashboard / integrating html report
        if os.path.exists(dashboard_path):
            the_html_d = None
            with open(dashboard_path, "r", encoding="utf-8") as f:
                the_html_d = f.read()
            if sb_config._multithreaded and "-c" in sys.argv:
                # Threads have "-c" in sys.argv, except for the last
                raise Exception('Break out of "try" block.')
            if sb_config._multithreaded:
                dash_pie_loc = constants.Dashboard.DASH_PIE
                pie_path = os.path.join(abs_path, dash_pie_loc)
                if os.path.exists(pie_path):
                    import json

                    with open(pie_path, "r") as f:
                        dash_pie = f.read().strip()
                    sb_config._saved_dashboard_pie = json.loads(dash_pie)
            # If the test run doesn't complete by itself, stop refresh
            the_html_d = the_html_d.replace(find_it, swap_with)
            the_html_d = the_html_d.replace(find_it_2, swap_with_2)
            the_html_d = the_html_d.replace(find_it_3, swap_with_3)
            the_html_d = the_html_d.replace(find_it_4, swap_with_4)
            the_html_d += stamp
            with open(dashboard_path, "w", encoding="utf-8") as f:
                f.write(the_html_d)  # Finalize the dashboard
    except KeyboardInterrupt:
        pass
    except Exception:
        pass