@staticmethod
    def _check_rules(browser, rules_js, config):
        """
        Run an accessibility audit on the page using the axe-core ruleset.

        Args:
            browser: a browser instance.
            rules_js: the ruleset JavaScript as a string.
            config: an AxsAuditConfig instance.

        Returns:
            A list of violations.

        Related documentation:

            https://github.com/dequelabs/axe-core/blob/master/doc/API.md#results-object

        __Caution__: You probably don't really want to call this method
        directly! It will be used by `AxeCoreAudit.do_audit`.
        """
        audit_run_script = dedent("""
            {rules_js}
            {custom_rules}
            axe.configure(customRules);
            var updatedResults = function(r) {{
                window.a11yAuditResults = JSON.stringify(r);
                window.console.log(window.a11yAuditResults);
            }}
            axe.a11yCheck({context}, {options}, updatedResults);
        """).format(
            rules_js=rules_js,
            custom_rules=config.custom_rules,
            context=config.context,
            options=config.rules
        )

        audit_results_script = dedent("""
            window.console.log(window.a11yAuditResults);
            return window.a11yAuditResults;
        """)

        browser.execute_script(audit_run_script)

        def audit_results_check_func():
            """
            A method to check that the audit has completed.

            Returns:

                (True, results) if the results are available.
                (False, None) if the results aren't available.
            """

            unicode_results = browser.execute_script(audit_results_script)

            try:
                results = json.loads(unicode_results)
            except (TypeError, __HOLE__):
                results = None

            if results:
                return True, results
            else:
                return False, None

        result = Promise(
            audit_results_check_func,
            "Timed out waiting for a11y audit results.",
            timeout=5,
        ).fulfill()

        # audit_results is report of accessibility violations for that session
        # Note that this ruleset doesn't have distinct error/warning levels.
        audit_results = result.get('violations')
        return audit_results
dataset/ETHPy150Open edx/bok-choy/bok_choy/a11y/axe_core_ruleset.py/AxeCoreAudit._check_rules