Skip to content

Commit

Permalink
Add tips and tricks section to user guide (#226)
Browse files Browse the repository at this point in the history
* Add tips and tricks section to user guide
  • Loading branch information
BeyondEvil committed Jul 12, 2019
1 parent 3a42568 commit 8c257f4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

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

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
27 changes: 27 additions & 0 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,33 @@ or set the ``SELENIUM_EXCLUDE_DEBUG`` environment variable to a list of the
For example, to exclude HTML, logs, and screenshots from the report, you could
set ``SELENIUM_EXCLUDE_DEBUG`` to ``html:logs:screenshot``.

Tips & Tricks
*************

Example solutions to common scenarios that sometimes gets reported as issues
to the project.

Save screenshot to file
-----------------------

To save a screenshot to the file system, especially when not using ``--html``,
you can place the ``pytest_selenium_capture_debug`` hook in ``conftest.py``.

The example will create a png-file using the test name.

.. code-block:: python
import base64
def pytest_selenium_capture_debug(item, report, extra):
for log_type in extra:
if log_type["name"] == "Screenshot":
content = base64.b64decode(log_type["content"].encode("utf-8"))
with open(item.name + ".png", "wb") as f:
f.write(content)
.. _Jenkins CI: https://jenkins.io/
.. _using environment variables in Jenkins pipelines: https://jenkins.io/doc/pipeline/tour/environment/
.. _Firefox options API documentation: https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.options.html
Expand Down
2 changes: 1 addition & 1 deletion testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def httpserver_base_url(httpserver):
@pytest.fixture(autouse=True)
def testdir(request, httpserver_base_url):
item = request.node
if "testdir" not in item.funcargnames:
if "testdir" not in item.fixturenames:
return

testdir = request.getfixturevalue("testdir")
Expand Down

0 comments on commit 8c257f4

Please sign in to comment.