Skip to content

Commit

Permalink
update docs, use fixture name in the screenshot file name
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenkoff committed Sep 25, 2014
1 parent 8cbdf9a commit 60c4fc6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
28 changes: 26 additions & 2 deletions README.rst
Expand Up @@ -190,9 +190,33 @@ You can have several browsers in one test.
assert browser.url == 'http://example.com'
Automatic screenshots of on test failure
----------------------------------------
Automatic screenshots on test failure
-------------------------------------

When your functional test fails, it's important to know the reason.
This becomes hard when tests are being run on the continuos integration server, where you cannot debug (use --pdb).
To simplify things, special behaviour of the browser fixture was introduced, so when test failed, it makes a screenshot
and puts it in the folder with the naming convention, to be compartible with this
`jenkins plugin <https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Attachments+Plugin>`_.

Making screenshots is fully compartible with `pytest-xdist plugin <https://pypi.python.org/pypi/pytest-xdist>`_ and will
transfer screenshots from the slave nodes through the communication channels automatically.

So if your test which uses browser fixture will fail, you should get a screenshot file in such path:

::

<pytest-screenshot-dir>/my.dotted.name.test.package/test_name-browser.png

The `pytest-screenshot-dir` for storing the screenshot is deferred by a fixture and command line argument,
as described above at the configuration options section.
Note that the making screenshots on the test failure is enabled by default. If you want to switch it off permanently,
override `splinter_make_screenshot_on_failure` fixture to return `False`. For temporary disabling you can use
command line argument:

::

py.test tests/functional --splinter-make-screenshot-on-failure=false


Python3 support
Expand Down
2 changes: 1 addition & 1 deletion pytest_splinter/plugin.py
Expand Up @@ -283,7 +283,7 @@ def make_screenshot_on_failure():
names = junitxml.mangle_testnames(request.node.nodeid.split("::"))
classname = '.'.join(names[:-1])
screenshot_dir = os.path.join(splinter_screenshot_dir, classname)
screenshot_file_name = '{0}.png'.format(names[-1])
screenshot_file_name = '{0}-{1}.png'.format(names[-1], parent.__name__)
if not slaveoutput:
if not os.path.exists(screenshot_dir):
os.makedirs(screenshot_dir)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_screenshot.py
Expand Up @@ -11,7 +11,7 @@ def test_screenshot(browser):
assert False
""", "-vl", "--splinter-session-scoped-browser=false")

assert testdir.tmpdir.join('test_browser_screenshot_normal', 'test_screenshot.png').isfile()
assert testdir.tmpdir.join('test_browser_screenshot_normal', 'test_screenshot-browser.png').isfile()


def test_browser_screenshot_xdist(testdir, mocked_browser):
Expand All @@ -24,4 +24,4 @@ def test_screenshot(browser):
assert False
""", "-vl", "-n1")

assert testdir.tmpdir.join('test_browser_screenshot_xdist', 'test_screenshot.png').isfile()
assert testdir.tmpdir.join('test_browser_screenshot_xdist', 'test_screenshot-browser.png').isfile()

0 comments on commit 60c4fc6

Please sign in to comment.