Skip to content

Commit e8fde61

Browse files
neverstewKimberly Sereduck
authored andcommitted
Feature/execute script asyncronously (#141)
* execute script asyncronously in order to effectively use promises * added travis configuration * added chromedriver to path on travis * changed chromedriver to point to executable * downloading chromedriver on travis * changed chromedriver version to env var
1 parent 305f1ba commit e8fde61

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

.travis.yml

100644100755
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ jobs:
1818
node_js: stable
1919
addons:
2020
firefox: latest-nightly
21-
env: TOXENV=py36 MOZ_HEADLESS=1 GECKODRIVER=0.22.0
21+
chrome: stable
22+
env: TOXENV=py36 MOZ_HEADLESS=1 GECKODRIVER=0.22.0 CHROMEDRIVER=2.40
2223
before_install:
24+
- wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER/chromedriver_linux64.zip
25+
- mkdir $HOME/chromedriver && unzip /tmp/chromedriver.zip -d $HOME/chromedriver
26+
- export PATH=$HOME/chromedriver:$PATH
2327
- wget -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER/geckodriver-v$GECKODRIVER-linux64.tar.gz
2428
- mkdir $HOME/geckodriver && tar xvf /tmp/geckodriver.tar.gz -C $HOME/geckodriver
2529
- export PATH=$HOME/geckodriver:$PATH
@@ -36,8 +40,12 @@ jobs:
3640
node_js: stable
3741
addons:
3842
firefox: latest-nightly
39-
env: TOXENV=py27 MOZ_HEADLESS=1 GECKODRIVER=0.22.0
43+
chrome: stable
44+
env: TOXENV=py27 MOZ_HEADLESS=1 GECKODRIVER=0.22.0 CHROMEDRIVER=2.40
4045
before_install:
46+
- wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER/chromedriver_linux64.zip
47+
- mkdir $HOME/chromedriver && unzip /tmp/chromedriver.zip -d $HOME/chromedriver
48+
- export PATH=$HOME/chromedriver:$PATH
4149
- wget -O /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER/geckodriver-v$GECKODRIVER-linux64.tar.gz
4250
- mkdir $HOME/geckodriver && tar xvf /tmp/geckodriver.tar.gz -C $HOME/geckodriver
4351
- export PATH=$HOME/geckodriver:$PATH

README.rst

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ Contributing
7373
------------
7474

7575
Fork the repository and submit PRs with bug fixes and enhancements;
76-
contributions are very welcome. You can run the tests using
76+
contributions are very welcome.
77+
78+
Node dependencies must be installed by running `npm install` inside the axe-selenium-python directory.
79+
80+
You can run the tests using
7781
`tox <https://tox.readthedocs.io/en/latest/>`_:
7882

7983
.. code-block:: bash

axe_selenium_python/axe.py

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def execute(self, context=None, options=None):
3333
:param context: which page part(s) to analyze and/or what to exclude.
3434
:param options: dictionary of aXe options.
3535
"""
36-
template = "return axe.run(%s).then(function(result){return result;});"
36+
template = "var callback = arguments[arguments.length - 1];" \
37+
"axe.run(%s).then(results => callback(results))"
3738
args = ""
3839

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

4950
command = template % args
50-
response = self.selenium.execute_script(command)
51+
response = self.selenium.execute_async_script(command)
5152
return response
5253

5354
def report(self, violations):

axe_selenium_python/tests/test_axe.py

100644100755
Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
from os import path
5+
from os import path, getenv
66

77
import pytest
88
from selenium import webdriver
@@ -13,21 +13,49 @@
1313

1414

1515
@pytest.fixture
16-
def driver():
16+
def firefox_driver():
1717
driver = webdriver.Firefox()
1818
yield driver
1919
driver.close()
2020

2121

22+
@pytest.fixture
23+
def chrome_driver():
24+
opts = webdriver.ChromeOptions()
25+
opts.headless = True
26+
opts.add_argument('--no-sandbox')
27+
driver_path = getenv('CHROMEDRIVER_PATH')
28+
driver = webdriver.Chrome(options=opts, executable_path=driver_path) \
29+
if driver_path else webdriver.Chrome(options=opts)
30+
yield driver
31+
driver.close()
32+
33+
2234
@pytest.mark.nondestructive
23-
def test_run_axe_sample_page(driver):
35+
def test_run_axe_sample_page_firefox(firefox_driver):
2436
"""Run axe against sample page and verify JSON output is as expected."""
25-
driver.get("file://" + _DEFAULT_TEST_FILE)
26-
axe = Axe(driver)
27-
axe.inject()
28-
data = axe.execute()
37+
data = _perform_axe_run(firefox_driver)
38+
39+
assert len(data["inapplicable"]) == 50
40+
assert len(data["incomplete"]) == 0
41+
assert len(data["passes"]) == 7
42+
assert len(data["violations"]) == 8
43+
44+
45+
@pytest.mark.nondestructive
46+
def test_run_axe_sample_page_chrome(chrome_driver):
47+
"""Run axe against sample page and verify JSON output is as expected."""
48+
data = _perform_axe_run(chrome_driver)
2949

3050
assert len(data["inapplicable"]) == 50
3151
assert len(data["incomplete"]) == 0
3252
assert len(data["passes"]) == 7
3353
assert len(data["violations"]) == 8
54+
55+
56+
def _perform_axe_run(driver):
57+
driver.get("file://" + _DEFAULT_TEST_FILE)
58+
axe = Axe(driver)
59+
axe.inject()
60+
data = axe.execute()
61+
return data

0 commit comments

Comments
 (0)