diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..fd45dea --- /dev/null +++ b/.coveragerc @@ -0,0 +1,4 @@ +[run] +omit = + **/modal/* + tests/* diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..a57d482 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,32 @@ +name: Unit tests and Coverage +on: + push: + branches: + - main + pull_request: + types: [ opened, synchronize, reopened ] + +jobs: + test: + name: Unit tests and Coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + playwright install + - name: Unit tests + run: coverage run -m pytest + - name: Generate Coverage Report + run: coverage xml + - name: Codacy Coverage + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: coverage.xml \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7978a25..eb3cee6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /dist/ /python_a11y_playwright.egg-info/ /python_a11y_playwright_test.egg-info/ +/.pytest_cache/ +/.coverage diff --git a/automateda11y/pw/axerunner.py b/automateda11y/pw/axerunner.py index 8dd02d9..3ad2f2c 100644 --- a/automateda11y/pw/axerunner.py +++ b/automateda11y/pw/axerunner.py @@ -14,6 +14,7 @@ def __init__(self, page): def set_page_title(self, page_title): self.params.set_page_title(page_title) + return self def execute(self): data = self.a11y.execute(Engine.AXE, self.params) diff --git a/automateda11y/pw/htmlcsrunner.py b/automateda11y/pw/htmlcsrunner.py index de9a7c4..f1e46ea 100644 --- a/automateda11y/pw/htmlcsrunner.py +++ b/automateda11y/pw/htmlcsrunner.py @@ -12,12 +12,15 @@ def __init__(self, page): def set_standard(self, standard="WCAG2AA"): self.params.set_standard(standard) + return self def set_ignore_code(self, codes): self.params.set_ignore_codes(codes) + return self def set_page_title(self, page_title): self.params.set_page_title(page_title) + return self def execute(self): data = self.a11y.execute(Engine.HTMLCS, self.params) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2c06efb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "python-a11y-playwright" +version = "0.0.2" +authors = [ + { name="Sridhar Bandi", email="sridhar.bandi.ece@gmail.com" }, +] +license = {text = "MIT License"} +description = "Automate Web Accessibility Testing using AXE/HTMLCS with Playwright Python" +readme = "ReadMe.md" +requires-python = ">=3.7" +classifiers = [ + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', +] +keywords = ["axe", "htmlcs", "accessibility", "playwright"] +dependencies = [ + "marshmallow-dataclass" +] + +[project.urls] +Homepage = "https://github.com/automated-a11y/python-a11y-playwright" +repository = "https://github.com/automated-a11y/python-a11y-playwright.git" + +[tool.setuptools.packages.find] +exclude = ["tests", "*.tests", "*.tests.*", "tests.*"] + +[tool.setuptools.package-data] +"automateda11y.pw.resources" = ["js/*.js"] diff --git a/requirements.txt b/requirements.txt index a26018d..d98d62a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ playwright==1.29.1 marshmallow-dataclass==8.5.11 -marshmallow~=3.19.0 -pynguin~=0.30.0 \ No newline at end of file +pytest-playwright==0.3.0 +coverage==7.1.0 \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index a994cac..0000000 --- a/setup.py +++ /dev/null @@ -1,41 +0,0 @@ -from pathlib import Path -from setuptools import setup, find_packages - -# Package meta-data. -NAME = 'python-a11y-playwright' -DESCRIPTION = 'Automate Web Accessibility Testing using AXE/HTMLCS with Playwright Python' -URL = 'https://github.com/automated-a11y/python-a11y-playwright' -EMAIL = 'sridhar.bandi.ece@gmail.com' -AUTHOR = 'Sridhar Bandi' -VERSION = '1.0.1' -CLASSIFIERS = [ - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', -] - -this_directory = Path(__file__).parent -long_description = (this_directory / "ReadMe.md").read_text() - -setup( - name=NAME, - version=VERSION, - packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]), - package_data={'automateda11y.pw.resources': ['js/*.js']}, - include_package_data=True, - url=URL, - license='MIT', - classifiers=CLASSIFIERS, - author=AUTHOR, - author_email=EMAIL, - description=DESCRIPTION, - install_requires=['marshmallow-dataclass', 'marshmallow'], - long_description=long_description, - long_description_content_type='text/markdown' -) diff --git a/tests/axetest.py b/tests/axetest.py deleted file mode 100644 index 3d632ee..0000000 --- a/tests/axetest.py +++ /dev/null @@ -1,20 +0,0 @@ -from pathlib import Path - -from playwright.sync_api import sync_playwright -from automateda11y.pw.axerunner import AxeRunner -from automateda11y.pw.settings import Settings - - -def root_dir(): - return Path(__file__).parent.parent.__str__() - - -with sync_playwright() as p: - Settings.report_dir = root_dir() + '/reports' - browser = p.chromium.launch(headless=False) - page = browser.new_page() - page.goto("https://www.hotukdeals.com/hot") - data = AxeRunner(page).execute() - print(data.browser) - print(page.title()) - browser.close() diff --git a/tests/htmlcstest.py b/tests/htmlcstest.py deleted file mode 100644 index cbbe9ce..0000000 --- a/tests/htmlcstest.py +++ /dev/null @@ -1,20 +0,0 @@ -from pathlib import Path - -from playwright.sync_api import sync_playwright -from automateda11y.pw.htmlcsrunner import HtmlCsRunner -from automateda11y.pw.settings import Settings - - -def root_dir(): - return Path(__file__).parent.parent.__str__() - - -with sync_playwright() as p: - Settings.report_dir = root_dir() + '/reports' - browser = p.chromium.launch(headless=False) - page = browser.new_page() - page.goto("http://playwright.dev") - data = HtmlCsRunner(page).execute() - print(data.notices) - print(page.title()) - browser.close() diff --git a/tests/test.html b/tests/test.html new file mode 100644 index 0000000..2baa095 --- /dev/null +++ b/tests/test.html @@ -0,0 +1,18 @@ + + +
+