|
6 | 6 | from pathlib import Path |
7 | 7 |
|
8 | 8 |
|
| 9 | +logger = logging.getLogger(__name__) |
9 | 10 | AXE_PATH = Path(__file__).parent / "resources" / "axe.js" |
10 | 11 | PATH_FOR_REPORT = Path(__file__).parent.parent / "axe-reports" |
11 | 12 | DEFAULT_WCAG_RULESET = ['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'wcag22a', 'wcag22aa', 'best-practice'] |
@@ -36,13 +37,16 @@ def run(page: Page, |
36 | 37 | strict_mode (bool): [Optional] If true, raise an exception if a violation is detected. If false (default), proceed with test execution. |
37 | 38 | html_report_generated (bool): [Optional] If true (default), generates a html report for the page scanned. If false, no html report is generated. |
38 | 39 | json_report_generated (bool): [Optional] If true (default), generates a json report for the page scanned. If false, no json report is generated. |
| 40 | + |
| 41 | + Returns: |
| 42 | + dict: A Python dictionary with the axe-core output of the page scanned. |
39 | 43 | """ |
40 | 44 |
|
41 | 45 | page.evaluate(AXE_PATH.read_text(encoding="UTF-8")) |
42 | 46 |
|
43 | 47 | response = page.evaluate("axe." + Axe._build_run_command(ruleset) + ".then(results => {return results;})") |
44 | 48 |
|
45 | | - logging.info(f"""Axe scan summary of [{response["url"]}]: Passes = {len(response["passes"])}, |
| 49 | + logger.info(f"""Axe scan summary of [{response["url"]}]: Passes = {len(response["passes"])}, |
46 | 50 | Violations = {len(response["violations"])}, Inapplicable = {len(response["inapplicable"])}, |
47 | 51 | Incomplete = {len(response["incomplete"])}""") |
48 | 52 |
|
@@ -81,6 +85,9 @@ def run_list(page: Page, |
81 | 85 | strict_mode (bool): [Optional] If true, raise an exception if a violation is detected. If false (default), proceed with test execution. |
82 | 86 | html_report_generated (bool): [Optional] If true (default), generates a html report for the page scanned. If false, no html report is generated. |
83 | 87 | json_report_generated (bool): [Optional] If true (default), generates a json report for the page scanned. If false, no json report is generated. |
| 88 | + |
| 89 | + Returns: |
| 90 | + dict: A Python dictionary with the axe-core output of all the pages scanned, with the page list used as the key for each report. |
84 | 91 | """ |
85 | 92 | results = {} |
86 | 93 | for selected_page in page_list: |
@@ -120,24 +127,24 @@ def _create_path_for_report(filename: str) -> Path: |
120 | 127 | return PATH_FOR_REPORT / filename |
121 | 128 |
|
122 | 129 | @staticmethod |
123 | | - def _create_json_report(data: dict, filename_overide: str = "") -> None: |
124 | | - filename = f"{Axe._modify_filename_for_report(data["url"])}.json" if filename_overide == "" else f"{filename_overide}.json" |
| 130 | + def _create_json_report(data: dict, filename_override: str = "") -> None: |
| 131 | + filename = f"{Axe._modify_filename_for_report(data["url"])}.json" if filename_override == "" else f"{filename_override}.json" |
125 | 132 | full_path = Axe._create_path_for_report(filename) |
126 | 133 |
|
127 | 134 | with open(full_path, 'w') as file: |
128 | 135 | file.writelines(json.dumps(data)) |
129 | 136 |
|
130 | | - logging.info(f"JSON report generated: {full_path}") |
| 137 | + logger.info(f"JSON report generated: {full_path}") |
131 | 138 |
|
132 | 139 | @staticmethod |
133 | | - def _create_html_report(data: dict, filename_overide: str = "") -> None: |
134 | | - filename = f"{Axe._modify_filename_for_report(data["url"])}.html" if filename_overide == "" else f"{filename_overide}.html" |
| 140 | + def _create_html_report(data: dict, filename_override: str = "") -> None: |
| 141 | + filename = f"{Axe._modify_filename_for_report(data["url"])}.html" if filename_override == "" else f"{filename_override}.html" |
135 | 142 | full_path = Axe._create_path_for_report(filename) |
136 | 143 |
|
137 | 144 | with open(full_path, 'w') as file: |
138 | 145 | file.writelines(Axe._generate_html(data)) |
139 | 146 |
|
140 | | - logging.info(f"HTML report generated: {full_path}") |
| 147 | + logger.info(f"HTML report generated: {full_path}") |
141 | 148 |
|
142 | 149 | @staticmethod |
143 | 150 | def _generate_html(data: dict) -> str: |
|
0 commit comments