Sitelet https://github.com/django-commons/axe-selenium-python/issues/191
Skip to content

Can not set rule disabled via options parameter #191

Description

@WallaceChen123

Hi guys,

I am utilizing axe-selenium-python to check our product pages, but I found that I can not set any rule disabled via the options parameter following the axe core guide.
options_param = {"rules": {"aria-allowed-attr": {"enabled": "false"}}} results = axe.run(options=options_param)
I am not sure whether I made any mistakes or if is there any issue with axe-selenium-python.

Activity

  1. Persipaani commented on Jun 20, 2024

    @Persipaani

    I know this is a 2 years old comment but since the library is still used and I was looking answer for this same question, here's my two cents:

    The issue is due to how dictionary is handled in the run function of axe.py as "enabled" should retain given values as boolean instead of strings.

    Here's one example how this could be implemented (you can change this to your axe.py if you never update it :P).

    def run(self, context = None, options = None):
      """
      Run axe against the current page.
      
      :param context: which page part(s) to analyze and/or what to exclude.
      :param options: dictionary of aXe options.
      """
      args = []
      
      # If context parameter is passed, add to args
      if context is not None:
          args.append(json.dumps(context))
      
      # If options parameter is passed, add to args
      if options is not None:
          # Convert the options dictionary to a JSON string
          options_json = json.dumps(options)
          args.append(options_json)
      
      # Join the arguments with a comma, if both are provided
      args_str = ", ".join(args)
      
      command = (
          f"var callback = arguments[arguments.length - 1];"
          f"axe.run({args_str}).then(results => callback(results))"
      )
      return self.selenium.execute_async_script(command)
    

    After this you can add rule excludes by passing dicts like this to axe run function as options like in the initial message.
    {"rules":{"svg-img-alt": {"enabled": False}}}
    and they should work fine.

    I would create a PR for this but I guess it does not make sense before someone starts maintaining the repo once again.

  2. m8ttyB commented on Jun 20, 2024

    @m8ttyB

    @Persipaani, FWIW, it's good to hear the library is still valid. Once we get word from Mozilla on the transfer progress (issue #192), moving this work to the community, we can begin triaging and implementing improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions