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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ cache:
- $HOME/virtualenv/python2.7.9/lib/python2.7/site-packages
- node_modules

install: pip install -r axe_selenium_python/tests/requirements/tests.txt
script: skip
Copy link

Choose a reason for hiding this comment

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

A question, not a nit. What does this line do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the install tells Travis where the dependency file is, the default is ./requirements.txt

The second line is to prevent Travis from running tests in the deploy stage (since tests have already been run)

Copy link

Choose a reason for hiding this comment

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

Beauty 👍


jobs:
include:
- stage:
Expand Down Expand Up @@ -53,13 +56,16 @@ jobs:

script: tox
- stage: deploy
if: tag =~ ^\d.\d.\d
deploy:
provider: pypi
user: kimberlythegeek
password:
secure: LHsL91XR32/M4r5ETAvaN/vUTakYByIfdwdCw6EI59LBvSnwaSant010QIl39+uafuev57yzUC/Y+orefczjkJnG3KdQBNS0Rt/zWIMw0Dr6Fp41Vg66e5URK/FRIwK36WlWzOcd3GkrQLLaDeqnXVzDWVMuXPP9/1ssu6mvriSeLctPsmX5N6m4yZwxNtpFsTLEh+BumXiamCuqjTI0RpyqxYlUVfio0G5LWeY9rkPskrwbSbc8xhq/PMk/ecLtlAxdn8AwgjLYCAt9d6NRfgL4Yp0R+kkfUQsX1Wf8A/pBNRr8Ht8Hy4CNlnEphgao4fgVEY4dc6tZL3FXOU9jQSmbChoANlbPzDhO+nb6d/QW5vLHVDufKyRQqtFxD90XFXlWFc/0gnD6tPZhi+UEFmBMoo9ugWDnYUeBd1T3lbwKT7sOmOQS58WhDVMLxPwr2BfgItGrNsaVHmzx9v0BnxZvD5ilmvNPrad6Rcsa0N8GtNXpnbyaupWzA97bemzuLqNHOjTm6TMZWRol6lLEJsJ1MRs7xWI4DYztXzlWITH7rvf6NNyvXKe9FPV3Lfoei3k1mT8QuEh6bIEFpBKRVV0ObQVSfFQ4M4wbgDBb3CbHVqMqFHgi98mpUo9tNGm4uzZCXw3hfEQpUPugKaH+VHoaylE+MR+fOhsyVlLQluM=
install: skip
script: skip
skip_cleanup: true
on:
tags: true
branch: master
distributions: sdist bdist_wheel
distributions: "sdist bdist_wheel"
skip_cleanup: true
14 changes: 9 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ You will need the following prerequisites in order to use axe-selenium-python:

- selenium >= 3.0.0
- Python 2.7 or 3.6
- `geckodriver <https://github.com/mozilla/geckodriver/releases>`_ downloaded and `added to your PATH <https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path#answer-40208762>`_
- The appropriate driver for the browser you intend to use, downloaded and added to your path, e.g. geckodriver for Firefox:
Copy link

Choose a reason for hiding this comment

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

nice

- `geckodriver <https://github.com/mozilla/geckodriver/releases>`_ downloaded and `added to your PATH <https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path#answer-40208762>`_

Installation
------------
Expand Down Expand Up @@ -73,12 +74,11 @@ Contributing

Fork the repository and submit PRs with bug fixes and enhancements;
contributions are very welcome. You can run the tests using
`Docker <https://www.docker.com/>`_:
`tox <https://tox.readthedocs.io/en/latest/>`_:

.. code-block:: bash

$ docker build -t axe-selenium-python .
$ docker run -it axe-selenium-python tox
$ tox

Resources
---------
Expand Down Expand Up @@ -117,7 +117,7 @@ version 1.2.3

version 1.2.1
**************
- Updated axe.min.js to ``axe-core@2.6.1``
- Updated axe to ``axe-core@2.6.1``
- Modified impact_included class method to reflect changes to the aXe API:
- There are now only 3 impact levels: 'critical', 'serious', and 'minor'

Expand All @@ -132,6 +132,7 @@ version 0.0.3
- Added run method to Axe class to simplify the usage in existing test suites
- run method includes the ability to set what impact level to test for: 'minor', 'moderate', 'severe', 'critical'

<<<<<<< HEAD
Copy link

Choose a reason for hiding this comment

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

here

version 0.0.276
****************
- Added pytest-axe usage example to README
Expand All @@ -141,6 +142,9 @@ version 0.0.275
- Added usage example to README

version 0.0.273
=======
version 0.0.28
>>>>>>> ba24ec56528e4458f0a5604a8d511923c943a479
Copy link

Choose a reason for hiding this comment

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

and here

****************
- Added selenium instance as a class attribute
- Changed file paths to OS independent structure
Expand Down
2 changes: 1 addition & 1 deletion axe_selenium_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# 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 .axe import Axe # NOQA
from .axe import Axe # NOQA
66 changes: 37 additions & 29 deletions axe_selenium_python/axe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from io import open
from os import path

_DEFAULT_SCRIPT = path.join(path.dirname(__file__), 'node_modules', 'axe-core', 'axe.min.js')
_DEFAULT_SCRIPT = path.join(
path.dirname(__file__), "node_modules", "axe-core", "axe.min.js"
)


class Axe(object):

def __init__(self, selenium, script_url=_DEFAULT_SCRIPT):
self.script_url = script_url
self.selenium = selenium
Expand All @@ -22,7 +23,7 @@ def inject(self):
:param script_url: location of the axe-core script.
:type script_url: string
"""
with open(self.script_url, 'r', encoding='utf8') as f:
with open(self.script_url, "r", encoding="utf8") as f:
self.selenium.execute_script(f.read())

def execute(self, context=None, options=None):
Expand All @@ -32,18 +33,18 @@ 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;});'
args = ''
template = "return axe.run(%s).then(function(result){return result;});"
args = ""

# If context parameter is passed, add to args
if context is not None:
args += '%r' % context
args += "%r" % context
# Add comma delimiter only if both parameters are passed
if context is not None and options is not None:
args += ','
args += ","
# If options parameter is passed, add to args
if options is not None:
args += '%s' % options
args += "%s" % options

command = template % args
response = self.selenium.execute_script(command)
Expand All @@ -58,36 +59,43 @@ def report(self, violations):
:return report: Readable report of violations.
:rtype: string
"""
string = ''
string += 'Found ' + str(len(violations)) + ' accessibility violations:'
string = ""
string += "Found " + str(len(violations)) + " accessibility violations:"
for violation in violations:
string += '\n\n\nRule Violated:\n' + violation['id'] + ' - ' + violation['description'] + \
'\n\tURL: ' + violation['helpUrl'] + \
'\n\tImpact Level: ' + violation['impact'] + \
'\n\tTags:'
for tag in violation['tags']:
string += ' ' + tag
string += '\n\tElements Affected:'
string += (
"\n\n\nRule Violated:\n"
+ violation["id"]
+ " - "
+ violation["description"]
+ "\n\tURL: "
+ violation["helpUrl"]
+ "\n\tImpact Level: "
+ violation["impact"]
+ "\n\tTags:"
)
for tag in violation["tags"]:
string += " " + tag
string += "\n\tElements Affected:"
i = 1
for node in violation['nodes']:
for target in node['target']:
string += '\n\t' + str(i) + ') Target: ' + target
for node in violation["nodes"]:
for target in node["target"]:
string += "\n\t" + str(i) + ") Target: " + target
i += 1
for item in node['all']:
string += '\n\t\t' + item['message']
for item in node['any']:
string += '\n\t\t' + item['message']
for item in node['none']:
string += '\n\t\t' + item['message']
string += '\n\n\n'
for item in node["all"]:
string += "\n\t\t" + item["message"]
for item in node["any"]:
string += "\n\t\t" + item["message"]
for item in node["none"]:
string += "\n\t\t" + item["message"]
string += "\n\n\n"
return string

def write_results(self, data, name='results.json'):
def write_results(self, data, name="results.json"):
"""
Write JSON to file with the specified name.

:param name: Name of file to be written to.
:param output: JSON object.
"""
with open(name, 'r', encoding='utf8') as f:
with open(name, "r", encoding="utf8") as f:
f.write(json.dumps(data, indent=4))
6 changes: 3 additions & 3 deletions axe_selenium_python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
"""Add description and sortable time header to HTML report."""
cells.insert(2, html.th('Description'))
cells.insert(0, html.th('Time', class_='sortable time', col='time'))
cells.insert(2, html.th("Description"))
cells.insert(0, html.th("Time", class_="sortable time", col="time"))


@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
"""Add description and sortable time column to HTML report."""
cells.insert(2, html.td(report.description))
cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
cells.insert(1, html.td(datetime.utcnow(), class_="col-time"))


@pytest.mark.hookwrapper
Expand Down
4 changes: 2 additions & 2 deletions axe_selenium_python/tests/test_axe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ..axe import Axe

_DEFAULT_TEST_FILE = path.join(path.dirname(__file__), 'test_page.html')
_DEFAULT_TEST_FILE = path.join(path.dirname(__file__), "test_page.html")


@pytest.fixture
Expand All @@ -22,7 +22,7 @@ def driver():
@pytest.mark.nondestructive
def test_run_axe_sample_page(driver):
"""Run axe against sample page and verify JSON output is as expected."""
driver.get('file://' + _DEFAULT_TEST_FILE)
driver.get("file://" + _DEFAULT_TEST_FILE)
axe = Axe(driver)
axe.inject()
data = axe.execute()
Expand Down
45 changes: 22 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@

from setuptools import find_packages, setup

with open('./README.rst') as f:
with open("./README.rst") as f:
readme = f.read()

setup(name='axe-selenium-python',
version='2.1.2',
description='Python library to integrate axe and selenium for web \
accessibility testing.',
long_description=readme,
url='http://github.com/mozilla-services/axe-selenium-python',
author='Kimberly Sereduck',
author_email='ksereduck@mozilla.com',
packages=find_packages(),
package_data={
'axe_selenium_python': [
'axe_selenium_python/node_modules/axe-core/axe.min.js',
'axe_selenium_python/tests/test_page.html'
],
},
include_package_data=True,
install_requires=[
'selenium>=3.0.2',
'pytest>=3.0'
],
license='Mozilla Public License 2.0 (MPL 2.0)',
keywords='axe-core selenium pytest-selenium accessibility automation mozilla')
setup(
name="axe-selenium-python",
use_scm_version=True,
description="Python library to integrate axe and selenium for web \
accessibility testing.",
long_description=open("README.rst").read(),
url="http://github.com/mozilla-services/axe-selenium-python",
author="Kimberly Sereduck",
author_email="ksereduck@mozilla.com",
packages=find_packages(),
package_data={
"axe_selenium_python": [
"axe_selenium_python/node_modules/axe-core/axe.min.js",
"axe_selenium_python/tests/test_page.html",
]
},
include_package_data=True,
install_requires=["selenium>=3.0.2", "pytest>=3.0"],
license="Mozilla Public License 2.0 (MPL 2.0)",
keywords="axe-core selenium pytest-selenium accessibility automation mozilla",
)
6 changes: 5 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ deps = -raxe_selenium_python/tests/requirements/flake8.txt
commands = flake8 {posargs:.}

[flake8]
ignore = E501
max-line-length = 88
Copy link

Choose a reason for hiding this comment

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

Cool, this is new to me (-:

# Black will break a line before a binary operator when splitting a block
# of code over multiple lines. This is so that Black is compliant with the
# recent changes in the PEP8 style guide.
ignore = W503

[isort]
default_section = THIRDPARTY
Expand Down