Skip to content

Commit 8c257f4

Browse files
authored
Add tips and tricks section to user guide (#226)
* Add tips and tricks section to user guide
1 parent 3a42568 commit 8c257f4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848
# General information about the project.
4949
project = u"pytest-selenium"
50-
copyright = u"2015, Dave Hunt"
51-
author = u"Dave Hunt"
50+
copyright = u"2019, Dave Hunt"
51+
author = u"Dave Hunt, Jim Brännlund"
5252

5353
# The version info for the project you're documenting, acts as replacement for
5454
# |version| and |release|, also used in various other places throughout the

docs/user_guide.rst

+27
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,33 @@ or set the ``SELENIUM_EXCLUDE_DEBUG`` environment variable to a list of the
660660
For example, to exclude HTML, logs, and screenshots from the report, you could
661661
set ``SELENIUM_EXCLUDE_DEBUG`` to ``html:logs:screenshot``.
662662

663+
Tips & Tricks
664+
*************
665+
666+
Example solutions to common scenarios that sometimes gets reported as issues
667+
to the project.
668+
669+
Save screenshot to file
670+
-----------------------
671+
672+
To save a screenshot to the file system, especially when not using ``--html``,
673+
you can place the ``pytest_selenium_capture_debug`` hook in ``conftest.py``.
674+
675+
The example will create a png-file using the test name.
676+
677+
.. code-block:: python
678+
679+
import base64
680+
681+
682+
def pytest_selenium_capture_debug(item, report, extra):
683+
for log_type in extra:
684+
if log_type["name"] == "Screenshot":
685+
content = base64.b64decode(log_type["content"].encode("utf-8"))
686+
with open(item.name + ".png", "wb") as f:
687+
f.write(content)
688+
689+
663690
.. _Jenkins CI: https://jenkins.io/
664691
.. _using environment variables in Jenkins pipelines: https://jenkins.io/doc/pipeline/tour/environment/
665692
.. _Firefox options API documentation: https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.options.html

testing/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def httpserver_base_url(httpserver):
2121
@pytest.fixture(autouse=True)
2222
def testdir(request, httpserver_base_url):
2323
item = request.node
24-
if "testdir" not in item.funcargnames:
24+
if "testdir" not in item.fixturenames:
2525
return
2626

2727
testdir = request.getfixturevalue("testdir")

0 commit comments

Comments
 (0)