mozilla-services / axe-selenium-python

aXe Selenium Integration python package
https://pypi.python.org/pypi/axe-selenium-python/
Mozilla Public License 2.0
58 stars 50 forks source link

Can not set rule disabled via options parameter #191

Open WallaceChen123 opened 1 year ago

WallaceChen123 commented 1 year ago

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.

Persipaani commented 2 months ago

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.

m8ttyB commented 2 months ago

@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.