Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .travis.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ jobs:
node_js: stable
addons:
firefox: latest-nightly
env: TOXENV=py36 MOZ_HEADLESS=1 GECKODRIVER=0.22.0
chrome: stable
env: TOXENV=py36 MOZ_HEADLESS=1 GECKODRIVER=0.22.0 CHROMEDRIVER=2.40
before_install:
- wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER/chromedriver_linux64.zip
- mkdir $HOME/chromedriver && unzip /tmp/chromedriver.zip -d $HOME/chromedriver
- export PATH=$HOME/chromedriver:$PATH
- wget -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER/geckodriver-v$GECKODRIVER-linux64.tar.gz
- mkdir $HOME/geckodriver && tar xvf /tmp/geckodriver.tar.gz -C $HOME/geckodriver
- export PATH=$HOME/geckodriver:$PATH
Expand All @@ -36,8 +40,12 @@ jobs:
node_js: stable
addons:
firefox: latest-nightly
env: TOXENV=py27 MOZ_HEADLESS=1 GECKODRIVER=0.22.0
chrome: stable
env: TOXENV=py27 MOZ_HEADLESS=1 GECKODRIVER=0.22.0 CHROMEDRIVER=2.40
before_install:
- wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER/chromedriver_linux64.zip
- mkdir $HOME/chromedriver && unzip /tmp/chromedriver.zip -d $HOME/chromedriver
- export PATH=$HOME/chromedriver:$PATH
- wget -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER/geckodriver-v$GECKODRIVER-linux64.tar.gz
- mkdir $HOME/geckodriver && tar xvf /tmp/geckodriver.tar.gz -C $HOME/geckodriver
- export PATH=$HOME/geckodriver:$PATH
Expand Down
6 changes: 5 additions & 1 deletion README.rst
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ Contributing
------------

Fork the repository and submit PRs with bug fixes and enhancements;
contributions are very welcome. You can run the tests using
contributions are very welcome.

Node dependencies must be installed by running `npm install` inside the axe-selenium-python directory.

You can run the tests using
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Sometimes I struggle with writing thorough documentation.

`tox <https://tox.readthedocs.io/en/latest/>`_:

.. code-block:: bash
Expand Down
5 changes: 3 additions & 2 deletions axe_selenium_python/axe.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def execute(self, context=None, options=None):
:param context: which page part(s) to analyze and/or what to exclude.
:param options: dictionary of aXe options.
"""
template = "return axe.run(%s).then(function(result){return result;});"
template = "var callback = arguments[arguments.length - 1];" \
"axe.run(%s).then(results => callback(results))"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work :)

I don't have a lot of experience with JavaScript; I tried a lot of different approaches and didn't get it to work!

args = ""

# If context parameter is passed, add to args
Expand All @@ -47,7 +48,7 @@ def execute(self, context=None, options=None):
args += "%s" % options

command = template % args
response = self.selenium.execute_script(command)
response = self.selenium.execute_async_script(command)
return response

def report(self, violations):
Expand Down
42 changes: 35 additions & 7 deletions axe_selenium_python/tests/test_axe.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

from os import path
from os import path, getenv

import pytest
from selenium import webdriver
Expand All @@ -13,21 +13,49 @@


@pytest.fixture
def driver():
def firefox_driver():
driver = webdriver.Firefox()
yield driver
driver.close()


@pytest.fixture
def chrome_driver():
opts = webdriver.ChromeOptions()
opts.headless = True
opts.add_argument('--no-sandbox')
driver_path = getenv('CHROMEDRIVER_PATH')
driver = webdriver.Chrome(options=opts, executable_path=driver_path) \
if driver_path else webdriver.Chrome(options=opts)
yield driver
driver.close()


@pytest.mark.nondestructive
def test_run_axe_sample_page(driver):
def test_run_axe_sample_page_firefox(firefox_driver):
"""Run axe against sample page and verify JSON output is as expected."""
driver.get("file://" + _DEFAULT_TEST_FILE)
axe = Axe(driver)
axe.inject()
data = axe.execute()
data = _perform_axe_run(firefox_driver)

assert len(data["inapplicable"]) == 50
assert len(data["incomplete"]) == 0
assert len(data["passes"]) == 7
assert len(data["violations"]) == 8


@pytest.mark.nondestructive
def test_run_axe_sample_page_chrome(chrome_driver):
"""Run axe against sample page and verify JSON output is as expected."""
data = _perform_axe_run(chrome_driver)

assert len(data["inapplicable"]) == 50
assert len(data["incomplete"]) == 0
assert len(data["passes"]) == 7
assert len(data["violations"]) == 8


def _perform_axe_run(driver):
driver.get("file://" + _DEFAULT_TEST_FILE)
axe = Axe(driver)
axe.inject()
data = axe.execute()
return data