diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index 05b2a1b..b2fae3d 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -98,14 +98,15 @@ def write_results(self, data, name=None): Write JSON to file with the specified name. :param name: Path to the file to be written to. If no path is passed - a new file will be created. + a new JSON file "results.json" will be created in the + current working directory. :param output: JSON object. """ if name: filepath = os.path.abspath(name) else: - filepath = os.path.join(os.path.getcwd(), name) + filepath = os.path.join(os.path.getcwd(), "results.json") with open(filepath, "w", encoding="utf8") as f: try: diff --git a/axe_selenium_python/tests/test_axe.py b/axe_selenium_python/tests/test_axe.py index 692b1b7..a6d53e9 100755 --- a/axe_selenium_python/tests/test_axe.py +++ b/axe_selenium_python/tests/test_axe.py @@ -3,7 +3,7 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. import json -from os import getenv, path +from os import getcwd, getenv, path import pytest from selenium import webdriver @@ -76,3 +76,17 @@ def test_write_results_to_file(tmpdir, mocker): actual_file_contents = json.loads(f.read()) assert data == actual_file_contents + + +def test_write_results_without_filepath(mocker): + axe = Axe(mocker.MagicMock()) + data = {"testKey": "testValue"} + cwd = getcwd() + filename = path.join(cwd, "results.json") + + axe.write_results(data, filename) + with open(filename) as f: + actual_file_contents = json.loads(f.read()) + + assert data == actual_file_contents + assert path.dirname(filename) == cwd