Can not get the result of the axe analysis
Closed this issue · 4 comments
line 39 in axe.py
template = 'return axe.run(%s).then(function(result){return result;});'
seriously? Can this javascript statements return the result? or just the Promise itself?
This is a python plugin that integrates a Javascript API with selenium to enable automated testing with pytest.
If you want results in Javascript, please use axe-core instead.
Yes this is a python plugin that integrates a javascript api with selenium, but how do you get the result in py.test?
according to your code, you'll get nothing of the result. All the stuff in the then callback will be done at the next frame of javascript, you should wait for a while to let it finish before return.
a probably walk around could be
def execute(self, context=None, options=None):
"""
Run axe against the current page.
:param context: which part of the page to analyze and/or what to exclude.
:param options: dictionary of aXe options.
"""
template = 'window.axe_scan_result=undefined; axe.run(%s).then(function(result){axe_scan_result = result;});'
args = ''
# If context parameter is passed, add to args
if context is not None:
args += '%r' % context
# Add comma delimiter only if both parameters are passed
if context is not None and options is not None:
args += ','
# If options parameter is passed, add to args
if options is not None:
args += '%s' % options
command = template % args
self.selenium.execute_script(command)
while (True):
response = self.selenium.execute_script('return window.axe_scan_result;')
if response == None:
time.sleep(0.1)
else:
break
return responseP.S. did you ever test it before commit? and why do you call the function self.impact_included(rule, impact)) but the declaration of it is def impact_included(rule, impact):, is it an instance method?
@kimberlythegeek I was working with your code, but yes @yuanstrong is right, you need to wait until the result can be returned.
A couple things to note here, when filing an issue always provide steps to reproduce. This issue was closed because it lacked specificity. This code has been tested and works. Lastly be professional, if need be review our code of conduct here https://www.mozilla.org/about/governance/policies/participation/
I realize that English is likely not your first language, however your comments come across as extremely disrespectful, and will not be tolerated in our community.
If you post another comment on this thread it will be frozen and you will be banned.
We welcome participation, but only if it is respectful. If you would like to discuss this further please reach out to me at mbrandt@mozilla.com. Again, do not post to this thread or you will be banned, reach out to me, and we can discuss.