Skip to content

Add tips and tricks section to user guide #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

# General information about the project.
project = u"pytest-selenium"
copyright = u"2015, Dave Hunt"
copyright = u"2019, Dave Hunt"
author = u"Dave Hunt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add other authors here now.. my last commit was almost a year ago.


# The version info for the project you're documenting, acts as replacement for
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