def inject_wcag2aa(driver, timestamp, file_name, site):
     """
     This method inject axe js into website and scans it against wcag2aa rule
     :param driver: webdriver
     :param timestamp: timestamp of current scan YYYY-MM-DD
     :param file_name: file name where to save results
     :param site: url to scan
     :return:
     """
     options = """
         {
         runOnly: {
             type: 'tag',
             values: ['wcag2aa']
             }
         }"""
     axe = Axe(driver)
     axe.inject()
     results = axe.run(context=None, options=options)
     f = open(f"accessibility_results/{timestamp}_wcag2aa/" +
              file_name.replace("/", "_"),
              "w",
              encoding="utf-8")
     f.write(site + "\n")
     f.write(axe.report(results["violations"]))
     f.close()
Example #2
0
 def inject_axe(driver, site, file_name):
     """Using selenium driver, axe injects its own js to the specific site and writes WCAG validations to file"""
     axe = Axe(driver)
     axe.inject()
     results = axe.run()
     f = open("results/" + file_name, "w", encoding="utf-8")
     f.write(site + "\n")
     f.write(axe.report(results["violations"]))
     f.close()
Example #3
0
 def inject_all_rules(driver, timestamp, culture, file_name, site):
     axe = Axe(driver)
     axe.inject()
     results = axe.run()
     f = open(
         f"results/{timestamp}_all/{culture}/{file_name.replace('/', '_')}",
         "w",
         encoding="utf-8")
     f.write(site + "\n")
     f.write(axe.report(results["violations"]))
     f.close()
Example #4
0
 def accesibility_check(self, url):
     self.open(url)
     axe = Axe(self.driver)
     # Inject axe-core javascript into page.
     axe.inject()
     # Run axe accessibility checks.
     results = axe.run()
     # Write results to file
     axe.write_results(results, 'a11y.json')
     # Assert no violations are found
     assert len(results["violations"]) == 0, axe.report(
         results["violations"])
Example #5
0
    def test_accessibility(self):
        urls_to_test = self.get_urls()
        for url in urls_to_test:
            self.driver.get(url)
            axe = Axe(self.driver)
            axe.inject()
            results = axe.run()
            import time

            assert len(results["violations"]) == 0, (
                axe.report(results["violations"]),
                url,
            )
Example #6
0
def test_google():
    driver = webdriver.Firefox()
    driver.get("http://www.google.com")
    axe = Axe(driver)
    # Inject axe-core javascript into page.
    axe.inject()
    # Run axe accessibility checks.
    results = axe.run()
    # Write results to file
    axe.write_results(results, 'a11y.json')
    driver.close()
    # Assert no violations are found
    assert len(results["violations"]) == 0, axe.report(results["violations"])
Example #7
0
def test_site(url: str):
    # Add the path the geckodriver you downloaded earlier
    # The following is an example
    driver = webdriver.Firefox()
    driver.get(url)
    axe = Axe(driver)
    # Inject axe-core javascript into page.
    axe.inject()
    # Run axe accessibility checks.
    results = axe.run()
    # Write results to file
    axe.write_results(results, 'pleasework.json')
    driver.close()
    # Assert no violations are found
    assert len(results["violations"]) == 0, axe.report(results["violations"])
def test_contrast(driver: webdriver.Chrome):
    axe = Axe(driver)
    # Inject axe-core javascript into page.
    axe.inject()
    # Run axe accessibility checks.
    results = axe.run(
        options={'runOnly': {
            'type': 'rule',
            'values': ['color-contrast']
        }})
    # Write results to file
    axe.write_results(results, 'a11y.json')
    # Assert no violations are found
    logging.info('results:\n%s', json.dumps(results, indent=4, sort_keys=True))
    assert len(results["violations"]) == 0, axe.report(results["violations"])
Example #9
0
 def accessibility(context, acc_standard):
     axe = Axe(context.browser)
     axe.inject()
     results = axe.run(
         options={'runOnly': {'type': 'tag', 'values': [acc_standard]}})
     current_url = context.browser.current_url
     try:
         assert len(results["violations"]) == 0
         context.test_case.test_result = 'pass'
     except AssertionError as ae:
         context.test_case.test_result = 'fail'
         violations = str(axe.report(results["violations"]))
         message = 'Page at url: %s failed accesibility with: %s ' %\
             (current_url, violations)
         BehaveStepHelper.save_accessibility_report(message)
         raise AssertionError(message)
Example #10
0
 def inject_only_wcag2aa(driver, timestamp, culture, file_name, site):
     options = """
         {
         runOnly: {
             type: 'tag',
             values: ['wcag2aa','wcag2a']
             }
         }"""
     axe = Axe(driver)
     axe.inject()
     results = axe.run(context=None, options=options)
     f = open(
         f"results/{timestamp}_wcag2aa/{culture}/{file_name.replace('/', '_')}",
         "w",
         encoding="utf-8")
     f.write(site + "\n")
     f.write(axe.report(results["violations"]))
     f.close()
    def test_accessibility(self):
        """
        Test: Page contains no axe accessibility violations for tags accessibility_test_tags and
        excluding the rules in accessibility_test_ignore_rules
        When: Page has AccessibilityMixin
        """
        self.page.launch()
        axe = Axe(self.driver)
        axe.inject()
        results = axe.run(options=self._build_axe_options())

        now = datetime.datetime.now()
        report_name = f"{type(self.page).__name__}-{now.strftime('%Y-%m-%d_%H-%M-%S')}.json"
        a11y_reports_folder = Path(AUTOREDUCE_HOME_ROOT, "selenium_tests", "a11y_reports")
        a11y_reports_folder.mkdir(parents=True, exist_ok=True)
        report_path = str(a11y_reports_folder / report_name)

        axe.write_results(results, report_path)
        self.assertEqual(len(results['violations']), 0, axe.report(results["violations"]))
 def inject_all(driver, timestamp, file_name, site):
     """
     This method inject axe js into website and scans it against all accessibility tags
     https://github.com/dequelabs/axe-core/blob/a5ebc936a53bf8a716fed35fe7ec72b2436eab8e/doc/API.md
     :param driver: webdriver
     :param timestamp: timestamp of current scan YYYY-MM-DD
     :param file_name: file name where to save results
     :param site: url to scan
     :return:
     """
     axe = Axe(driver)
     axe.inject()
     results = axe.run()
     f = open(f"accessibility_results/{timestamp}_all/" +
              file_name.replace("/", "_"),
              "w",
              encoding="utf-8")
     f.write(site + "\n")
     f.write(axe.report(results["violations"]))
     f.close()